Add info api for note

This commit is contained in:
Wu Cheng-Han 2016-08-19 11:24:36 +08:00
parent 058c35730b
commit 4d7c3d2120

View file

@ -294,6 +294,35 @@ function actionDownload(req, res, note) {
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling 'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
}); });
res.end(body); 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) { function actionPDF(req, res, note) {
@ -382,6 +411,9 @@ function noteActions(req, res, next) {
case "download": case "download":
actionDownload(req, res, note); actionDownload(req, res, note);
break; break;
case "info":
actionInfo(req, res, note);
break;
case "pdf": case "pdf":
actionPDF(req, res, note); actionPDF(req, res, note);
break; break;