diff --git a/lib/response.js b/lib/response.js index 39d83ca29..b61fe51d2 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;