Fix standard

Signed-off-by: James Tsai <jamesscamel@gmail.com>
This commit is contained in:
James Tsai 2020-07-01 11:33:41 +08:00
parent 2973bfbceb
commit 07f32f5bbf
13 changed files with 51 additions and 52 deletions

1
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1 @@
123,125

View File

@ -18,8 +18,8 @@ const gitlabAuthStrategy = new GitlabStrategy({
callbackURL: config.serverURL + '/auth/gitlab/callback' callbackURL: config.serverURL + '/auth/gitlab/callback'
}, passportGeneralCallback) }, passportGeneralCallback)
if (process.env['https_proxy']) { if (process.env.https_proxy) {
const httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy']) const httpsProxyAgent = new HttpsProxyAgent(process.env.https_proxy)
gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent) gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent)
} }

View File

@ -131,7 +131,7 @@ function historyPost (req, res) {
if (req.isAuthenticated()) { if (req.isAuthenticated()) {
var noteId = req.params.noteId var noteId = req.params.noteId
if (!noteId) { if (!noteId) {
if (typeof req.body['history'] === 'undefined') return response.errorBadRequest(req, res) if (typeof req.body.history === 'undefined') return response.errorBadRequest(req, res)
if (config.debug) { logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history) } if (config.debug) { logger.info('SERVER received history from [' + req.user.id + ']: ' + req.body.history) }
try { try {
var history = JSON.parse(req.body.history) var history = JSON.parse(req.body.history)
@ -147,7 +147,7 @@ function historyPost (req, res) {
return response.errorBadRequest(req, res) return response.errorBadRequest(req, res)
} }
} else { } else {
if (typeof req.body['pinned'] === 'undefined') return response.errorBadRequest(req, res) if (typeof req.body.pinned === 'undefined') return response.errorBadRequest(req, res)
getHistory(req.user.id, function (err, history) { getHistory(req.user.id, function (err, history) {
if (err) return response.errorInternalError(req, res) if (err) return response.errorInternalError(req, res)
if (!history) return response.errorNotFound(req, res) if (!history) return response.errorNotFound(req, res)

View File

@ -189,7 +189,7 @@ async function noteActions (req, res) {
} }
} }
async function getMyNoteList(userid, callback) { async function getMyNoteList (userid, callback) {
const myNotes = await Note.findAll({ const myNotes = await Note.findAll({
where: { where: {
ownerId: userid ownerId: userid
@ -199,7 +199,7 @@ async function getMyNoteList(userid, callback) {
return callback(null, null) return callback(null, null)
} }
try { try {
let myNoteList = [] const myNoteList = []
for (let i = 0; i < myNotes.length; i++) { for (let i = 0; i < myNotes.length; i++) {
const note = myNotes[i] const note = myNotes[i]
myNoteList[i] = { myNoteList[i] = {
@ -215,13 +215,13 @@ async function getMyNoteList(userid, callback) {
logger.info('Parse myNoteList success: ' + userid) logger.info('Parse myNoteList success: ' + userid)
} }
return callback(null, myNoteList) return callback(null, myNoteList)
} catch (err){ } catch (err) {
logger.error('Parse myNoteList failed') logger.error('Parse myNoteList failed')
return callback(err, null) return callback(err, null)
} }
} }
function listMyNotes(req, res) { function listMyNotes (req, res) {
if (req.isAuthenticated()) { if (req.isAuthenticated()) {
getMyNoteList(req.user.id, (err, myNoteList) => { getMyNoteList(req.user.id, (err, myNoteList) => {
if (err) return errorInternalError(req, res) if (err) return errorInternalError(req, res)
@ -239,5 +239,3 @@ exports.showNote = showNote
exports.showPublishNote = showPublishNote exports.showPublishNote = showPublishNote
exports.noteActions = noteActions exports.noteActions = noteActions
exports.listMyNotes = listMyNotes exports.listMyNotes = listMyNotes

View File

@ -464,7 +464,7 @@ export function finishView (view) {
const { lat, lon } = data[0] const { lat, lon } = data[0]
position = [lat, lon] position = [lat, lon]
} }
$elem.html(`<div class="geo-map"></div>`) $elem.html('<div class="geo-map"></div>')
const map = L.map($elem.find('.geo-map')[0]).setView(position, zoom || 16) const map = L.map($elem.find('.geo-map')[0]).setView(position, zoom || 16)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
@ -975,7 +975,7 @@ export function deduplicatedHeaderId (view) {
if (window.linkifyHeaderStyle === 'gfm') { if (window.linkifyHeaderStyle === 'gfm') {
// consistent with GitHub, GitLab, Pandoc & co. // consistent with GitHub, GitLab, Pandoc & co.
// all headers contained in the document, in order of appearance // all headers contained in the document, in order of appearance
const allHeaders = view.find(`:header`).toArray() const allHeaders = view.find(':header').toArray()
// list of finaly assigned header IDs // list of finaly assigned header IDs
const headerIds = new Set() const headerIds = new Set()
for (let j = 0; j < allHeaders.length; j++) { for (let j = 0; j < allHeaders.length; j++) {
@ -1133,7 +1133,7 @@ md.use(markdownitContainer, 'spoiler', {
if (summary) { if (summary) {
return `<details><summary>${md.renderInline(summary)}</summary>\n` return `<details><summary>${md.renderInline(summary)}</summary>\n`
} else { } else {
return `<details>\n` return '<details>\n'
} }
} else { } else {
// closing tag // closing tag

View File

@ -1789,7 +1789,7 @@ socket.on('reconnect', function (data) {
socket.on('connect', function (data) { socket.on('connect', function (data) {
clearInterval(retryTimer) clearInterval(retryTimer)
retryTimer = null retryTimer = null
personalInfo['id'] = socket.id personalInfo.id = socket.id
showStatus(statusType.connected) showStatus(statusType.connected)
socket.emit('version') socket.emit('version')
}) })
@ -2359,8 +2359,8 @@ function emitUserStatus (force) {
var type = null var type = null
if (visibleXS) { type = 'xs' } else if (visibleSM) { type = 'sm' } else if (visibleMD) { type = 'md' } else if (visibleLG) { type = 'lg' } if (visibleXS) { type = 'xs' } else if (visibleSM) { type = 'sm' } else if (visibleMD) { type = 'md' } else if (visibleLG) { type = 'lg' }
personalInfo['idle'] = idle.isAway personalInfo.idle = idle.isAway
personalInfo['type'] = type personalInfo.type = type
for (var i = 0; i < onlineUsers.length; i++) { for (var i = 0; i < onlineUsers.length; i++) {
if (onlineUsers[i].id === personalInfo.id) { if (onlineUsers[i].id === personalInfo.id) {
@ -2637,7 +2637,7 @@ editorInstance.on('focus', function (editor) {
onlineUsers[i].cursor = editor.getCursor() onlineUsers[i].cursor = editor.getCursor()
} }
} }
personalInfo['cursor'] = editor.getCursor() personalInfo.cursor = editor.getCursor()
socket.emit('cursor focus', editor.getCursor()) socket.emit('cursor focus', editor.getCursor())
}) })
@ -2650,7 +2650,7 @@ function cursorActivityInner (editor) {
onlineUsers[i].cursor = editor.getCursor() onlineUsers[i].cursor = editor.getCursor()
} }
} }
personalInfo['cursor'] = editor.getCursor() personalInfo.cursor = editor.getCursor()
socket.emit('cursor activity', editor.getCursor()) socket.emit('cursor activity', editor.getCursor())
} }
} }
@ -2697,7 +2697,7 @@ editorInstance.on('blur', function (cm) {
onlineUsers[i].cursor = null onlineUsers[i].cursor = null
} }
} }
personalInfo['cursor'] = null personalInfo.cursor = null
socket.emit('cursor blur') socket.emit('cursor blur')
}) })

View File

@ -16,4 +16,4 @@ export const availableThemes = [
{ name: 'Tomorror Night Eighties', value: 'tomorrow-night-eighties' } { name: 'Tomorror Night Eighties', value: 'tomorrow-night-eighties' }
] ]
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` 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`

View File

@ -587,7 +587,7 @@ export default class Editor {
if (lang) { if (lang) {
this.statusIndicators.find(`.status-spellcheck li[value="${lang}"]`).addClass('active') this.statusIndicators.find(`.status-spellcheck li[value="${lang}"]`).addClass('active')
} else { } else {
this.statusIndicators.find(`.status-spellcheck li[value="disabled"]`).addClass('active') this.statusIndicators.find('.status-spellcheck li[value="disabled"]').addClass('active')
} }
} }
@ -627,7 +627,7 @@ export default class Editor {
} }
const self = this const self = this
this.statusIndicators.find(`.status-spellcheck li`).click(function () { this.statusIndicators.find('.status-spellcheck li').click(function () {
const lang = $(this).attr('value') const lang = $(this).attr('value')
if (lang === 'disabled') { if (lang === 'disabled') {

View File

@ -23,11 +23,11 @@ export const supportLanguages = [
value: 'de', value: 'de',
aff: { aff: {
url: `${serverurl}/build/dictionary-de/index.aff`, url: `${serverurl}/build/dictionary-de/index.aff`,
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.aff` cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.aff'
}, },
dic: { dic: {
url: `${serverurl}/build/dictionary-de/index.dic`, url: `${serverurl}/build/dictionary-de/index.dic`,
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.dic` cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de@2.0.3/index.dic'
} }
}, },
{ {
@ -35,11 +35,11 @@ export const supportLanguages = [
value: 'de_AT', value: 'de_AT',
aff: { aff: {
url: `${serverurl}/build/dictionary-de-at/index.aff`, url: `${serverurl}/build/dictionary-de-at/index.aff`,
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.aff` cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.aff'
}, },
dic: { dic: {
url: `${serverurl}/build/dictionary-de-at/index.dic`, url: `${serverurl}/build/dictionary-de-at/index.dic`,
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.dic` cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-at@2.0.3/index.dic'
} }
}, },
{ {
@ -47,11 +47,11 @@ export const supportLanguages = [
value: 'de_CH', value: 'de_CH',
aff: { aff: {
url: `${serverurl}/build/dictionary-de-ch/index.aff`, url: `${serverurl}/build/dictionary-de-ch/index.aff`,
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.aff` cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.aff'
}, },
dic: { dic: {
url: `${serverurl}/build/dictionary-de-ch/index.dic`, url: `${serverurl}/build/dictionary-de-ch/index.dic`,
cdnUrl: `https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.dic` cdnUrl: 'https://cdn.jsdelivr.net/npm/dictionary-de-ch@2.0.3/index.dic'
} }
} }
] ]

View File

@ -7,10 +7,10 @@ export function parseFenceCodeParams (lang) {
paraMatch && paraMatch.forEach(param => { paraMatch && paraMatch.forEach(param => {
param = param.trim() param = param.trim()
if (param[0] === '#') { if (param[0] === '#') {
params['id'] = param.slice(1) params.id = param.slice(1)
} else if (param[0] === '.') { } else if (param[0] === '.') {
if (params['class']) params['class'] = [] if (params.class) params.class = []
params['class'] = params['class'].concat(param.slice(1)) params.class = params.class.concat(param.slice(1))
} else { } else {
const offset = param.indexOf('=') const offset = param.indexOf('=')
const id = param.substring(0, offset).trim().toLowerCase() const id = param.substring(0, offset).trim().toLowerCase()
@ -21,8 +21,8 @@ export function parseFenceCodeParams (lang) {
val = val.substring(1, val.length - 1) val = val.substring(1, val.length - 1)
} }
if (id === 'class') { if (id === 'class') {
if (params['class']) params['class'] = [] if (params.class) params.class = []
params['class'] = params['class'].concat(val) params.class = params.class.concat(val)
} else { } else {
params[id] = val params[id] = val
} }

View File

@ -12,27 +12,27 @@ var dataUriRegex = /^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base
// custom white list // custom white list
var whiteList = filterXSS.whiteList var whiteList = filterXSS.whiteList
// allow ol specify start number // allow ol specify start number
whiteList['ol'] = ['start'] whiteList.ol = ['start']
// allow li specify value number // allow li specify value number
whiteList['li'] = ['value'] whiteList.li = ['value']
// allow style tag // allow style tag
whiteList['style'] = [] whiteList.style = []
// allow kbd tag // allow kbd tag
whiteList['kbd'] = [] whiteList.kbd = []
// allow ifram tag with some safe attributes // allow ifram tag with some safe attributes
whiteList['iframe'] = ['allowfullscreen', 'name', 'referrerpolicy', 'src', 'width', 'height'] whiteList.iframe = ['allowfullscreen', 'name', 'referrerpolicy', 'src', 'width', 'height']
// allow summary tag // allow summary tag
whiteList['summary'] = [] whiteList.summary = []
// allow ruby tag // allow ruby tag
whiteList['ruby'] = [] whiteList.ruby = []
// allow rp tag for ruby // allow rp tag for ruby
whiteList['rp'] = [] whiteList.rp = []
// allow rt tag for ruby // allow rt tag for ruby
whiteList['rt'] = [] whiteList.rt = []
// allow figure tag // allow figure tag
whiteList['figure'] = [] whiteList.figure = []
// allow figcaption tag // allow figcaption tag
whiteList['figcaption'] = [] whiteList.figcaption = []
var filterXSSOptions = { var filterXSSOptions = {
allowCommentTag: true, allowCommentTag: true,

View File

@ -50,7 +50,7 @@ describe('realtime#update note is dirty timer', function () {
callback(null, note) callback(null, note)
}) })
realtime.notes['note1'] = { realtime.notes.note1 = {
server: { server: {
isDirty: false isDirty: false
}, },
@ -64,7 +64,7 @@ describe('realtime#update note is dirty timer', function () {
socks: [] socks: []
} }
realtime.notes['note2'] = note2 realtime.notes.note2 = note2
clock.tick(1000) clock.tick(1000)
setTimeout(() => { setTimeout(() => {
@ -75,7 +75,7 @@ describe('realtime#update note is dirty timer', function () {
it('should not do anything when note missing', function (done) { it('should not do anything when note missing', function (done) {
sinon.stub(realtime, 'updateNote').callsFake(function (note, callback) { sinon.stub(realtime, 'updateNote').callsFake(function (note, callback) {
delete realtime.notes['note'] delete realtime.notes.note
callback(null, note) callback(null, note)
}) })
@ -85,7 +85,7 @@ describe('realtime#update note is dirty timer', function () {
}, },
socks: [makeMockSocket()] socks: [makeMockSocket()]
} }
realtime.notes['note'] = note realtime.notes.note = note
clock.tick(1000) clock.tick(1000)
@ -115,7 +115,7 @@ describe('realtime#update note is dirty timer', function () {
}, },
socks: [makeMockSocket(), undefined, makeMockSocket()] socks: [makeMockSocket(), undefined, makeMockSocket()]
} }
realtime.notes['note'] = note realtime.notes.note = note
clock.tick(1000) clock.tick(1000)

View File

@ -1,7 +1,7 @@
'use strict' 'use strict'
function stripTags (s) { function stripTags (s) {
return s.replace(RegExp(`</?[^<>]*>`, 'gi'), '') return s.replace(RegExp('</?[^<>]*>', 'gi'), '')
} }
exports.stripTags = stripTags exports.stripTags = stripTags