diff --git a/.eslintrc.json b/.eslintrc.json index b587f2d3..72ce2be8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,24 +11,10 @@ "document": false, "navigator": false, "window": false, - "app": true, "appconfig": true, "appdata": true, - "db": true, - "entries": true, - "git": true, - "lang": true, - "lcdata": true, - "mark": true, - "rights": true, - "search": true, - "upl": true, - "winston": true, - "ws": true, - "Mongoose": true, "ROOTPATH": true, "SERVERPATH": true, - "IS_DEBUG": true, - "PROCNAME": true + "IS_DEBUG": true } } diff --git a/package.json b/package.json index 1db21387..9cf6d7cb 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,6 @@ "through2": "^2.0.3", "validator": "^7.0.0", "validator-as-promised": "^1.0.2", - "vue-template-es2015-compiler": "^1.5.2", "winston": "^2.3.1", "yargs": "^8.0.1" }, @@ -135,7 +134,7 @@ "eslint-plugin-node": "latest", "eslint-plugin-promise": "latest", "eslint-plugin-standard": "latest", - "fuse-box": "beta", + "fuse-box": "^2.0.0", "jest": "latest", "jquery": "^3.2.1", "jquery-contextmenu": "^2.4.5", @@ -147,38 +146,13 @@ "nodemon": "latest", "pug-lint": "latest", "snyk": "latest", - "standard": "latest", "twemoji-awesome": "^1.0.6", "typescript": "^2.3.2", "uglify-js": "latest", "vee-validate": "^2.0.0-rc.3", "vue": "^2.3.3", - "vue-template-compiler": "^2.3.3" - }, - "standard": { - "globals": [ - "app", - "appconfig", - "appdata", - "db", - "entries", - "git", - "mark", - "lang", - "lcdata", - "rights", - "search", - "upl", - "winston", - "ws", - "Mongoose", - "ROOTPATH", - "IS_DEBUG", - "PROCNAME", - "describe", - "it", - "expect" - ] + "vue-template-compiler": "^2.3.3", + "vue-template-es2015-compiler": "^1.5.2" }, "jest": { "collectCoverage": false, diff --git a/server/agent.js b/server/agent.js index f583db8a..2639e59b 100644 --- a/server/agent.js +++ b/server/agent.js @@ -26,7 +26,7 @@ global.winston = require('./libs/logger')(IS_DEBUG, 'AGENT') // Load global modules // ---------------------------------------- -winston.info('Background Agent is initializing...') +global.winston.info('Background Agent is initializing...') global.db = require('./libs/db').init() global.upl = require('./libs/uploads-agent').init() @@ -53,7 +53,7 @@ const entryHelper = require('./helpers/entry') // Localization Engine // ---------------------------------------- -lang +global.lang .use(i18nextBackend) .use(i18nextMw.LanguageDetector) .init({ @@ -77,8 +77,8 @@ let job let jobIsBusy = false let jobUplWatchStarted = false -db.onReady.then(() => { - return db.Entry.remove({}) +global.db.onReady.then(() => { + return global.db.Entry.remove({}) }).then(() => { job = new Cron({ cronTime: '0 */5 * * * *', @@ -86,10 +86,10 @@ db.onReady.then(() => { // Make sure we don't start two concurrent jobs if (jobIsBusy) { - winston.warn('Previous job has not completed gracefully or is still running! Skipping for now. (This is not normal, you should investigate)') + global.winston.warn('Previous job has not completed gracefully or is still running! Skipping for now. (This is not normal, you should investigate)') return } - winston.info('Running all jobs...') + global.winston.info('Running all jobs...') jobIsBusy = true // Prepare async job collector @@ -107,7 +107,7 @@ db.onReady.then(() => { // -> Sync with Git remote //* **************************************** - jobs.push(git.resync().then(() => { + jobs.push(global.git.resync().then(() => { // -> Stream all documents let cacheJobs = [] @@ -140,7 +140,7 @@ db.onReady.then(() => { // -> Update cache and search index if (fileStatus !== 'active') { - return entries.updateCache(entryPath).then(entry => { + return global.entries.updateCache(entryPath).then(entry => { process.send({ action: 'searchAdd', content: entry @@ -187,18 +187,18 @@ db.onReady.then(() => { // ---------------------------------------- Promise.all(jobs).then(() => { - winston.info('All jobs completed successfully! Going to sleep for now.') + global.winston.info('All jobs completed successfully! Going to sleep for now.') if (!jobUplWatchStarted) { jobUplWatchStarted = true - upl.initialScan().then(() => { + global.upl.initialScan().then(() => { job.start() }) } return true }).catch((err) => { - winston.error('One or more jobs have failed: ', err) + global.winston.error('One or more jobs have failed: ', err) }).finally(() => { jobIsBusy = false }) @@ -214,7 +214,7 @@ db.onReady.then(() => { // ---------------------------------------- process.on('disconnect', () => { - winston.warn('Lost connection to main server. Exiting...') + global.winston.warn('Lost connection to main server. Exiting...') job.stop() process.exit() }) diff --git a/server/controllers/admin.js b/server/controllers/admin.js index dd8975b6..4514257d 100644 --- a/server/controllers/admin.js +++ b/server/controllers/admin.js @@ -1,5 +1,7 @@ 'use strict' +/* global db, lang, rights, winston */ + var express = require('express') var router = express.Router() const Promise = require('bluebird') diff --git a/server/controllers/auth.js b/server/controllers/auth.js index b1a07dcb..b513470e 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -1,5 +1,7 @@ 'use strict' +/* global db, lang */ + const Promise = require('bluebird') const express = require('express') const router = express.Router() diff --git a/server/controllers/pages.js b/server/controllers/pages.js index a633af57..44fcb82e 100644 --- a/server/controllers/pages.js +++ b/server/controllers/pages.js @@ -1,5 +1,7 @@ 'use strict' +/* global entries, lang, winston */ + const express = require('express') const router = express.Router() const _ = require('lodash') diff --git a/server/controllers/uploads.js b/server/controllers/uploads.js index 437f8ec3..ddcc92d2 100644 --- a/server/controllers/uploads.js +++ b/server/controllers/uploads.js @@ -1,5 +1,7 @@ 'use strict' +/* global git, lang, lcdata, upl */ + const express = require('express') const router = express.Router() diff --git a/server/controllers/ws.js b/server/controllers/ws.js index 1abcd7b4..95065ee0 100644 --- a/server/controllers/ws.js +++ b/server/controllers/ws.js @@ -1,6 +1,6 @@ 'use strict' -/* global appconfig, rights */ +/* global appconfig, entries, rights, search, upl */ /* eslint-disable standard/no-callback-literal */ const _ = require('lodash') diff --git a/server/index.js b/server/index.js index d9950c20..1fc92a99 100644 --- a/server/index.js +++ b/server/index.js @@ -25,7 +25,7 @@ global.appdata = appconf.data // ---------------------------------------- global.winston = require('./libs/logger')(IS_DEBUG, 'SERVER') -winston.info('Wiki.js is initializing...') +global.winston.info('Wiki.js is initializing...') // ---------------------------------------- // Load global modules @@ -53,8 +53,7 @@ const favicon = require('serve-favicon') const flash = require('connect-flash') const fork = require('child_process').fork const http = require('http') -const i18nextBackend = require('i18next-node-fs-backend') -const i18nextMw = require('i18next-express-middleware') +const i18nBackend = require('i18next-node-fs-backend') const passport = require('passport') const passportSocketIo = require('passport.socketio') const session = require('express-session') @@ -68,7 +67,8 @@ var ctrl = autoload(path.join(SERVERPATH, '/controllers')) // Define Express App // ---------------------------------------- -global.app = express() +const app = express() +global.app = app app.use(compression()) // ---------------------------------------- @@ -90,10 +90,10 @@ app.use(express.static(path.join(ROOTPATH, 'assets'))) require('./libs/auth')(passport) global.rights = require('./libs/rights') -rights.init() +global.rights.init() let sessionStore = new SessionMongoStore({ - mongooseConnection: db.connection, + mongooseConnection: global.db.connection, touchAfter: 15 }) @@ -119,16 +119,15 @@ app.use(mw.seo) // Localization Engine // ---------------------------------------- -lang - .use(i18nextBackend) - .use(i18nextMw.LanguageDetector) +global.lang + .use(i18nBackend) .init({ load: 'languageOnly', ns: ['common', 'admin', 'auth', 'errors', 'git'], defaultNS: 'common', saveMissing: false, - supportedLngs: ['en', 'fr'], - preload: ['en', 'fr'], + preload: [appconfig.lang], + lng: appconfig.lang, fallbackLng: 'en', backend: { loadPath: path.join(SERVERPATH, 'locales/{{lng}}/{{ns}}.json') @@ -139,7 +138,6 @@ lang // View Engine Setup // ---------------------------------------- -app.use(i18nextMw.handle(lang)) app.set('views', path.join(SERVERPATH, 'views')) app.set('view engine', 'pug') @@ -151,7 +149,9 @@ app.use(bodyParser.urlencoded({ extended: false, limit: '1mb' })) // ---------------------------------------- app.locals._ = require('lodash') +app.locals.t = global.lang.t.bind(global.lang) app.locals.moment = require('moment') +app.locals.moment.locale(appconfig.lang) app.locals.appconfig = appconfig app.use(mw.flash) @@ -187,7 +187,7 @@ app.use(function (err, req, res, next) { // Start HTTP server // ---------------------------------------- -winston.info('Starting HTTP/WS server on port ' + appconfig.port + '...') +global.winston.info('Starting HTTP/WS server on port ' + appconfig.port + '...') app.set('port', appconfig.port) var server = http.createServer(app) @@ -202,10 +202,10 @@ server.on('error', (error) => { // handle specific listen errors with friendly messages switch (error.code) { case 'EACCES': - winston.error('Listening on port ' + appconfig.port + ' requires elevated privileges!') + global.winston.error('Listening on port ' + appconfig.port + ' requires elevated privileges!') return process.exit(1) case 'EADDRINUSE': - winston.error('Port ' + appconfig.port + ' is already in use!') + global.winston.error('Port ' + appconfig.port + ' is already in use!') return process.exit(1) default: throw error @@ -213,7 +213,7 @@ server.on('error', (error) => { }) server.on('listening', () => { - winston.info('HTTP/WS server started successfully! [RUNNING]') + global.winston.info('HTTP/WS server started successfully! [RUNNING]') }) // ---------------------------------------- @@ -248,7 +248,7 @@ bgAgent.on('message', m => { switch (m.action) { case 'searchAdd': - search.add(m.content) + global.search.add(m.content) break } }) diff --git a/server/libs/auth.js b/server/libs/auth.js index 24a17ecc..3629a8f5 100644 --- a/server/libs/auth.js +++ b/server/libs/auth.js @@ -1,6 +1,6 @@ 'use strict' -/* global appconfig, appdata, db, winston */ +/* global appconfig, appdata, db, lang, winston */ const fs = require('fs') diff --git a/server/libs/db.js b/server/libs/db.js index 7aef4c20..3afc617d 100644 --- a/server/libs/db.js +++ b/server/libs/db.js @@ -21,7 +21,6 @@ module.exports = { */ init () { let self = this - global.Mongoose = modb let dbModelsPath = path.join(SERVERPATH, 'models') diff --git a/server/libs/entries.js b/server/libs/entries.js index 2a5b9e37..020390ab 100644 --- a/server/libs/entries.js +++ b/server/libs/entries.js @@ -1,5 +1,7 @@ 'use strict' +/* global db, git, lang, mark, rights, search, winston */ + const Promise = require('bluebird') const path = require('path') const fs = Promise.promisifyAll(require('fs-extra')) diff --git a/server/libs/git.js b/server/libs/git.js index 422f99fc..22946cdb 100644 --- a/server/libs/git.js +++ b/server/libs/git.js @@ -1,5 +1,7 @@ 'use strict' +/* global lang, winston */ + const Git = require('git-wrapper2-promise') const Promise = require('bluebird') const path = require('path') diff --git a/server/libs/local.js b/server/libs/local.js index 9507419c..381041ae 100644 --- a/server/libs/local.js +++ b/server/libs/local.js @@ -1,5 +1,7 @@ 'use strict' +/* global lang, winston */ + const path = require('path') const Promise = require('bluebird') const fs = Promise.promisifyAll(require('fs-extra')) diff --git a/server/libs/search.js b/server/libs/search.js index 0738e574..724886c1 100644 --- a/server/libs/search.js +++ b/server/libs/search.js @@ -1,5 +1,7 @@ 'use strict' +/* global winston */ + const Promise = require('bluebird') const _ = require('lodash') const searchIndex = require('./search-index') diff --git a/server/libs/system.js b/server/libs/system.js index c905161d..7542b2a6 100644 --- a/server/libs/system.js +++ b/server/libs/system.js @@ -1,5 +1,7 @@ 'use strict' +/* global winston */ + const Promise = require('bluebird') const crypto = require('crypto') const fs = Promise.promisifyAll(require('fs-extra')) diff --git a/server/libs/uploads-agent.js b/server/libs/uploads-agent.js index 426ca964..d8e9fe3e 100644 --- a/server/libs/uploads-agent.js +++ b/server/libs/uploads-agent.js @@ -1,5 +1,7 @@ 'use strict' +/* global db, git, lang, upl */ + const path = require('path') const Promise = require('bluebird') const fs = Promise.promisifyAll(require('fs-extra')) diff --git a/server/libs/uploads.js b/server/libs/uploads.js index 931d774b..2bee6322 100644 --- a/server/libs/uploads.js +++ b/server/libs/uploads.js @@ -1,5 +1,7 @@ 'use strict' +/* global db, lang, lcdata, upl, winston */ + const path = require('path') const Promise = require('bluebird') const fs = Promise.promisifyAll(require('fs-extra')) diff --git a/server/middlewares/auth.js b/server/middlewares/auth.js index 9518bfd6..cd20b7a0 100644 --- a/server/middlewares/auth.js +++ b/server/middlewares/auth.js @@ -2,8 +2,6 @@ /* global appdata, rights */ -const moment = require('moment-timezone') - /** * Authentication middleware * @@ -34,12 +32,6 @@ module.exports = (req, res, next) => { return res.render('error-forbidden') } - // Set i18n locale - - req.i18n.changeLanguage(req.user.lang) - res.locals.userMoment = moment - res.locals.userMoment.locale(req.user.lang) - // Expose user data res.locals.user = req.user diff --git a/server/models/bruteforce.js b/server/models/bruteforce.js index 998cac7a..76981fd7 100644 --- a/server/models/bruteforce.js +++ b/server/models/bruteforce.js @@ -1,5 +1,7 @@ 'use strict' +const Mongoose = require('mongoose') + /** * BruteForce schema * diff --git a/server/models/entry.js b/server/models/entry.js index 6740f722..746d6d28 100644 --- a/server/models/entry.js +++ b/server/models/entry.js @@ -1,5 +1,7 @@ 'use strict' +const Mongoose = require('mongoose') + /** * Entry schema * diff --git a/server/models/upl-file.js b/server/models/upl-file.js index be0866ca..a48602bb 100644 --- a/server/models/upl-file.js +++ b/server/models/upl-file.js @@ -1,5 +1,7 @@ 'use strict' +const Mongoose = require('mongoose') + /** * Upload File schema * diff --git a/server/models/upl-folder.js b/server/models/upl-folder.js index 3b103bc8..80028b6f 100644 --- a/server/models/upl-folder.js +++ b/server/models/upl-folder.js @@ -1,5 +1,7 @@ 'use strict' +const Mongoose = require('mongoose') + /** * Upload Folder schema * diff --git a/server/models/user.js b/server/models/user.js index 16fdba2b..1c32f694 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -1,5 +1,8 @@ 'use strict' +/* global db, lang */ + +const Mongoose = require('mongoose') const Promise = require('bluebird') const bcrypt = require('bcryptjs-then') const _ = require('lodash') diff --git a/yarn.lock b/yarn.lock index b06d71b7..7fd13ce2 100644 Binary files a/yarn.lock and b/yarn.lock differ