mirror of https://github.com/Requarks/wiki.git
NGPixel
6 years ago
41 changed files with 475 additions and 770 deletions
Split View
Diff Options
-
11assets/browserconfig.xml
-
2assets/manifest.json
-
2client/js/components/editor.component.js
-
3client/js/components/login.vue
-
52client/js/components/navigator.vue
-
36client/js/components/setup.component.js
-
15client/js/helpers/common.js
-
25client/js/helpers/form.js
-
59client/js/helpers/index.js
-
2client/js/helpers/lodash.js
-
26client/js/helpers/pages.js
-
2client/js/modules/localization.js
-
2client/js/pages/admin-edit-user.component.js
-
2client/js/pages/admin-profile.component.js
-
2client/js/pages/admin-settings.component.js
-
2client/js/pages/admin-theme.component.js
-
2client/js/pages/content-view.component.js
-
2client/js/pages/source-view.component.js
-
3client/js/store/modules/anchor.js
-
57client/scss/components/navigator.scss
-
12client/svg/icons.svg
-
2package.json
-
307server/controllers/admin.js
-
5server/controllers/auth.js
-
0server/controllers/common.js
-
162server/controllers/uploads.js
-
116server/controllers/ws.js
-
30server/extensions/authentication/dropbox.js
-
31server/extensions/authentication/oauth2.js
-
86server/extensions/renderer/common/mathjax.js
-
15server/extensions/renderer/markdown/abbreviations.js
-
15server/extensions/renderer/markdown/emoji.js
-
18server/extensions/renderer/markdown/expand-tabs.js
-
15server/extensions/renderer/markdown/footnotes.js
-
15server/extensions/renderer/markdown/mathjax.js
-
15server/extensions/renderer/markdown/tasks-lists.js
-
23server/master.js
-
34server/setup.js
-
4server/views/master.pug
-
22server/views/setup.pug
-
11yarn.lock
@ -1,2 +1,11 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<browserconfig><msapplication><tile><square70x70logo src="/favicons/ms-icon-70x70.png"/><square150x150logo src="/favicons/ms-icon-150x150.png"/><square310x310logo src="/favicons/ms-icon-310x310.png"/><TileColor>#ffffff</TileColor></tile></msapplication></browserconfig> |
|||
<browserconfig> |
|||
<msapplication> |
|||
<tile> |
|||
<square70x70logo src="/favicons/ms-icon-70x70.png"/> |
|||
<square150x150logo src="/favicons/ms-icon-150x150.png"/> |
|||
<square310x310logo src="/favicons/ms-icon-310x310.png"/> |
|||
<TileColor>#ffffff</TileColor> |
|||
</tile> |
|||
</msapplication> |
|||
</browserconfig> |
@ -1,15 +0,0 @@ |
|||
'use strict' |
|||
|
|||
import filesize from 'filesize.js' |
|||
import toUpper from 'lodash/toUpper' |
|||
|
|||
module.exports = { |
|||
/** |
|||
* Convert bytes to humanized form |
|||
* @param {number} rawSize Size in bytes |
|||
* @returns {string} Humanized file size |
|||
*/ |
|||
filesize(rawSize) { |
|||
return toUpper(filesize(rawSize)) |
|||
} |
|||
} |
@ -1,25 +0,0 @@ |
|||
'use strict' |
|||
|
|||
module.exports = { |
|||
/** |
|||
* Set Input Selection |
|||
* @param {DOMElement} input The input element |
|||
* @param {number} startPos The starting position |
|||
* @param {nunber} endPos The ending position |
|||
*/ |
|||
setInputSelection: (input, startPos, endPos) => { |
|||
input.focus() |
|||
if (typeof input.selectionStart !== 'undefined') { |
|||
input.selectionStart = startPos |
|||
input.selectionEnd = endPos |
|||
} else if (document.selection && document.selection.createRange) { |
|||
// IE branch
|
|||
input.select() |
|||
var range = document.selection.createRange() |
|||
range.collapse(true) |
|||
range.moveEnd('character', endPos) |
|||
range.moveStart('character', startPos) |
|||
range.select() |
|||
} |
|||
} |
|||
} |
@ -1,26 +0,0 @@ |
|||
'use strict' |
|||
|
|||
import deburr from 'lodash/deburr' |
|||
import filter from 'lodash/filter' |
|||
import isEmpty from 'lodash/isEmpty' |
|||
import join from 'lodash/join' |
|||
import kebabCase from 'lodash/kebabCase' |
|||
import map from 'lodash/map' |
|||
import split from 'lodash/split' |
|||
import trim from 'lodash/trim' |
|||
|
|||
module.exports = { |
|||
/** |
|||
* Convert raw path to safe path |
|||
* @param {string} rawPath Raw path |
|||
* @returns {string} Safe path |
|||
*/ |
|||
makeSafePath: (rawPath) => { |
|||
let rawParts = split(trim(rawPath), '/') |
|||
rawParts = map(rawParts, (r) => { |
|||
return kebabCase(deburr(trim(r))) |
|||
}) |
|||
|
|||
return join(filter(rawParts, (r) => { return !isEmpty(r) }), '/') |
|||
} |
|||
} |
@ -1,307 +0,0 @@ |
|||
'use strict' |
|||
|
|||
/* global wiki */ |
|||
|
|||
var express = require('express') |
|||
var router = express.Router() |
|||
const Promise = require('bluebird') |
|||
const validator = require('validator') |
|||
const _ = require('lodash') |
|||
const axios = require('axios') |
|||
const path = require('path') |
|||
const fs = Promise.promisifyAll(require('fs-extra')) |
|||
const os = require('os') |
|||
const filesize = require('filesize.js') |
|||
|
|||
/** |
|||
* Admin |
|||
*/ |
|||
router.get('/', (req, res) => { |
|||
res.redirect('/admin/profile') |
|||
}) |
|||
|
|||
router.get('/profile', (req, res) => { |
|||
if (res.locals.isGuest) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
res.render('pages/admin/profile', { adminTab: 'profile' }) |
|||
}) |
|||
|
|||
router.post('/profile', (req, res) => { |
|||
if (res.locals.isGuest) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
return wiki.db.User.findById(req.user.id).then((usr) => { |
|||
usr.name = _.trim(req.body.name) |
|||
if (usr.provider === 'local' && req.body.password !== '********') { |
|||
let nPwd = _.trim(req.body.password) |
|||
if (nPwd.length < 6) { |
|||
return Promise.reject(new Error('New Password too short!')) |
|||
} else { |
|||
return wiki.db.User.hashPassword(nPwd).then((pwd) => { |
|||
usr.password = pwd |
|||
return usr.save() |
|||
}) |
|||
} |
|||
} else { |
|||
return usr.save() |
|||
} |
|||
}).then(() => { |
|||
return res.json({ msg: 'OK' }) |
|||
}).catch((err) => { |
|||
res.status(400).json({ msg: err.message }) |
|||
}) |
|||
}) |
|||
|
|||
router.get('/stats', (req, res) => { |
|||
if (res.locals.isGuest) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
Promise.all([ |
|||
wiki.db.Entry.count(), |
|||
wiki.db.UplFile.count(), |
|||
wiki.db.User.count() |
|||
]).spread((totalEntries, totalUploads, totalUsers) => { |
|||
return res.render('pages/admin/stats', { |
|||
totalEntries, totalUploads, totalUsers, adminTab: 'stats' |
|||
}) || true |
|||
}).catch((err) => { |
|||
throw err |
|||
}) |
|||
}) |
|||
|
|||
router.get('/users', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
wiki.db.User.find({}) |
|||
.select('-password -rights') |
|||
.sort('name email') |
|||
.exec().then((usrs) => { |
|||
res.render('pages/admin/users', { adminTab: 'users', usrs }) |
|||
}) |
|||
}) |
|||
|
|||
router.get('/users/:id', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
if (!validator.isMongoId(req.params.id)) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
wiki.db.User.findById(req.params.id) |
|||
.select('-password -providerId') |
|||
.exec().then((usr) => { |
|||
let usrOpts = { |
|||
canChangeEmail: (usr.email !== 'guest' && usr.provider === 'local' && usr.email !== req.app.locals.appconfig.admin), |
|||
canChangeName: (usr.email !== 'guest'), |
|||
canChangePassword: (usr.email !== 'guest' && usr.provider === 'local'), |
|||
canChangeRole: (usr.email !== 'guest' && !(usr.provider === 'local' && usr.email === req.app.locals.appconfig.admin)), |
|||
canBeDeleted: (usr.email !== 'guest' && !(usr.provider === 'local' && usr.email === req.app.locals.appconfig.admin)) |
|||
} |
|||
|
|||
res.render('pages/admin/users-edit', { adminTab: 'users', usr, usrOpts }) |
|||
}).catch(err => { // eslint-disable-line handle-callback-err
|
|||
return res.status(404).end() || true |
|||
}) |
|||
}) |
|||
|
|||
/** |
|||
* Create / Authorize a new user |
|||
*/ |
|||
router.post('/users/create', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.status(401).json({ msg: 'Unauthorized' }) |
|||
} |
|||
|
|||
let nUsr = { |
|||
email: _.toLower(_.trim(req.body.email)), |
|||
provider: _.trim(req.body.provider), |
|||
password: req.body.password, |
|||
name: _.trim(req.body.name) |
|||
} |
|||
|
|||
if (!validator.isEmail(nUsr.email)) { |
|||
return res.status(400).json({ msg: 'Invalid email address' }) |
|||
} else if (!validator.isIn(nUsr.provider, ['local', 'google', 'windowslive', 'facebook', 'github', 'slack'])) { |
|||
return res.status(400).json({ msg: 'Invalid provider' }) |
|||
} else if (nUsr.provider === 'local' && !validator.isLength(nUsr.password, { min: 6 })) { |
|||
return res.status(400).json({ msg: 'Password too short or missing' }) |
|||
} else if (nUsr.provider === 'local' && !validator.isLength(nUsr.name, { min: 2 })) { |
|||
return res.status(400).json({ msg: 'Name is missing' }) |
|||
} |
|||
|
|||
wiki.db.User.findOne({ email: nUsr.email, provider: nUsr.provider }).then(exUsr => { |
|||
if (exUsr) { |
|||
return res.status(400).json({ msg: 'User already exists!' }) || true |
|||
} |
|||
|
|||
let pwdGen = (nUsr.provider === 'local') ? wiki.db.User.hashPassword(nUsr.password) : Promise.resolve(true) |
|||
return pwdGen.then(nPwd => { |
|||
if (nUsr.provider !== 'local') { |
|||
nUsr.password = '' |
|||
nUsr.name = '-- pending --' |
|||
} else { |
|||
nUsr.password = nPwd |
|||
} |
|||
|
|||
nUsr.rights = [{ |
|||
role: 'read', |
|||
path: '/', |
|||
exact: false, |
|||
deny: false |
|||
}] |
|||
|
|||
return wiki.db.User.create(nUsr).then(() => { |
|||
return res.json({ ok: true }) |
|||
}) |
|||
}).catch(err => { |
|||
wiki.logger.warn(err) |
|||
return res.status(500).json({ msg: err }) |
|||
}) |
|||
}).catch(err => { |
|||
wiki.logger.warn(err) |
|||
return res.status(500).json({ msg: err }) |
|||
}) |
|||
}) |
|||
|
|||
router.post('/users/:id', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.status(401).json({ msg: wiki.lang.t('errors:unauthorized') }) |
|||
} |
|||
|
|||
if (!validator.isMongoId(req.params.id)) { |
|||
return res.status(400).json({ msg: wiki.lang.t('errors:invaliduserid') }) |
|||
} |
|||
|
|||
return wiki.db.User.findById(req.params.id).then((usr) => { |
|||
usr.name = _.trim(req.body.name) |
|||
usr.rights = JSON.parse(req.body.rights) |
|||
if (usr.provider === 'local' && req.body.password !== '********') { |
|||
let nPwd = _.trim(req.body.password) |
|||
if (nPwd.length < 6) { |
|||
return Promise.reject(new Error(wiki.lang.t('errors:newpasswordtooshort'))) |
|||
} else { |
|||
return wiki.db.User.hashPassword(nPwd).then((pwd) => { |
|||
usr.password = pwd |
|||
return usr.save() |
|||
}) |
|||
} |
|||
} else { |
|||
return usr.save() |
|||
} |
|||
}).then((usr) => { |
|||
// Update guest rights for future requests
|
|||
if (usr.provider === 'local' && usr.email === 'guest') { |
|||
wiki.rights.guest = usr |
|||
} |
|||
return usr |
|||
}).then(() => { |
|||
return res.json({ msg: 'OK' }) |
|||
}).catch((err) => { |
|||
res.status(400).json({ msg: err.message }) |
|||
}) |
|||
}) |
|||
|
|||
/** |
|||
* Delete / Deauthorize a user |
|||
*/ |
|||
router.delete('/users/:id', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.status(401).json({ msg: wiki.lang.t('errors:unauthorized') }) |
|||
} |
|||
|
|||
if (!validator.isMongoId(req.params.id)) { |
|||
return res.status(400).json({ msg: wiki.lang.t('errors:invaliduserid') }) |
|||
} |
|||
|
|||
return wiki.db.User.findByIdAndRemove(req.params.id).then(() => { |
|||
return res.json({ ok: true }) |
|||
}).catch((err) => { |
|||
res.status(500).json({ ok: false, msg: err.message }) |
|||
}) |
|||
}) |
|||
|
|||
router.get('/settings', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
res.render('pages/admin/settings', { adminTab: 'settings' }) |
|||
}) |
|||
|
|||
router.get('/system', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
let hostInfo = { |
|||
cpus: os.cpus(), |
|||
hostname: os.hostname(), |
|||
nodeversion: process.version, |
|||
os: `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`, |
|||
totalmem: filesize(os.totalmem()), |
|||
cwd: process.cwd() |
|||
} |
|||
|
|||
fs.readJsonAsync(path.join(wiki.ROOTPATH, 'package.json')).then(packageObj => { |
|||
axios.get('https://api.github.com/repos/Requarks/wiki/releases/latest').then(resp => { |
|||
let sysversion = { |
|||
current: 'v' + packageObj.version, |
|||
latest: resp.data.tag_name, |
|||
latestPublishedAt: resp.data.published_at |
|||
} |
|||
|
|||
res.render('pages/admin/system', { adminTab: 'system', hostInfo, sysversion }) |
|||
}).catch(err => { |
|||
wiki.logger.warn(err) |
|||
res.render('pages/admin/system', { adminTab: 'system', hostInfo, sysversion: { current: 'v' + packageObj.version } }) |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
router.post('/system/install', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
// let sysLib = require(path.join(ROOTPATH, 'libs/system.js'))
|
|||
// sysLib.install('v1.0-beta.7')
|
|||
res.status(400).send('Sorry, Upgrade/Re-Install via the web UI is not yet ready. You must use the npm upgrade method in the meantime.').end() |
|||
}) |
|||
|
|||
router.get('/theme', (req, res) => { |
|||
if (!res.locals.rights.manage) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
res.render('pages/admin/theme', { adminTab: 'theme' }) |
|||
}) |
|||
|
|||
router.post('/theme', (req, res) => { |
|||
if (res.locals.isGuest) { |
|||
return res.render('error-forbidden') |
|||
} |
|||
|
|||
if (!validator.isIn(req.body.primary, wiki.data.colors)) { |
|||
return res.status(406).json({ msg: 'Primary color is invalid.' }) |
|||
} else if (!validator.isIn(req.body.alt, wiki.data.colors)) { |
|||
return res.status(406).json({ msg: 'Alternate color is invalid.' }) |
|||
} else if (!validator.isIn(req.body.footer, wiki.data.colors)) { |
|||
return res.status(406).json({ msg: 'Footer color is invalid.' }) |
|||
} |
|||
|
|||
wiki.config.theme.primary = req.body.primary |
|||
wiki.config.theme.alt = req.body.alt |
|||
wiki.config.theme.footer = req.body.footer |
|||
wiki.config.theme.code.dark = req.body.codedark === 'true' |
|||
wiki.config.theme.code.colorize = req.body.codecolorize === 'true' |
|||
|
|||
return res.json({ msg: 'OK' }) |
|||
}) |
|||
|
|||
module.exports = router |
@ -1,162 +0,0 @@ |
|||
'use strict' |
|||
|
|||
/* global wiki */ |
|||
|
|||
const express = require('express') |
|||
const router = express.Router() |
|||
|
|||
const readChunk = require('read-chunk') |
|||
const fileType = require('file-type') |
|||
const Promise = require('bluebird') |
|||
const fs = Promise.promisifyAll(require('fs-extra')) |
|||
const path = require('path') |
|||
const _ = require('lodash') |
|||
|
|||
const validPathRe = new RegExp('^([a-z0-9/-' + wiki.data.regex.cjk + wiki.data.regex.arabic + ']+\\.[a-z0-9]+)$') |
|||
const validPathThumbsRe = new RegExp('^([a-z0-9]+\\.png)$') |
|||
|
|||
// ==========================================
|
|||
// SERVE UPLOADS FILES
|
|||
// ==========================================
|
|||
|
|||
router.get('/t/*', (req, res, next) => { |
|||
let fileName = req.params[0] |
|||
if (!validPathThumbsRe.test(fileName)) { |
|||
return res.sendStatus(404).end() |
|||
} |
|||
|
|||
// todo: Authentication-based access
|
|||
|
|||
res.sendFile(fileName, { |
|||
root: wiki.disk.getThumbsPath(), |
|||
dotfiles: 'deny' |
|||
}, (err) => { |
|||
if (err) { |
|||
res.status(err.status).end() |
|||
} |
|||
}) |
|||
}) |
|||
|
|||
// router.post('/img', wiki.disk.uploadImgHandler, (req, res, next) => {
|
|||
// let destFolder = _.chain(req.body.folder).trim().toLower().value()
|
|||
|
|||
// wiki.upl.validateUploadsFolder(destFolder).then((destFolderPath) => {
|
|||
// if (!destFolderPath) {
|
|||
// res.json({ ok: false, msg: wiki.lang.t('errors:invalidfolder') })
|
|||
// return true
|
|||
// }
|
|||
|
|||
// Promise.map(req.files, (f) => {
|
|||
// let destFilename = ''
|
|||
// let destFilePath = ''
|
|||
|
|||
// return wiki.disk.validateUploadsFilename(f.originalname, destFolder, true).then((fname) => {
|
|||
// destFilename = fname
|
|||
// destFilePath = path.resolve(destFolderPath, destFilename)
|
|||
|
|||
// return readChunk(f.path, 0, 262)
|
|||
// }).then((buf) => {
|
|||
// // -> Check MIME type by magic number
|
|||
|
|||
// let mimeInfo = fileType(buf)
|
|||
// if (!_.includes(['image/png', 'image/jpeg', 'image/gif', 'image/webp'], mimeInfo.mime)) {
|
|||
// return Promise.reject(new Error(wiki.lang.t('errors:invalidfiletype')))
|
|||
// }
|
|||
// return true
|
|||
// }).then(() => {
|
|||
// // -> Move file to final destination
|
|||
|
|||
// return fs.moveAsync(f.path, destFilePath, { clobber: false })
|
|||
// }).then(() => {
|
|||
// return {
|
|||
// ok: true,
|
|||
// filename: destFilename,
|
|||
// filesize: f.size
|
|||
// }
|
|||
// }).reflect()
|
|||
// }, {concurrency: 3}).then((results) => {
|
|||
// let uplResults = _.map(results, (r) => {
|
|||
// if (r.isFulfilled()) {
|
|||
// return r.value()
|
|||
// } else {
|
|||
// return {
|
|||
// ok: false,
|
|||
// msg: r.reason().message
|
|||
// }
|
|||
// }
|
|||
// })
|
|||
// res.json({ ok: true, results: uplResults })
|
|||
// return true
|
|||
// }).catch((err) => {
|
|||
// res.json({ ok: false, msg: err.message })
|
|||
// return true
|
|||
// })
|
|||
// })
|
|||
// })
|
|||
|
|||
// router.post('/file', wiki.disk.uploadFileHandler, (req, res, next) => {
|
|||
// let destFolder = _.chain(req.body.folder).trim().toLower().value()
|
|||
|
|||
// wiki.upl.validateUploadsFolder(destFolder).then((destFolderPath) => {
|
|||
// if (!destFolderPath) {
|
|||
// res.json({ ok: false, msg: wiki.lang.t('errors:invalidfolder') })
|
|||
// return true
|
|||
// }
|
|||
|
|||
// Promise.map(req.files, (f) => {
|
|||
// let destFilename = ''
|
|||
// let destFilePath = ''
|
|||
|
|||
// return wiki.disk.validateUploadsFilename(f.originalname, destFolder, false).then((fname) => {
|
|||
// destFilename = fname
|
|||
// destFilePath = path.resolve(destFolderPath, destFilename)
|
|||
|
|||
// // -> Move file to final destination
|
|||
|
|||
// return fs.moveAsync(f.path, destFilePath, { clobber: false })
|
|||
// }).then(() => {
|
|||
// return {
|
|||
// ok: true,
|
|||
// filename: destFilename,
|
|||
// filesize: f.size
|
|||
// }
|
|||
// }).reflect()
|
|||
// }, {concurrency: 3}).then((results) => {
|
|||
// let uplResults = _.map(results, (r) => {
|
|||
// if (r.isFulfilled()) {
|
|||
// return r.value()
|
|||
// } else {
|
|||
// return {
|
|||
// ok: false,
|
|||
// msg: r.reason().message
|
|||
// }
|
|||
// }
|
|||
// })
|
|||
// res.json({ ok: true, results: uplResults })
|
|||
// return true
|
|||
// }).catch((err) => {
|
|||
// res.json({ ok: false, msg: err.message })
|
|||
// return true
|
|||
// })
|
|||
// })
|
|||
// })
|
|||
|
|||
// router.get('/*', (req, res, next) => {
|
|||
// let fileName = req.params[0]
|
|||
// if (!validPathRe.test(fileName)) {
|
|||
// return res.sendStatus(404).end()
|
|||
// }
|
|||
|
|||
// // todo: Authentication-based access
|
|||
|
|||
// res.sendFile(fileName, {
|
|||
// root: wiki.git.getRepoPath() + '/uploads/',
|
|||
// dotfiles: 'deny'
|
|||
// }, (err) => {
|
|||
// if (err) {
|
|||
// res.status(err.status).end()
|
|||
// }
|
|||
// })
|
|||
// })
|
|||
|
|||
module.exports = router |
@ -1,116 +0,0 @@ |
|||
'use strict' |
|||
|
|||
/* global appconfig, entries, rights, search, upl */ |
|||
/* eslint-disable standard/no-callback-literal */ |
|||
|
|||
const _ = require('lodash') |
|||
|
|||
module.exports = (socket) => { |
|||
// Check if Guest
|
|||
if (!socket.request.user.logged_in) { |
|||
socket.request.user = _.assign(rights.guest, socket.request.user) |
|||
} |
|||
|
|||
// -----------------------------------------
|
|||
// SEARCH
|
|||
// -----------------------------------------
|
|||
|
|||
if (appconfig.public || socket.request.user.logged_in) { |
|||
socket.on('search', (data, cb) => { |
|||
cb = cb || _.noop |
|||
search.find(data.terms).then((results) => { |
|||
return cb(results) || true |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
// -----------------------------------------
|
|||
// TREE VIEW (LIST ALL PAGES)
|
|||
// -----------------------------------------
|
|||
|
|||
if (appconfig.public || socket.request.user.logged_in) { |
|||
socket.on('treeFetch', (data, cb) => { |
|||
cb = cb || _.noop |
|||
entries.getFromTree(data.basePath, socket.request.user).then((f) => { |
|||
return cb(f) || true |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
// -----------------------------------------
|
|||
// UPLOADS
|
|||
// -----------------------------------------
|
|||
|
|||
if (socket.request.user.logged_in) { |
|||
socket.on('uploadsGetFolders', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.getUploadsFolders().then((f) => { |
|||
return cb(f) || true |
|||
}) |
|||
}) |
|||
|
|||
socket.on('uploadsCreateFolder', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.createUploadsFolder(data.foldername).then((f) => { |
|||
return cb(f) || true |
|||
}) |
|||
}) |
|||
|
|||
socket.on('uploadsGetImages', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.getUploadsFiles('image', data.folder).then((f) => { |
|||
return cb(f) || true |
|||
}) |
|||
}) |
|||
|
|||
socket.on('uploadsGetFiles', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.getUploadsFiles('binary', data.folder).then((f) => { |
|||
return cb(f) || true |
|||
}) |
|||
}) |
|||
|
|||
socket.on('uploadsDeleteFile', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.deleteUploadsFile(data.uid).then((f) => { |
|||
return cb(f) || true |
|||
}) |
|||
}) |
|||
|
|||
socket.on('uploadsFetchFileFromURL', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.downloadFromUrl(data.folder, data.fetchUrl).then((f) => { |
|||
return cb({ ok: true }) || true |
|||
}).catch((err) => { |
|||
return cb({ |
|||
ok: false, |
|||
msg: err.message |
|||
}) || true |
|||
}) |
|||
}) |
|||
|
|||
socket.on('uploadsRenameFile', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.moveUploadsFile(data.uid, data.folder, data.filename).then((f) => { |
|||
return cb({ ok: true }) || true |
|||
}).catch((err) => { |
|||
return cb({ |
|||
ok: false, |
|||
msg: err.message |
|||
}) || true |
|||
}) |
|||
}) |
|||
|
|||
socket.on('uploadsMoveFile', (data, cb) => { |
|||
cb = cb || _.noop |
|||
upl.moveUploadsFile(data.uid, data.folder).then((f) => { |
|||
return cb({ ok: true }) || true |
|||
}).catch((err) => { |
|||
return cb({ |
|||
ok: false, |
|||
msg: err.message |
|||
}) || true |
|||
}) |
|||
}) |
|||
} |
|||
} |
@ -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 |
|||
}) |
|||
}) |
|||
) |
|||
} |
|||
} |
@ -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 |
|||
}) |
|||
}) |
|||
) |
|||
} |
|||
} |
@ -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) |
|||
} |
|||
} |
@ -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) |
|||
} |
|||
} |
@ -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) |
|||
} |
|||
} |
@ -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) |
|||
}) |
|||
} |
|||
} |
@ -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) |
|||
} |
|||
} |
@ -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) |
|||
} |
|||
} |
@ -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) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save