summaryrefslogtreecommitdiff
path: root/lib/response.js
diff options
context:
space:
mode:
authorCheng-Han, Wu2016-03-04 23:12:03 +0800
committerCheng-Han, Wu2016-03-04 23:12:03 +0800
commitc183002c14397c8b6e1ef26c1367197d987d7c62 (patch)
tree219e445c6d7988eb2dfaa860d28ee3e18b7307a2 /lib/response.js
parent04eabff3c39ac75ef69d21257dd9f7e35cf8c572 (diff)
Fixed note title might get wrong
Diffstat (limited to 'lib/response.js')
-rw-r--r--lib/response.js41
1 files changed, 18 insertions, 23 deletions
diff --git a/lib/response.js b/lib/response.js
index cc1020b3..d8f82a9f 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -56,7 +56,7 @@ var response = {
showNote: showNote,
showPublishNote: showPublishNote,
showPublishSlide: showPublishSlide,
- showIndex: showIndex,
+ showIndex: showIndex,
noteActions: noteActions,
publishNoteActions: publishNoteActions,
githubActions: githubActions
@@ -75,7 +75,7 @@ function responseError(res, code, detail, msg) {
code: code,
detail: detail,
msg: msg,
- useCDN: config.usecdn
+ useCDN: config.usecdn
});
res.write(content);
res.end();
@@ -99,16 +99,15 @@ function responseHackMD(res, noteId) {
if (err) {
return response.errorNotFound(res);
}
- var body = LZString.decompressFromBase64(data.rows[0].content);
+ var notedata = data.rows[0];
+ var body = LZString.decompressFromBase64(notedata.content);
var meta = null;
try {
meta = metaMarked(body).meta;
} catch(err) {
//na
}
- var title = data.rows[0].title;
- var decodedTitle = LZString.decompressFromBase64(title);
- if (decodedTitle) title = decodedTitle;
+ var title = Note.decodeTitle(notedata.title);
title = Note.generateWebTitle(title);
var template = config.hackmdpath;
var options = {
@@ -231,9 +230,7 @@ function showPublishNote(req, res, next) {
}
var updatetime = notedata.update_time;
var text = S(body).escapeHTML().s;
- var title = notedata.title;
- var decodedTitle = LZString.decompressFromBase64(title);
- if (decodedTitle) title = decodedTitle;
+ var title = Note.decodeTitle(notedata.title);
title = Note.generateWebTitle(title);
var origin = config.getserverurl();
var data = {
@@ -325,13 +322,16 @@ function actionDownload(req, res, noteId) {
if (err) {
return response.errorNotFound(res);
}
- var body = LZString.decompressFromBase64(data.rows[0].content);
- var title = Note.getNoteTitle(body);
+ var notedata = data.rows[0];
+ var body = LZString.decompressFromBase64(notedata.content);
+ var title = Note.decodeTitle(notedata.title);
+ var filename = title;
+ filename = encodeURIComponent(filename);
res.writeHead(200, {
'Access-Control-Allow-Origin': '*', //allow CORS as API
'Content-Type': 'text/markdown; charset=UTF-8',
'Cache-Control': 'private',
- 'Content-disposition': 'attachment; filename=' + title + '.md',
+ 'Content-disposition': 'attachment; filename=' + filename + '.md',
'Content-Length': body.length
});
res.end(body);
@@ -343,13 +343,14 @@ function actionPDF(req, res, noteId) {
if (err) {
return response.errorNotFound(res);
}
- var body = LZString.decompressFromBase64(data.rows[0].content);
+ var notedata = data.rows[0];
+ var body = LZString.decompressFromBase64(notedata.content);
try {
body = metaMarked(body).markdown;
} catch(err) {
//na
}
- var title = Note.getNoteTitle(body);
+ var title = Note.decodeTitle(notedata.title);
if (!fs.existsSync(config.tmppath)) {
fs.mkdirSync(config.tmppath);
@@ -545,10 +546,7 @@ function githubActionGist(req, res, noteId) {
var access_token = body.access_token;
if (access_token) {
var content = LZString.decompressFromBase64(notedata.content);
- var title = notedata.title;
- var decodedTitle = LZString.decompressFromBase64(title);
- if (decodedTitle) title = decodedTitle;
- else title = 'Untitled';
+ var title = Note.decodeTitle(notedata.title);
var filename = title.replace('/', ' ') + '.md';
var gist = {
"files": {}
@@ -612,9 +610,7 @@ function showPublishSlide(req, res, next) {
} catch(err) {
//na
}
- var title = notedata.title;
- var decodedTitle = LZString.decompressFromBase64(title);
- if (decodedTitle) title = decodedTitle;
+ var title = Note.decodeTitle(notedata.title);
title = Note.generateWebTitle(title);
var text = S(body).escapeHTML().s;
render(res, title, text);
@@ -640,5 +636,4 @@ var render = function (res, title, markdown) {
}));
};
-
-module.exports = response;
+module.exports = response; \ No newline at end of file