Skip to content

Commit d44be73

Browse files
committed
fix linter error
Signed-off-by: nick.chen <[email protected]>
1 parent 9ded54e commit d44be73

File tree

5 files changed

+76
-77
lines changed

5 files changed

+76
-77
lines changed

lib/migrations/202106200000000-create-note-aliases-history.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ module.exports = {
2121
() => queryInterface.addIndex(
2222
'ArchivedNoteAliases',
2323
['alias'], {
24-
indicesType: 'UNIQUE'
25-
})
24+
indicesType: 'UNIQUE'
25+
})
2626
)
2727
},
2828

2929
down: function (queryInterface) {
30-
return queryInterface.dropTable('Users');
30+
return queryInterface.dropTable('Users')
3131
}
3232
}

lib/models/note.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ module.exports = function (sequelize, DataTypes) {
238238
return _callback(null, null)
239239
}
240240
return callback(null, archivedAlias.noteId)
241-
});
241+
})
242242
},
243243
parseNoteIdByAlias: function (_callback) {
244244
// try to parse note id by alias (e.g. doc)

lib/note/index.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ const config = require('../config')
44
const logger = require('../logger')
55
const { Note, User, Revision } = require('../models')
66

7-
const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, errorInternalError, responseError } = require('../response')
7+
const { newCheckViewPermission, errorForbidden, responseCodiMD, errorNotFound, errorInternalError } = require('../response')
88
const { updateHistory, historyDelete } = require('../history')
99
const { actionPublish, actionSlide, actionInfo, actionDownload, actionPDF, actionGist, actionRevision, actionPandoc } = require('./noteActions')
1010
const realtime = require('../realtime/realtime')
11-
const serv = require('./service');
11+
const serv = require('./service')
1212

1313
async function getNoteById (noteId, { includeUser } = { includeUser: false }) {
1414
const id = await Note.parseNoteIdAsync(noteId)
@@ -334,53 +334,52 @@ const updateNote = async (req, res) => {
334334
}
335335

336336
const checkAliasValid = async (req, res) => {
337-
const originAliasOrNoteId = req.params.originAliasOrNoteId;
338-
const alias = req.query.alias;
337+
const originAliasOrNoteId = req.params.originAliasOrNoteId
338+
const alias = req.query.alias
339339
const isValid = await serv.asyncCheckAliasValid(originAliasOrNoteId, alias)
340340
.catch((err) => {
341-
logger.error(err.message);
342-
return res.status(500).send('Internal Error.');
341+
logger.error(err.message)
342+
return res.status(500).send('Internal Error.')
343343
})
344344

345345
res.send({
346346
status: 'ok',
347347
isValid
348-
});
348+
})
349349
}
350350

