mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-29 05:04:22 -05:00
Fixed note title might get wrong
This commit is contained in:
parent
04eabff3c3
commit
c183002c14
2 changed files with 27 additions and 23 deletions
|
@ -47,6 +47,7 @@ var note = {
|
|||
checkNoteIdValid: checkNoteIdValid,
|
||||
checkNoteExist: checkNoteExist,
|
||||
getNoteTitle: getNoteTitle,
|
||||
decodeTitle: decodeTitle,
|
||||
generateWebTitle: generateWebTitle,
|
||||
increaseViewCount: increaseViewCount,
|
||||
updatePermission: updatePermission,
|
||||
|
@ -96,6 +97,14 @@ function getNoteTitle(body) {
|
|||
return title;
|
||||
}
|
||||
|
||||
// decode title
|
||||
function decodeTitle(title) {
|
||||
var decodedTitle = LZString.decompressFromBase64(title);
|
||||
if (decodedTitle) title = decodedTitle;
|
||||
else title = 'Untitled';
|
||||
return title;
|
||||
}
|
||||
|
||||
//generate note web page title
|
||||
function generateWebTitle(title) {
|
||||
title = !title || title == "Untitled" ? "HackMD - Collaborative notes" : title + " - HackMD";
|
||||
|
|
|
@ -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;
|
Loading…
Reference in a new issue