@@ -56,7 +56,7 @@ var response = {
5656 showNote : showNote ,
5757 showPublishNote : showPublishNote ,
5858 showPublishSlide : showPublishSlide ,
59- showIndex : showIndex ,
59+ showIndex : showIndex ,
6060 noteActions : noteActions ,
6161 publishNoteActions : publishNoteActions ,
6262 githubActions : githubActions
@@ -75,7 +75,7 @@ function responseError(res, code, detail, msg) {
7575 code : code ,
7676 detail : detail ,
7777 msg : msg ,
78- useCDN : config . usecdn
78+ useCDN : config . usecdn
7979 } ) ;
8080 res . write ( content ) ;
8181 res . end ( ) ;
@@ -99,16 +99,15 @@ function responseHackMD(res, noteId) {
9999 if ( err ) {
100100 return response . errorNotFound ( res ) ;
101101 }
102- var body = LZString . decompressFromBase64 ( data . rows [ 0 ] . content ) ;
102+ var notedata = data . rows [ 0 ] ;
103+ var body = LZString . decompressFromBase64 ( notedata . content ) ;
103104 var meta = null ;
104105 try {
105106 meta = metaMarked ( body ) . meta ;
106107 } catch ( err ) {
107108 //na
108109 }
109- var title = data . rows [ 0 ] . title ;
110- var decodedTitle = LZString . decompressFromBase64 ( title ) ;
111- if ( decodedTitle ) title = decodedTitle ;
110+ var title = Note . decodeTitle ( notedata . title ) ;
112111 title = Note . generateWebTitle ( title ) ;
113112 var template = config . hackmdpath ;
114113 var options = {
@@ -231,9 +230,7 @@ function showPublishNote(req, res, next) {
231230 }
232231 var updatetime = notedata . update_time ;
233232 var text = S ( body ) . escapeHTML ( ) . s ;
234- var title = notedata . title ;
235- var decodedTitle = LZString . decompressFromBase64 ( title ) ;
236- if ( decodedTitle ) title = decodedTitle ;
233+ var title = Note . decodeTitle ( notedata . title ) ;
237234 title = Note . generateWebTitle ( title ) ;
238235 var origin = config . getserverurl ( ) ;
239236 var data = {
@@ -325,13 +322,16 @@ function actionDownload(req, res, noteId) {
325322 if ( err ) {
326323 return response . errorNotFound ( res ) ;
327324 }
328- var body = LZString . decompressFromBase64 ( data . rows [ 0 ] . content ) ;
329- var title = Note . getNoteTitle ( body ) ;
325+ var notedata = data . rows [ 0 ] ;
326+ var body = LZString . decompressFromBase64 ( notedata . content ) ;
327+ var title = Note . decodeTitle ( notedata . title ) ;
328+ var filename = title ;
329+ filename = encodeURIComponent ( filename ) ;
330330 res . writeHead ( 200 , {
331331 'Access-Control-Allow-Origin' : '*' , //allow CORS as API
332332 'Content-Type' : 'text/markdown; charset=UTF-8' ,
333333 'Cache-Control' : 'private' ,
334- 'Content-disposition' : 'attachment; filename=' + title + '.md' ,
334+ 'Content-disposition' : 'attachment; filename=' + filename + '.md' ,
335335 'Content-Length' : body . length
336336 } ) ;
337337 res . end ( body ) ;
@@ -343,13 +343,14 @@ function actionPDF(req, res, noteId) {
343343 if ( err ) {
344344 return response . errorNotFound ( res ) ;
345345 }
346- var body = LZString . decompressFromBase64 ( data . rows [ 0 ] . content ) ;
346+ var notedata = data . rows [ 0 ] ;
347+ var body = LZString . decompressFromBase64 ( notedata . content ) ;
347348 try {
348349 body = metaMarked ( body ) . markdown ;
349350 } catch ( err ) {
350351 //na
351352 }
352- var title = Note . getNoteTitle ( body ) ;
353+ var title = Note . decodeTitle ( notedata . title ) ;
353354
354355 if ( ! fs . existsSync ( config . tmppath ) ) {
355356 fs . mkdirSync ( config . tmppath ) ;
@@ -545,10 +546,7 @@ function githubActionGist(req, res, noteId) {
545546 var access_token = body . access_token ;
546547 if ( access_token ) {
547548 var content = LZString . decompressFromBase64 ( notedata . content ) ;
548- var title = notedata . title ;
549- var decodedTitle = LZString . decompressFromBase64 ( title ) ;
550- if ( decodedTitle ) title = decodedTitle ;
551- else title = 'Untitled' ;
549+ var title = Note . decodeTitle ( notedata . title ) ;
552550 var filename = title . replace ( '/' , ' ' ) + '.md' ;
553551 var gist = {
554552 "files" : { }
@@ -612,9 +610,7 @@ function showPublishSlide(req, res, next) {
612610 } catch ( err ) {
613611 //na
614612 }
615- var title = notedata . title ;
616- var decodedTitle = LZString . decompressFromBase64 ( title ) ;
617- if ( decodedTitle ) title = decodedTitle ;
613+ var title = Note . decodeTitle ( notedata . title ) ;
618614 title = Note . generateWebTitle ( title ) ;
619615 var text = S ( body ) . escapeHTML ( ) . s ;
620616 render ( res , title , text ) ;
@@ -640,5 +636,4 @@ var render = function (res, title, markdown) {
640636 } ) ) ;
641637} ;
642638
643-
644- module . exports = response ;
639+ module . exports = response ;
0 commit comments