@@ -8,7 +8,7 @@ const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, e
88const { updateHistory } = require ( '../history' )
99const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require ( './noteActions' )
1010
11- async function getNoteById ( noteId , { includeUser } = { includeUser : false } ) {
11+ async function getNoteById ( noteId , { includeUser } = { includeUser : false } ) {
1212 const id = await Note . parseNoteIdAsync ( noteId )
1313
1414 const includes = [ ]
@@ -32,7 +32,7 @@ async function getNoteById (noteId, { includeUser } = { includeUser: false }) {
3232 return note
3333}
3434
35- async function createNote ( userId , noteAlias ) {
35+ async function createNote ( userId , noteAlias ) {
3636 if ( ! config . allowAnonymous && ! userId ) {
3737 throw new Error ( 'can not create note' )
3838 }
@@ -50,7 +50,7 @@ async function createNote (userId, noteAlias) {
5050}
5151
5252// controller
53- async function showNote ( req , res ) {
53+ async function showNote ( req , res ) {
5454 const noteId = req . params . noteId
5555 const userId = req . user ? req . user . id : null
5656
@@ -78,7 +78,7 @@ async function showNote (req, res) {
7878 return responseCodiMD ( res , note )
7979}
8080
81- function canViewNote ( note , isLogin , userId ) {
81+ function canViewNote ( note , isLogin , userId ) {
8282 if ( note . permission === 'private' ) {
8383 return note . ownerId === userId
8484 }
@@ -88,7 +88,7 @@ function canViewNote (note, isLogin, userId) {
8888 return true
8989}
9090
91- async function showPublishNote ( req , res ) {
91+ async function showPublishNote ( req , res ) {
9292 const shortid = req . params . shortid
9393
9494 const note = await getNoteById ( shortid , {
@@ -141,7 +141,7 @@ async function showPublishNote (req, res) {
141141 res . render ( 'pretty.ejs' , data )
142142}
143143
144- async function noteActions ( req , res ) {
144+ async function noteActions ( req , res ) {
145145 const noteId = req . params . noteId
146146
147147 const note = await getNoteById ( noteId )
@@ -189,30 +189,26 @@ async function noteActions (req, res) {
189189 }
190190}
191191
192- async function getMyNoteList ( userid , callback ) {
192+ async function getMyNoteList ( userId , callback ) {
193193 const myNotes = await Note . findAll ( {
194194 where : {
195- ownerId : userid
195+ ownerId : userId
196196 }
197197 } )
198198 if ( ! myNotes ) {
199199 return callback ( null , null )
200200 }
201201 try {
202- const myNoteList = [ ]
203- for ( let i = 0 ; i < myNotes . length ; i ++ ) {
204- const note = myNotes [ i ]
205- myNoteList [ i ] = {
206- id : Note . encodeNoteId ( note . id ) ,
207- text : note . title ,
208- tags : Note . parseNoteInfo ( note . content ) . tags ,
209- createdAt : note . createdAt ,
210- lastchangeAt : note . lastchangeAt ,
211- shortId : note . shortid
212- }
213- }
202+ const myNoteList = myNotes . map ( note => ( {
203+ id : Note . encodeNoteId ( note . id ) ,
204+ text : note . title ,
205+ tags : Note . parseNoteInfo ( note . content ) . tags ,
206+ createdAt : note . createdAt ,
207+ lastchangeAt : note . lastchangeAt ,
208+ shortId : note . shortid
209+ } ) )
214210 if ( config . debug ) {
215- logger . info ( 'Parse myNoteList success: ' + userid )
211+ logger . info ( 'Parse myNoteList success: ' + userId )
216212 }
217213 return callback ( null , myNoteList )
218214 } catch ( err ) {
@@ -221,7 +217,7 @@ async function getMyNoteList (userid, callback) {
221217 }
222218}
223219
224- function listMyNotes ( req , res ) {
220+ function listMyNotes ( req , res ) {
225221 if ( req . isAuthenticated ( ) ) {
226222 getMyNoteList ( req . user . id , ( err , myNoteList ) => {
227223 if ( err ) return errorInternalError ( req , res )
0 commit comments