Skip to content

Commit 8e72eb5

Browse files
authored
Merge pull request #1548 from hackmdio/feature/list-my-note-api
List-my-note API
2 parents 6804711 + 03bc329 commit 8e72eb5

File tree

14 files changed

+92
-46
lines changed

14 files changed

+92
-46
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ public/uploads/*
2828
!public/uploads/.gitkeep
2929
/.nyc_output
3030
/coverage/
31+
32+
.vscode/settings.json

lib/auth/gitlab/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const gitlabAuthStrategy = new GitlabStrategy({
1818
callbackURL: config.serverURL + '/auth/gitlab/callback'
1919
}, passportGeneralCallback)
2020

21-
if (process.env['https_proxy']) {
22-
const httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy'])
21+
if (process.env.https_proxy) {
22+
const httpsProxyAgent = new HttpsProxyAgent(process.env.https_proxy)
2323
gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent)
2424
}
2525

lib/history/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function historyPost (req, res) {
131131
if (req.isAuthenticated()) {
132132
var noteId = req.params.noteId
133133
if (!noteId) {
134-
if (typeof req.body['history'] === 'undefined') return response.errorBadRequest(req, res)
134+
if (typeof req.body.history === 'undefined') return response.errorBadRequest(req, res)
135135
if (config.debug) { logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history) }
136136
try {
137137
var history = JSON.parse(req.body.history)
@@ -147,7 +147,7 @@ function historyPost (req, res) {
147147
return response.errorBadRequest(req, res)
148148
}
149149
} else {
150-
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(req, res)
150+
if (typeof req.body.pinned === 'undefined') return response.errorBadRequest(req, res)
151151
getHistory(req.user.id, function (err, history) {
152152
if (err) return response.errorInternalError(req, res)
153153
if (!history) return response.errorNotFound(req, res)

lib/note/index.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
const config = require('../config')
44
const logger = require('../logger')
5-
65
const { Note, User } = require('../models')
76

8-
const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound } = require('../response')
7+
const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, errorInternalError } = require('../response')
98
const { updateHistory } = require('../history')
109
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions')
1110

@@ -191,6 +190,49 @@ async function noteActions (req, res) {
191190
}
192191
}
193192

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+
194235
exports.showNote = showNote
195236
exports.showPublishNote = showPublishNote
196237
exports.noteActions = noteActions
238+
exports.listMyNotes = listMyNotes

lib/routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ appRouter.get('/s/:shortid/:action', response.publishNoteActions)
7070
appRouter.get('/p/:shortid', response.showPublishSlide)
7171
// publish slide actions
7272
appRouter.get('/p/:shortid/:action', response.publishSlideActions)
73+
// gey my note list
74+
appRouter.get('/api/notes/myNotes', noteController.listMyNotes)
7375
// get note by id
7476
appRouter.get('/:noteId', wrap(noteController.showNote))
7577
// note actions

public/js/extra.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ export function finishView (view) {
474474
const { lat, lon } = data[0]
475475
position = [lat, lon]
476476
}
477-
$elem.html(`<div class="geo-map"></div>`)
477+
$elem.html('<div class="geo-map"></div>')
478478
const map = L.map($elem.find('.geo-map')[0]).setView(position, zoom || 16)
479479

480480
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
@@ -1017,7 +1017,7 @@ export function deduplicatedHeaderId (view) {
10171017
if (window.linkifyHeaderStyle === 'gfm') {
10181018
// consistent with GitHub, GitLab, Pandoc & co.
10191019
// all headers contained in the document, in order of appearance
1020-
const allHeaders = view.find(`:header`).toArray()
1020+
const allHeaders = view.find(':header').toArray()
10211021
// list of finaly assigned header IDs
10221022
const headerIds = new Set()
10231023
for (let j = 0; j < allHeaders.length; j++) {
@@ -1177,7 +1177,7 @@ md.use(markdownitContainer, 'spoiler', {
11771177
if (summary) {
11781178
return `<details><summary>${md.renderInline(summary)}</summary>\n`
11791179
} else {
1180-
return `<details>\n`
1180+
return '<details>\n'
11811181
}
11821182
} else {
11831183
// closing tag

public/js/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ socket.on('reconnect', function (data) {
17891789
socket.on('connect', function (data) {
17901790
clearInterval(retryTimer)
17911791
retryTimer = null
1792-
personalInfo['id'] = socket.id
1792+
personalInfo.id = socket.id
17931793
showStatus(statusType.connected)
17941794
socket.emit('version')
17951795
})
@@ -2359,8 +2359,8 @@ function emitUserStatus (force) {
23592359
var type = null
23602360
if (visibleXS) { type = 'xs' } else if (visibleSM) { type = 'sm' } else if (visibleMD) { type = 'md' } else if (visibleLG) { type = 'lg' }
23612361

2362-
personalInfo['idle'] = idle.isAway
2363-
personalInfo['type'] = type
2362+
personalInfo.idle = idle.isAway
2363+
personalInfo.type = type
23642364

23652365
for (var i = 0; i < onlineUsers.length; i++) {
23662366
if (onlineUsers[i].id === personalInfo.id) {
@@ -2637,7 +2637,7 @@ editorInstance.on('focus', function (editor) {
26372637
onlineUsers[i].cursor = editor.getCursor()
26382638
}
26392639
}
2640-
personalInfo['cursor'] = editor.getCursor()
2640+
personalInfo.cursor = editor.getCursor()
26412641
socket.emit('cursor focus', editor.getCursor())
26422642
})
26432643

@@ -2650,7 +2650,7 @@ function cursorActivityInner (editor) {
26502650
onlineUsers[i].cursor = editor.getCursor()
26512651
}
26522652
}
2653-
personalInfo['cursor'] = editor.getCursor()
2653+
personalInfo.cursor = editor.getCursor()
26542654
socket.emit('cursor activity', editor.getCursor())
26552655
}
26562656
}
@@ -2697,7 +2697,7 @@ editorInstance.on('blur', function (cm) {
26972697
onlineUsers[i].cursor = null
26982698
}
26992699
}
2700-
personalInfo['cursor'] = null
2700+
personalInfo.cursor = null
27012701
socket.emit('cursor blur')
27022702
})
27032703

public/js/lib/editor/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ export const availableThemes = [
1616
{ name: 'Tomorror Night Eighties', value: 'tomorrow-night-eighties' }
1717
]
1818

19-
export const emojifyImageDir = window.USE_CDN ? `https://cdn.jsdelivr.net/npm/@hackmd/emojify.js@2.1.0/dist/images/basic` : `${serverurl}/build/emojify.js/dist/images/basic`
19+
export const emojifyImageDir = window.USE_CDN ? 'https://cdn.jsdelivr.net/npm/@hackmd/emojify.js@2.1.0/dist/images/basic' : `${serverurl}/build/emojify.js/dist/images/basic`

public/js/lib/editor/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ export default class Editor {
592592
if (lang) {
593593
this.statusIndicators.find(`.status-spellcheck li[value="${lang}"]`).addClass('active')
594594
} else {
595-
this.statusIndicators.find(`.status-spellcheck li[value="disabled"]`).addClass('active')
595+
this.statusIndicators.find('.status-spellcheck li[value="disabled"]').addClass('active')
596596
}
597597
}
598598

@@ -632,7 +632,7 @@ export default class Editor {
632632
}
633633

634634
const self = this
635-
this.statusIndicators.find(`.status-spellcheck li`).click(function () {
635+
this.statusIndicators.find('.status-spellcheck li').click(function () {
636636
const lang = $(this).attr('value')
637637

638638
if (lang === 'disabled') {

public/js/lib/editor/spellcheck.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,35 @@ export const supportLanguages = [
2323
value: 'de',
2424
aff: {
2525
url: `${serverurl}/build/dictionary-de/index.aff`,
26-
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.aff`
26+
cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.aff'
2727
},
2828
dic: {
2929
url: `${serverurl}/build/dictionary-de/index.dic`,
30-
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.dic`
30+
cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.dic'
3131
}
3232
},
3333
{
3434
name: 'German (Austria)',
3535
value: 'de_AT',
3636
aff: {
3737
url: `${serverurl}/build/dictionary-de-at/index.aff`,
38-
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.aff`
38+
cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.aff'
3939
},
4040
dic: {
4141
url: `${serverurl}/build/dictionary-de-at/index.dic`,
42-
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.dic`
42+
cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.dic'
4343
}
4444
},
4545
{
4646
name: 'German (Switzerland)',
4747
value: 'de_CH',
4848
aff: {
4949
url: `${serverurl}/build/dictionary-de-ch/index.aff`,
50-
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.aff`
50+
cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.aff'
5151
},
5252
dic: {
5353
url: `${serverurl}/build/dictionary-de-ch/index.dic`,
54-
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.dic`
54+
cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.dic'
5555
}
5656
}
5757
]

0 commit comments

Comments
 (0)