351351
const updateNoteAlias = async (req, res) => {
352-
const originAliasOrNoteId = req.params.originAliasOrNoteId;
353-
const alias = req.body.alias || '';
352+
const originAliasOrNoteId = req.params.originAliasOrNoteId
353+
const alias = req.body.alias || ''
354354
const userId = req.user ? req.user.id : null
355355
const note = await serv.asyncGetNote(originAliasOrNoteId)
356356
.catch((err) => {
357-
logger.error('get note failed:' + err.message);
358-
return false;
357+
logger.error('get note failed:' + err.message)
358+
return false
359359
})
360360

361-
if (note.ownerId != userId) {
362-
return res.status(403).send('Forbidden.');
361+
if (note.ownerId !== userId) {
362+
return res.status(403).send('Forbidden.')
363363
}
364364

365365
const isValid = await serv.asyncCheckAliasValid(originAliasOrNoteId, alias)
366366
.catch((err) => {
367-
logger.error(err.message);
368-
return res.status(500).send('Internal Error.');
367+
logger.error(err.message)
368+
return res.status(500).send('Internal Error.')
369369
})
370370

371371
if (!isValid) {
372-
console.log("\n\n\n", err.message, "\n\n\n");
373-
return res.status(400).send('Bad Request.');
372+
return res.status(400).send('Bad Request.')
374373
}
375374

376375
const isSuccess = await serv.asyncUpdateAlias(originAliasOrNoteId, alias)
377376
.catch((err) => {
378-
logger.error('update note alias failed:' + err.message);
379-
return false;
377+
logger.error('update note alias failed:' + err.message)
378+
return false
380379
})
381380

382381
if (!isSuccess) {
383-
return res.status(500).send('Internal Error.');
382+
return res.status(500).send('Internal Error.')
384383
}
385384

386385
res.send({

lib/note/service.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11

2-
const { Note, ArchivedNoteAlias, sequelize } = require('../models');
3-
const realtime = require('../realtime/realtime');
2+
const { Note, ArchivedNoteAlias, sequelize } = require('../models')
3+
const realtime = require('../realtime/realtime')
44

5-
const forbiddenAlias = ['', 'new', 'me', 'history', '403', '404', '500', 'config'];
5+
const forbiddenAlias = ['', 'new', 'me', 'history', '403', '404', '500', 'config']
66
const sanitize = (alias) => {
7-
return alias.replace(/( |\/)/, '');
7+
return alias.replace(/( |\/)/, '')
88
}
99

1010
const asyncGetNote = async (originAliasOrNoteId) => {
11-
const noteId = await Note.parseNoteIdAsync(originAliasOrNoteId);
11+
const noteId = await Note.parseNoteIdAsync(originAliasOrNoteId)
1212
const note = await Note.findOne({
1313
where: {
1414
id: noteId
1515
}
1616
})
1717
if (!note) {
18-
throw Error('Can\'t find the note.');
18+
throw Error('Can\'t find the note.')
1919
}
20-
return note;
20+
return note
2121
}
2222

2323
const asyncGetNoteIdForAliasConflict = async (alias) => {
24-
const sanitizedAlias = sanitize(alias);
24+
const sanitizedAlias = sanitize(alias)
2525
const p1 = Note.findOne({
2626
where: {
2727
alias: sanitizedAlias
2828
}
29-
});
29+
})
3030
const p2 = ArchivedNoteAlias.findOne({
3131
where: {
3232
alias: sanitizedAlias
3333
}
34-
});
35-
const [conflictNote, conflictAarchivedAlias] = await Promise.all([p1, p2]);
34+
})
35+
const [conflictNote, conflictAarchivedAlias] = await Promise.all([p1, p2])
3636

3737
if (conflictNote) {
3838
return conflictNote.id
3939
}
4040
if (conflictAarchivedAlias) {
4141
return conflictAarchivedAlias.noteId
4242
}
43-
return null;
43+
return null
4444
}
4545

4646
const asyncCheckAliasValid = async (originAliasOrNoteId, alias) => {
47-
const sanitizedAlias = sanitize(alias);
47+
const sanitizedAlias = sanitize(alias)
4848
if (forbiddenAlias.indexOf(sanitizedAlias) > -1) {
49-
return false;
49+
return false
5050
}
5151

5252
const conflictNoteId = await asyncGetNoteIdForAliasConflict(alias)
53-
.catch((err) => { throw err });
53+
.catch((err) => { throw err })
5454

5555
const note = await asyncGetNote(originAliasOrNoteId)
56-
.catch((err) => { throw err });
56+
.catch((err) => { throw err })
5757

58-
return !conflictNoteId || conflictNoteId === note.id;
58+
return !conflictNoteId || conflictNoteId === note.id
5959
}
6060

6161
const asyncUpdateAlias = async (originAliasOrNoteId, alias) => {
62-
const sanitizedAlias = sanitize(alias);
62+
const sanitizedAlias = sanitize(alias)
6363
const note = await asyncGetNote(originAliasOrNoteId)
64-
.catch((err) => { throw err });
64+
.catch((err) => { throw err })
6565

66-
const t = await sequelize.transaction();
66+
const t = await sequelize.transaction()
6767
if (note.alias) {
6868
const archivedAlias = await ArchivedNoteAlias.findOne({
6969
where: {
70-
alias: note.alias,
70+
alias: note.alias
7171
}
7272
})
7373
.catch(async err => { throw err })
@@ -77,8 +77,8 @@ const asyncUpdateAlias = async (originAliasOrNoteId, alias) => {
7777
alias: note.alias
7878
}, { transaction: t })
7979
.catch(async err => {
80-
await t.rollback();
81-
throw Error('Add archived note alias failed. ' + err.message);
80+
await t.rollback()
81+
throw Error('Add archived note alias failed. ' + err.message)
8282
})
8383
}
8484
}
@@ -88,21 +88,21 @@ const asyncUpdateAlias = async (originAliasOrNoteId, alias) => {
8888
lastchangeAt: Date.now()
8989
}, { transaction: t })
9090
.catch(async err => {
91-
await t.rollback();
92-
throw Error('Write note content error. ' + err.message);
91+
await t.rollback()
92+
throw Error('Write note content error. ' + err.message)
9393
})
9494

