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'
}, passportGeneralCallback)
if (process.env['https_proxy']) {
const httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy'])
if (process.env.https_proxy) {
const httpsProxyAgent = new HttpsProxyAgent(process.env.https_proxy)
gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent)
}

View File

@ -131,7 +131,7 @@ function historyPost (req, res) {
if (req.isAuthenticated()) {
var noteId = req.params.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) }
try {
var history = JSON.parse(req.body.history)
@ -147,7 +147,7 @@ function historyPost (req, res) {
return response.errorBadRequest(req, res)
}
} 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) {
if (err) return response.errorInternalError(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({
where: {
ownerId: userid
@ -199,7 +199,7 @@ async function getMyNoteList(userid, callback) {
return callback(null, null)
}
try {
let myNoteList = []
const myNoteList = []
for (let i = 0; i < myNotes.length; i++) {
const note = myNotes[i]
myNoteList[i] = {
@ -215,13 +215,13 @@ async function getMyNoteList(userid, callback) {
logger.info('Parse myNoteList success: ' + userid)
}
return callback(null, myNoteList)
} catch (err){
logger.error('Parse myNoteList failed')
return callback(err, null)
} catch (err) {
logger.error('Parse myNoteList failed')
return callback(err, null)
}
}
function listMyNotes(req, res) {
function listMyNotes (req, res) {
if (req.isAuthenticated()) {
getMyNoteList(req.user.id, (err, myNoteList) => {
if (err) return errorInternalError(req, res)
@ -239,5 +239,3 @@ exports.showNote = showNote
exports.showPublishNote = showPublishNote
exports.noteActions = noteActions
exports.listMyNotes = listMyNotes

View File

@ -464,7 +464,7 @@ export function finishView (view) {
const { lat, lon } = data[0]
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)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
@ -975,7 +975,7 @@ export function deduplicatedHeaderId (view) {
if (window.linkifyHeaderStyle === 'gfm') {
// consistent with GitHub, GitLab, Pandoc & co.
// 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
const headerIds = new Set()
for (let j = 0; j < allHeaders.length; j++) {
@ -1133,7 +1133,7 @@ md.use(markdownitContainer, 'spoiler', {
if (summary) {
return `<details><summary>${md.renderInline(summary)}</summary>\n`
} else {
return `<details>\n`
return '<details>\n'
}
} else {
// closing tag

View File

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

View File

@ -16,4 +16,4 @@ export const availableThemes = [
{ 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) {
this.statusIndicators.find(`.status-spellcheck li[value="${lang}"]`).addClass('active')
} 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
this.statusIndicators.find(`.status-spellcheck li`).click(function () {
this.statusIndicators.find('.status-spellcheck li').click(function () {
const lang = $(this).attr('value')
if (lang === 'disabled') {

View File

@ -23,11 +23,11 @@ export const supportLanguages = [
value: 'de',
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: {
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',
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: {
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',
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: {
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 => {
param = param.trim()
if (param[0] === '#') {
params['id'] = param.slice(1)
params.id = param.slice(1)
} else if (param[0] === '.') {
if (params['class']) params['class'] = []
params['class'] = params['class'].concat(param.slice(1))
if (params.class) params.class = []
params.class = params.class.concat(param.slice(1))
} else {
const offset = param.indexOf('=')
const id = param.substring(0, offset).trim().toLowerCase()
@ -21,8 +21,8 @@ export function parseFenceCodeParams (lang) {
val = val.substring(1, val.length - 1)
}
if (id === 'class') {
if (params['class']) params['class'] = []
params['class'] = params['class'].concat(val)
if (params.class) params.class = []
params.class = params.class.concat(val)
} else {
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
var whiteList = filterXSS.whiteList
// allow ol specify start number
whiteList['ol'] = ['start']
whiteList.ol = ['start']
// allow li specify value number
whiteList['li'] = ['value']
whiteList.li = ['value']
// allow style tag
whiteList['style'] = []
whiteList.style = []
// allow kbd tag
whiteList['kbd'] = []
whiteList.kbd = []
// 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
whiteList['summary'] = []
whiteList.summary = []
// allow ruby tag
whiteList['ruby'] = []
whiteList.ruby = []
// allow rp tag for ruby
whiteList['rp'] = []
whiteList.rp = []
// allow rt tag for ruby
whiteList['rt'] = []
whiteList.rt = []
// allow figure tag
whiteList['figure'] = []
whiteList.figure = []
// allow figcaption tag
whiteList['figcaption'] = []
whiteList.figcaption = []
var filterXSSOptions = {
allowCommentTag: true,

View File

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

View File

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