refactor: renderers + auth providers + fixes
This commit is contained in:
30
server/extensions/authentication/dropbox.js
Normal file
30
server/extensions/authentication/dropbox.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Dropbox Account
|
||||
// ------------------------------------
|
||||
|
||||
const DropboxStrategy = require('passport-dropbox-oauth2').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'dropbox',
|
||||
title: 'Dropbox',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret'],
|
||||
init (passport, conf) {
|
||||
passport.use('dropbox',
|
||||
new DropboxStrategy({
|
||||
apiVersion: '2',
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
31
server/extensions/authentication/oauth2.js
Normal file
31
server/extensions/authentication/oauth2.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// OAuth2 Account
|
||||
// ------------------------------------
|
||||
|
||||
const OAuth2Strategy = require('passport-oauth2').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'oauth2',
|
||||
title: 'OAuth2',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'authorizationURL', 'tokenURL'],
|
||||
init (passport, conf) {
|
||||
passport.use('oauth2',
|
||||
new OAuth2Strategy({
|
||||
authorizationURL: conf.authorizationURL,
|
||||
tokenURL: conf.tokenURL,
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
86
server/extensions/renderer/common/mathjax.js
Normal file
86
server/extensions/renderer/common/mathjax.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const mathjax = require('mathjax-node')
|
||||
const _ = require('lodash')
|
||||
|
||||
// ------------------------------------
|
||||
// Mathjax
|
||||
// ------------------------------------
|
||||
|
||||
/* global wiki */
|
||||
|
||||
const mathRegex = [
|
||||
{
|
||||
format: 'TeX',
|
||||
regex: /\\\[([\s\S]*?)\\\]/g
|
||||
},
|
||||
{
|
||||
format: 'inline-TeX',
|
||||
regex: /\\\((.*?)\\\)/g
|
||||
},
|
||||
{
|
||||
format: 'MathML',
|
||||
regex: /<math([\s\S]*?)<\/math>/g
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
key: 'common/mathjax',
|
||||
title: 'Mathjax',
|
||||
dependsOn: [],
|
||||
props: [],
|
||||
init (conf) {
|
||||
mathjax.config({
|
||||
MathJax: {
|
||||
jax: ['input/TeX', 'input/MathML', 'output/SVG'],
|
||||
extensions: ['tex2jax.js', 'mml2jax.js'],
|
||||
TeX: {
|
||||
extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
|
||||
},
|
||||
SVG: {
|
||||
scale: 120,
|
||||
font: 'STIX-Web'
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async render (content) {
|
||||
let matchStack = []
|
||||
let replaceStack = []
|
||||
let currentMatch
|
||||
let mathjaxState = {}
|
||||
|
||||
_.forEach(mathRegex, mode => {
|
||||
do {
|
||||
currentMatch = mode.regex.exec(content)
|
||||
if (currentMatch) {
|
||||
matchStack.push(currentMatch[0])
|
||||
replaceStack.push(
|
||||
new Promise((resolve, reject) => {
|
||||
mathjax.typeset({
|
||||
math: (mode.format === 'MathML') ? currentMatch[0] : currentMatch[1],
|
||||
format: mode.format,
|
||||
speakText: false,
|
||||
svg: true,
|
||||
state: mathjaxState,
|
||||
timeout: 30 * 1000
|
||||
}, result => {
|
||||
if (!result.errors) {
|
||||
resolve(result.svg)
|
||||
} else {
|
||||
resolve(currentMatch[0])
|
||||
wiki.logger.warn(result.errors.join(', '))
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
} while (currentMatch)
|
||||
})
|
||||
|
||||
return (matchStack.length > 0) ? Promise.all(replaceStack).then(results => {
|
||||
_.forEach(matchStack, (repMatch, idx) => {
|
||||
content = content.replace(repMatch, results[idx])
|
||||
})
|
||||
return content
|
||||
}) : Promise.resolve(content)
|
||||
}
|
||||
}
|
15
server/extensions/renderer/markdown/abbreviations.js
Normal file
15
server/extensions/renderer/markdown/abbreviations.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const mdAbbr = require('markdown-it-abbr')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Abbreviations
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'markdown/abbreviations',
|
||||
title: 'Abbreviations',
|
||||
dependsOn: [],
|
||||
props: [],
|
||||
init (md, conf) {
|
||||
md.use(mdAbbr)
|
||||
}
|
||||
}
|
15
server/extensions/renderer/markdown/emoji.js
Normal file
15
server/extensions/renderer/markdown/emoji.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const mdEmoji = require('markdown-it-emoji')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Emoji
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'markdown/emoji',
|
||||
title: 'Emoji',
|
||||
dependsOn: [],
|
||||
props: [],
|
||||
init (md, conf) {
|
||||
md.use(mdEmoji)
|
||||
}
|
||||
}
|
18
server/extensions/renderer/markdown/expand-tabs.js
Normal file
18
server/extensions/renderer/markdown/expand-tabs.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const mdExpandTabs = require('markdown-it-expand-tabs')
|
||||
const _ = require('lodash')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Expand Tabs
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'markdown/expand-tabs',
|
||||
title: 'Expand Tabs',
|
||||
dependsOn: [],
|
||||
props: ['tabWidth'],
|
||||
init (md, conf) {
|
||||
md.use(mdExpandTabs, {
|
||||
tabWidth: _.toInteger(conf.tabWidth || 4)
|
||||
})
|
||||
}
|
||||
}
|
15
server/extensions/renderer/markdown/footnotes.js
Normal file
15
server/extensions/renderer/markdown/footnotes.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const mdFootnote = require('markdown-it-footnote')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Footnotes
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'markdown/footnotes',
|
||||
title: 'Footnotes',
|
||||
dependsOn: [],
|
||||
props: [],
|
||||
init (md, conf) {
|
||||
md.use(mdFootnote)
|
||||
}
|
||||
}
|
15
server/extensions/renderer/markdown/mathjax.js
Normal file
15
server/extensions/renderer/markdown/mathjax.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const mdMathjax = require('markdown-it-mathjax')()
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Mathjax Preprocessor
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'markdown/mathjax',
|
||||
title: 'Mathjax Preprocessor',
|
||||
dependsOn: [],
|
||||
props: [],
|
||||
init (md, conf) {
|
||||
md.use(mdMathjax)
|
||||
}
|
||||
}
|
15
server/extensions/renderer/markdown/tasks-lists.js
Normal file
15
server/extensions/renderer/markdown/tasks-lists.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const mdTaskLists = require('markdown-it-task-lists')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Task Lists
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'markdown/task-lists',
|
||||
title: 'Task Lists',
|
||||
dependsOn: [],
|
||||
props: [],
|
||||
init (md, conf) {
|
||||
md.use(mdTaskLists)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user