95-
await t.commit();
95+
await t.commit()
9696

9797
realtime.io.to(updatedNote.id)
9898
.emit('alias updated', {
9999
alias: updatedNote.alias
100-
});
100+
})
101101

102-
return true;
102+
return true
103103
}
104104

105-
exports.sanitize = sanitize;
106-
exports.asyncGetNote = asyncGetNote;
107-
exports.asyncCheckAliasValid = asyncCheckAliasValid;
108-
exports.asyncUpdateAlias = asyncUpdateAlias;
105+
exports.sanitize = sanitize
106+
exports.asyncGetNote = asyncGetNote
107+
exports.asyncCheckAliasValid = asyncCheckAliasValid
108+
exports.asyncUpdateAlias = asyncUpdateAlias

public/js/index.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,10 +1277,10 @@ const checkNoteUrlValid = (noteUrl = '') => {
12771277
alias: noteUrl
12781278
},
12791279
success: (data) => {
1280-
resolve(data.isValid);
1280+
resolve(data.isValid)
12811281
}
12821282
})
1283-
});
1283+
})
12841284
}
12851285

12861286
const updateNoteUrl = (noteUrl = '') => {
@@ -1291,45 +1291,45 @@ const updateNoteUrl = (noteUrl = '') => {
12911291
data: JSON.stringify({
12921292
alias: noteUrl
12931293
}),
1294-
contentType: "application/json;charset=utf-8",
1294+
contentType: 'application/json;charset=utf-8',
12951295
success: (data) => {
1296-
resolve(data.status === 'ok');
1296+
resolve(data.status === 'ok')
12971297
},
12981298
error: reject
12991299
})
1300-
});
1300+
})
13011301
}
13021302

13031303
ui.modal.customNoteUrl.on('submit', function (e) {
1304-
e.preventDefault();
1304+
e.preventDefault()
13051305
const showErrorMessage = (msg) => {
1306-
ui.modal.customNoteUrl.find('.error-message').text(msg);
1307-
ui.modal.customNoteUrl.find('.alert').show();
1306+
ui.modal.customNoteUrl.find('.error-message').text(msg)
1307+
ui.modal.customNoteUrl.find('.alert').show()
13081308
}
1309-
const hideErrorMessage = () => ui.modal.customNoteUrl.find('.alert').hide();
1309+
const hideErrorMessage = () => ui.modal.customNoteUrl.find('.alert').hide()
13101310

1311-
const customUrl = ui.modal.customNoteUrl.find('[name="custom-url"]').val();
1311+
const customUrl = ui.modal.customNoteUrl.find('[name="custom-url"]').val()
13121312
checkNoteUrlValid(customUrl)
13131313
.then(isValid => {
13141314
if (!isValid) {
1315-
showErrorMessage('The url is exist.');
1316-
return ;
1315+
showErrorMessage('The url is exist.')
1316+
return
13171317
}
1318-
hideErrorMessage();
1319-
return updateNoteUrl(customUrl);
1318+
hideErrorMessage()
1319+
return updateNoteUrl(customUrl)
13201320
})
13211321
.then(isSuccess => {
1322-
if(isSuccess){
1323-
hideErrorMessage();
1322+
if (isSuccess) {
1323+
hideErrorMessage()
13241324
ui.modal.customNoteUrl.modal('hide')
13251325
}
13261326
}, err => {
1327-
if(err.status == 403){
1328-
showErrorMessage('Only note owner can edit custom url.');
1327+
if (err.status === 403) {
1328+
showErrorMessage('Only note owner can edit custom url.')
13291329
}
13301330
})
13311331
.catch((err) => {
1332-
showErrorMessage('Something wrong: ' + err.message);
1332+
showErrorMessage('Something wrong: ' + err.message)
13331333
})
13341334
})
13351335

@@ -2286,9 +2286,9 @@ socket.on('cursor blur', function (data) {
22862286
})
22872287

22882288
socket.on('alias updated', function (data) {
2289-
const alias = data.alias;
2289+
const alias = data.alias
22902290
history.replaceState({}, '', alias)
2291-
});
2291+
})
22922292

22932293
var options = {
22942294
valueNames: ['id', 'name'],

0 commit comments

Comments
 (0)