|
2 | 2 |
|
3 | 3 | const config = require('../config')
|
4 | 4 | const logger = require('../logger')
|
5 |
| - |
6 | 5 | const { Note, User } = require('../models')
|
7 | 6 |
|
8 |
| -const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound } = require('../response') |
| 7 | +const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, errorInternalError } = require('../response') |
9 | 8 | const { updateHistory } = require('../history')
|
10 | 9 | const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions')
|
11 | 10 |
|
@@ -121,6 +120,7 @@ async function showPublishNote (req, res) {
|
121 | 120 | const data = {
|
122 | 121 | title: title,
|
123 | 122 | description: meta.description || (markdown ? Note.generateDescription(markdown) : null),
|
| 123 | + image: meta.image, |
124 | 124 | viewcount: note.viewcount,
|
125 | 125 | createtime: createTime,
|
126 | 126 | updatetime: updateTime,
|
@@ -190,6 +190,49 @@ async function noteActions (req, res) {
|
190 | 190 | }
|
191 | 191 | }
|
192 | 192 |
|
| 193 | +async function getMyNoteList (userId, callback) { |
| 194 | + const myNotes = await Note.findAll({ |
| 195 | + where: { |
| 196 | + ownerId: userId |
| 197 | + } |
| 198 | + }) |
| 199 | + if (!myNotes) { |
| 200 | + return callback(null, null) |
| 201 | + } |
| 202 | + try { |
| 203 | + const myNoteList = myNotes.map(note => ({ |
| 204 | + id: Note.encodeNoteId(note.id), |
| 205 | + text: note.title, |
| 206 | + tags: Note.parseNoteInfo(note.content).tags, |
| 207 | + createdAt: note.createdAt, |
| 208 | + lastchangeAt: note.lastchangeAt, |
| 209 | + shortId: note.shortid |
| 210 | + })) |
| 211 | + if (config.debug) { |
| 212 | + logger.info('Parse myNoteList success: ' + userId) |
| 213 | + } |
| 214 | + return callback(null, myNoteList) |
| 215 | + } catch (err) { |
| 216 | + logger.error('Parse myNoteList failed') |
| 217 | + return callback(err, null) |
| 218 | + } |
| 219 | +} |
| 220 | + |
| 221 | +function listMyNotes (req, res) { |
| 222 | + if (req.isAuthenticated()) { |
| 223 | + getMyNoteList(req.user.id, (err, myNoteList) => { |
| 224 | + if (err) return errorInternalError(req, res) |
| 225 | + if (!myNoteList) return errorNotFound(req, res) |
| 226 | + res.send({ |
| 227 | + myNotes: myNoteList |
| 228 | + }) |
| 229 | + }) |
| 230 | + } else { |
| 231 | + return errorForbidden(req, res) |
| 232 | + } |
| 233 | +} |
| 234 | + |
193 | 235 | exports.showNote = showNote
|
194 | 236 | exports.showPublishNote = showPublishNote
|
195 | 237 | exports.noteActions = noteActions
|
| 238 | +exports.listMyNotes = listMyNotes |
0 commit comments