From 4d7c3d21206ef61de2323f2138dd99cf5dbf5d31 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Fri, 19 Aug 2016 11:24:36 +0800 Subject: [PATCH] Add info api for note --- lib/response.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/response.js b/lib/response.js index 39d83ca..b61fe51 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;