This repository was archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
82 lines (68 loc) · 2.34 KB
/
app.js
File metadata and controls
82 lines (68 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Generated by CoffeeScript 1.10.0
(function() {
var HOST, PORT, app, koa, leaApiGetter, leaLogin, readabilityFetchContent, route, toMarkdown;
koa = require('koa');
route = require('koa-route');
toMarkdown = require('to-markdown');
readabilityFetchContent = require('./utils').readabilityFetchContent;
leaApiGetter = require('./lea-api');
leaLogin = leaApiGetter.login;
HOST = process.env.HOST || '0.0.0.0';
PORT = process.env.PORT || '8080';
app = koa();
app.use(route.get('/favour', function*() {
var api, content, email, err, error, error1, error2, notebook, notebookId, notebookMatched, notebooks, pwd, ref, ref1, result, title, token, url;
ref = this.query, token = ref.token, email = ref.email, pwd = ref.pwd, url = ref.url, notebook = ref.notebook, notebookId = ref.notebookId;
try {
if ((!token) && (email && pwd)) {
token = (yield leaLogin(email, pwd));
}
} catch (error) {
err = error;
this["throw"](400, 'Login error.');
}
if (!token) {
this["throw"](400, 'No token or login info provided.');
}
if (!url) {
this["throw"](400, 'No url provided.');
}
if ((!notebook) && (!notebookId)) {
this["throw"](400, 'No notebook info provided.');
}
api = leaApiGetter(token);
if (!notebookId) {
notebooks = (yield api.getNotebooks());
}
notebookMatched = notebooks.filter(function(v) {
return v.name === notebook;
});
if (notebookMatched.length < 1) {
this["throw"](400, 'No notebook matched.');
}
notebookId = notebookMatched[0].id;
title = null;
content = null;
try {
ref1 = (yield readabilityFetchContent(url)), title = ref1.title, content = ref1.content;
} catch (error1) {
err = error1;
this["throw"](400, "Readability error." + (JSON.stringify(err)));
}
content = toMarkdown(content);
result = null;
try {
result = (yield api.addNote(title, notebookId, content));
} catch (error2) {
err = error2;
this["throw"](400, "Leanote Server error." + (JSON.stringify(err)));
}
if (result['Ok'] && result['Ok'] === false) {
this["throw"](400, "Error " + (JSON.stringify(result)));
}
return this.body = result;
}));
app.listen(PORT);
console.log("app listen on " + PORT);
}).call(this);
//# sourceMappingURL=app.js.map