summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWu Cheng-Han2016-08-19 11:24:36 +0800
committerWu Cheng-Han2016-08-19 11:24:36 +0800
commit4d7c3d21206ef61de2323f2138dd99cf5dbf5d31 (patch)
treeeebad2d5b1974e730db1e37deb258810fab9742c /lib
parent058c35730b3b8b0d3572c6e96093f760c402b727 (diff)
Add info api for note
Diffstat (limited to 'lib')
-rwxr-xr-xlib/response.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/response.js b/lib/response.js
index 39d83ca2..b61fe51d 100755
--- a/lib/response.js
+++ b/lib/response.js
@@ -294,6 +294,35 @@ function actionDownload(req, res, note) {
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
});
res.end(body);
+
+function actionInfo(req, res, note) {
+ var body = LZString.decompressFromBase64(note.content);
+ var meta = null;
+ try {
+ meta = models.Note.parseMeta(metaMarked(body).meta);
+ } catch(err) {
+ //na
+ }
+ if (!meta) meta = {};
+ var createtime = note.createdAt;
+ var updatetime = note.lastchangeAt;
+ var text = S(body).escapeHTML().s;
+ var title = models.Note.decodeTitle(note.title);
+ var data = {
+ title: meta.title || title,
+ description: meta.description,
+ viewcount: note.viewcount,
+ createtime: createtime,
+ updatetime: updatetime
+ };
+ res.set({
+ 'Access-Control-Allow-Origin': '*', //allow CORS as API
+ 'Access-Control-Allow-Headers': 'Range',
+ 'Access-Control-Expose-Headers': 'Cache-Control, Content-Encoding, Content-Range',
+ 'Cache-Control': 'private',
+ 'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
+ });
+ res.send(data);
}
function actionPDF(req, res, note) {
@@ -382,6 +411,9 @@ function noteActions(req, res, next) {
case "download":
actionDownload(req, res, note);
break;
+ case "info":
+ actionInfo(req, res, note);
+ break;
case "pdf":
actionPDF(req, res, note);
break;