refactor: global namespace + admin pages UI
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
const _ = require('lodash')
|
||||
const passport = require('passport')
|
||||
@@ -17,11 +17,11 @@ module.exports = {
|
||||
})
|
||||
|
||||
passport.deserializeUser(function (id, done) {
|
||||
wiki.db.User.findById(id).then((user) => {
|
||||
WIKI.db.User.findById(id).then((user) => {
|
||||
if (user) {
|
||||
done(null, user)
|
||||
} else {
|
||||
done(new Error(wiki.lang.t('auth:errors:usernotfound')), null)
|
||||
done(new Error(WIKI.lang.t('auth:errors:usernotfound')), null)
|
||||
}
|
||||
return true
|
||||
}).catch((err) => {
|
||||
@@ -31,49 +31,49 @@ module.exports = {
|
||||
|
||||
// Load authentication strategies
|
||||
|
||||
_.forOwn(_.omitBy(wiki.config.auth.strategies, s => s.enabled === false), (strategyConfig, strategyKey) => {
|
||||
strategyConfig.callbackURL = `${wiki.config.site.host}${wiki.config.site.path}login/${strategyKey}/callback`
|
||||
_.forOwn(_.omitBy(WIKI.config.auth.strategies, s => s.enabled === false), (strategyConfig, strategyKey) => {
|
||||
strategyConfig.callbackURL = `${WIKI.config.site.host}${WIKI.config.site.path}login/${strategyKey}/callback`
|
||||
let strategy = require(`../modules/authentication/${strategyKey}`)
|
||||
try {
|
||||
strategy.init(passport, strategyConfig)
|
||||
} catch (err) {
|
||||
wiki.logger.error(`Authentication Provider ${strategyKey}: [ FAILED ]`)
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error(`Authentication Provider ${strategyKey}: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
fs.readFile(path.join(wiki.ROOTPATH, `assets/svg/auth-icon-${strategyKey}.svg`), 'utf8').then(iconData => {
|
||||
fs.readFile(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${strategyKey}.svg`), 'utf8').then(iconData => {
|
||||
strategy.icon = iconData
|
||||
}).catch(err => {
|
||||
if (err.code === 'ENOENT') {
|
||||
strategy.icon = '[missing icon]'
|
||||
} else {
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
})
|
||||
this.strategies[strategy.key] = strategy
|
||||
wiki.logger.info(`Authentication Provider ${strategyKey}: [ OK ]`)
|
||||
WIKI.logger.info(`Authentication Provider ${strategyKey}: [ OK ]`)
|
||||
})
|
||||
|
||||
// Create Guest account for first-time
|
||||
|
||||
wiki.db.User.findOne({
|
||||
WIKI.db.User.findOne({
|
||||
where: {
|
||||
provider: 'local',
|
||||
email: 'guest@example.com'
|
||||
}
|
||||
}).then((c) => {
|
||||
if (c < 1) {
|
||||
return wiki.db.User.create({
|
||||
return WIKI.db.User.create({
|
||||
provider: 'local',
|
||||
email: 'guest@example.com',
|
||||
name: 'Guest',
|
||||
password: '',
|
||||
role: 'guest'
|
||||
}).then(() => {
|
||||
wiki.logger.info('[AUTH] Guest account created successfully!')
|
||||
WIKI.logger.info('[AUTH] Guest account created successfully!')
|
||||
return true
|
||||
}).catch((err) => {
|
||||
wiki.logger.error('[AUTH] An error occured while creating guest account:')
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error('[AUTH] An error occured while creating guest account:')
|
||||
WIKI.logger.error(err)
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -81,22 +81,22 @@ module.exports = {
|
||||
|
||||
// .then(() => {
|
||||
// if (process.env.WIKI_JS_HEROKU) {
|
||||
// return wiki.db.User.findOne({ provider: 'local', email: process.env.WIKI_ADMIN_EMAIL }).then((c) => {
|
||||
// return WIKI.db.User.findOne({ provider: 'local', email: process.env.WIKI_ADMIN_EMAIL }).then((c) => {
|
||||
// if (c < 1) {
|
||||
// // Create root admin account (HEROKU ONLY)
|
||||
|
||||
// return wiki.db.User.create({
|
||||
// return WIKI.db.User.create({
|
||||
// provider: 'local',
|
||||
// email: process.env.WIKI_ADMIN_EMAIL,
|
||||
// name: 'Administrator',
|
||||
// password: '$2a$04$MAHRw785Xe/Jd5kcKzr3D.VRZDeomFZu2lius4gGpZZ9cJw7B7Mna', // admin123 (default)
|
||||
// role: 'admin'
|
||||
// }).then(() => {
|
||||
// wiki.logger.info('[AUTH] Root admin account created successfully!')
|
||||
// WIKI.logger.info('[AUTH] Root admin account created successfully!')
|
||||
// return true
|
||||
// }).catch((err) => {
|
||||
// wiki.logger.error('[AUTH] An error occured while creating root admin account:')
|
||||
// wiki.logger.error(err)
|
||||
// WIKI.logger.error('[AUTH] An error occured while creating root admin account:')
|
||||
// WIKI.logger.error(err)
|
||||
// return err
|
||||
// })
|
||||
// } else { return true }
|
||||
|
@@ -4,7 +4,7 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
const yaml = require('js-yaml')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
@@ -12,9 +12,9 @@ module.exports = {
|
||||
*/
|
||||
init() {
|
||||
let confPaths = {
|
||||
config: path.join(wiki.ROOTPATH, 'config.yml'),
|
||||
data: path.join(wiki.SERVERPATH, 'app/data.yml'),
|
||||
dataRegex: path.join(wiki.SERVERPATH, 'app/regex.js')
|
||||
config: path.join(WIKI.ROOTPATH, 'config.yml'),
|
||||
data: path.join(WIKI.SERVERPATH, 'app/data.yml'),
|
||||
dataRegex: path.join(WIKI.SERVERPATH, 'app/regex.js')
|
||||
}
|
||||
|
||||
let appconfig = {}
|
||||
@@ -43,9 +43,9 @@ module.exports = {
|
||||
|
||||
appconfig.public = (appconfig.public === true || _.toLower(appconfig.public) === 'true')
|
||||
|
||||
wiki.config = appconfig
|
||||
wiki.data = appdata
|
||||
wiki.version = require(path.join(wiki.ROOTPATH, 'package.json')).version
|
||||
WIKI.config = appconfig
|
||||
WIKI.data = appdata
|
||||
WIKI.version = require(path.join(WIKI.ROOTPATH, 'package.json')).version
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -56,10 +56,10 @@ module.exports = {
|
||||
*/
|
||||
async loadFromDb(subsets) {
|
||||
if (!_.isArray(subsets) || subsets.length === 0) {
|
||||
subsets = wiki.data.configNamespaces
|
||||
subsets = WIKI.data.configNamespaces
|
||||
}
|
||||
|
||||
let results = await wiki.db.Setting.findAll({
|
||||
let results = await WIKI.db.Setting.findAll({
|
||||
attributes: ['key', 'config'],
|
||||
where: {
|
||||
key: {
|
||||
@@ -69,11 +69,11 @@ module.exports = {
|
||||
})
|
||||
if (_.isArray(results) && results.length === subsets.length) {
|
||||
results.forEach(result => {
|
||||
wiki.config[result.key] = result.config
|
||||
WIKI.config[result.key] = result.config
|
||||
})
|
||||
return true
|
||||
} else {
|
||||
wiki.logger.warn('DB Configuration is empty or incomplete.')
|
||||
WIKI.logger.warn('DB Configuration is empty or incomplete.')
|
||||
return false
|
||||
}
|
||||
},
|
||||
@@ -85,18 +85,18 @@ module.exports = {
|
||||
*/
|
||||
async saveToDb(subsets) {
|
||||
if (!_.isArray(subsets) || subsets.length === 0) {
|
||||
subsets = wiki.data.configNamespaces
|
||||
subsets = WIKI.data.configNamespaces
|
||||
}
|
||||
|
||||
try {
|
||||
for (let set of subsets) {
|
||||
await wiki.db.Setting.upsert({
|
||||
await WIKI.db.Setting.upsert({
|
||||
key: set,
|
||||
config: _.get(wiki.config, set, {})
|
||||
config: _.get(WIKI.config, set, {})
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
wiki.logger.error(`Failed to save configuration to DB: ${err.message}`)
|
||||
WIKI.logger.error(`Failed to save configuration to DB: ${err.message}`)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ const path = require('path')
|
||||
const Promise = require('bluebird')
|
||||
const Sequelize = require('sequelize')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
const operatorsAliases = {
|
||||
$eq: Sequelize.Op.eq,
|
||||
@@ -57,30 +57,30 @@ module.exports = {
|
||||
*/
|
||||
init() {
|
||||
let self = this
|
||||
let dbModelsPath = path.join(wiki.SERVERPATH, 'models')
|
||||
let dbModelsPath = path.join(WIKI.SERVERPATH, 'models')
|
||||
|
||||
// Define Sequelize instance
|
||||
|
||||
this.inst = new this.Sequelize(wiki.config.db.db, wiki.config.db.user, wiki.config.db.pass, {
|
||||
host: wiki.config.db.host,
|
||||
port: wiki.config.db.port,
|
||||
this.inst = new this.Sequelize(WIKI.config.db.db, WIKI.config.db.user, WIKI.config.db.pass, {
|
||||
host: WIKI.config.db.host,
|
||||
port: WIKI.config.db.port,
|
||||
dialect: 'postgres',
|
||||
pool: {
|
||||
max: 10,
|
||||
min: 0,
|
||||
idle: 10000
|
||||
},
|
||||
logging: log => { wiki.logger.log('debug', log) },
|
||||
logging: log => { WIKI.logger.log('debug', log) },
|
||||
operatorsAliases
|
||||
})
|
||||
|
||||
// Attempt to connect and authenticate to DB
|
||||
|
||||
this.inst.authenticate().then(() => {
|
||||
wiki.logger.info('Database (PostgreSQL) connection: [ OK ]')
|
||||
WIKI.logger.info('Database (PostgreSQL) connection: [ OK ]')
|
||||
}).catch(err => {
|
||||
wiki.logger.error('Failed to connect to PostgreSQL instance.')
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error('Failed to connect to PostgreSQL instance.')
|
||||
WIKI.logger.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
@@ -107,16 +107,16 @@ module.exports = {
|
||||
syncSchemas() {
|
||||
return self.inst.sync({
|
||||
force: false,
|
||||
logging: log => { wiki.logger.log('debug', log) }
|
||||
logging: log => { WIKI.logger.log('debug', log) }
|
||||
})
|
||||
},
|
||||
// -> Set Connection App Name
|
||||
setAppName() {
|
||||
return self.inst.query(`set application_name = 'Wiki.js'`, { raw: true })
|
||||
return self.inst.query(`set application_name = 'WIKI.js'`, { raw: true })
|
||||
}
|
||||
}
|
||||
|
||||
let initTasksQueue = (wiki.IS_MASTER) ? [
|
||||
let initTasksQueue = (WIKI.IS_MASTER) ? [
|
||||
initTasks.syncSchemas,
|
||||
initTasks.setAppName
|
||||
] : [
|
||||
|
@@ -1,41 +0,0 @@
|
||||
const _ = require('lodash')
|
||||
const fs = require('fs')
|
||||
const gqlTools = require('graphql-tools')
|
||||
const path = require('path')
|
||||
|
||||
/* global wiki */
|
||||
|
||||
const typeDefs = fs.readFileSync(path.join(wiki.SERVERPATH, 'schemas/types.graphql'), 'utf8')
|
||||
|
||||
const DateScalar = require('../schemas/scalar-date')
|
||||
const AuthenticationResolvers = require('../schemas/resolvers-authentication')
|
||||
const CommentResolvers = require('../schemas/resolvers-comment')
|
||||
const DocumentResolvers = require('../schemas/resolvers-document')
|
||||
const FileResolvers = require('../schemas/resolvers-file')
|
||||
const FolderResolvers = require('../schemas/resolvers-folder')
|
||||
const GroupResolvers = require('../schemas/resolvers-group')
|
||||
const SettingResolvers = require('../schemas/resolvers-setting')
|
||||
const TagResolvers = require('../schemas/resolvers-tag')
|
||||
const TranslationResolvers = require('../schemas/resolvers-translation')
|
||||
const UserResolvers = require('../schemas/resolvers-user')
|
||||
|
||||
const resolvers = _.merge(
|
||||
AuthenticationResolvers,
|
||||
CommentResolvers,
|
||||
DocumentResolvers,
|
||||
FileResolvers,
|
||||
FolderResolvers,
|
||||
GroupResolvers,
|
||||
SettingResolvers,
|
||||
TagResolvers,
|
||||
TranslationResolvers,
|
||||
UserResolvers,
|
||||
DateScalar
|
||||
)
|
||||
|
||||
const Schema = gqlTools.makeExecutableSchema({
|
||||
typeDefs,
|
||||
resolvers
|
||||
})
|
||||
|
||||
module.exports = Schema
|
@@ -2,19 +2,19 @@ const _ = require('lodash')
|
||||
const cluster = require('cluster')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
numWorkers: 1,
|
||||
workers: [],
|
||||
init() {
|
||||
if (cluster.isMaster) {
|
||||
wiki.logger.info('=======================================')
|
||||
wiki.logger.info('= Wiki.js =============================')
|
||||
wiki.logger.info('=======================================')
|
||||
WIKI.logger.info('=======================================')
|
||||
WIKI.logger.info('= WIKI.js =============================')
|
||||
WIKI.logger.info('=======================================')
|
||||
|
||||
wiki.redis = require('./redis').init()
|
||||
wiki.queue = require('./queue').init()
|
||||
WIKI.redis = require('./redis').init()
|
||||
WIKI.queue = require('./queue').init()
|
||||
|
||||
this.setWorkerLimit()
|
||||
this.bootMaster()
|
||||
@@ -27,9 +27,9 @@ module.exports = {
|
||||
*/
|
||||
preBootMaster() {
|
||||
return Promise.mapSeries([
|
||||
() => { return wiki.db.onReady },
|
||||
() => { return wiki.configSvc.loadFromDb() },
|
||||
() => { return wiki.queue.clean() }
|
||||
() => { return WIKI.db.onReady },
|
||||
() => { return WIKI.configSvc.loadFromDb() },
|
||||
() => { return WIKI.queue.clean() }
|
||||
], fn => { return fn() })
|
||||
},
|
||||
/**
|
||||
@@ -37,15 +37,15 @@ module.exports = {
|
||||
*/
|
||||
bootMaster() {
|
||||
this.preBootMaster().then(sequenceResults => {
|
||||
if (_.every(sequenceResults, rs => rs === true) && wiki.config.configMode !== 'setup') {
|
||||
if (_.every(sequenceResults, rs => rs === true) && WIKI.config.configMode !== 'setup') {
|
||||
this.postBootMaster()
|
||||
} else {
|
||||
wiki.logger.info('Starting configuration manager...')
|
||||
WIKI.logger.info('Starting configuration manager...')
|
||||
require('../setup')()
|
||||
}
|
||||
return true
|
||||
}).catch(err => {
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
},
|
||||
@@ -59,13 +59,13 @@ module.exports = {
|
||||
this.spawnWorker()
|
||||
})
|
||||
|
||||
wiki.queue.uplClearTemp.add({}, {
|
||||
WIKI.queue.uplClearTemp.add({}, {
|
||||
repeat: { cron: '*/15 * * * *' }
|
||||
})
|
||||
|
||||
cluster.on('exit', (worker, code, signal) => {
|
||||
if (!global.DEV) {
|
||||
wiki.logger.info(`Background Worker #${worker.id} was terminated.`)
|
||||
WIKI.logger.info(`Background Worker #${worker.id} was terminated.`)
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -73,7 +73,7 @@ module.exports = {
|
||||
* Boot Worker Process
|
||||
*/
|
||||
bootWorker() {
|
||||
wiki.logger.info(`Background Worker #${cluster.worker.id} is initializing...`)
|
||||
WIKI.logger.info(`Background Worker #${cluster.worker.id} is initializing...`)
|
||||
require('../worker')
|
||||
},
|
||||
/**
|
||||
@@ -87,7 +87,7 @@ module.exports = {
|
||||
*/
|
||||
setWorkerLimit() {
|
||||
const numCPUs = require('os').cpus().length
|
||||
this.numWorkers = (wiki.config.workers > 0) ? wiki.config.workers : numCPUs
|
||||
this.numWorkers = (WIKI.config.workers > 0) ? WIKI.config.workers : numCPUs
|
||||
if (this.numWorkers > numCPUs) {
|
||||
this.numWorkers = numCPUs
|
||||
}
|
||||
|
@@ -6,24 +6,24 @@ const i18next = require('i18next')
|
||||
const path = require('path')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
engine: null,
|
||||
namespaces: [],
|
||||
init() {
|
||||
this.namespaces = wiki.data.localeNamespaces
|
||||
this.namespaces = WIKI.data.localeNamespaces
|
||||
this.engine = i18next
|
||||
this.engine.use(i18nBackend).init({
|
||||
load: 'languageOnly',
|
||||
ns: this.namespaces,
|
||||
defaultNS: 'common',
|
||||
saveMissing: false,
|
||||
preload: [wiki.config.site.lang],
|
||||
lng: wiki.config.site.lang,
|
||||
preload: [WIKI.config.site.lang],
|
||||
lng: WIKI.config.site.lang,
|
||||
fallbackLng: 'en',
|
||||
backend: {
|
||||
loadPath: path.join(wiki.SERVERPATH, 'locales/{{lng}}/{{ns}}.yml')
|
||||
loadPath: path.join(WIKI.SERVERPATH, 'locales/{{lng}}/{{ns}}.yml')
|
||||
}
|
||||
})
|
||||
return this
|
||||
|
@@ -3,7 +3,7 @@ const cluster = require('cluster')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
loggers: {},
|
||||
@@ -11,7 +11,7 @@ module.exports = {
|
||||
let winston = require('winston')
|
||||
|
||||
let logger = new (winston.Logger)({
|
||||
level: wiki.config.logLevel,
|
||||
level: WIKI.config.logLevel,
|
||||
transports: []
|
||||
})
|
||||
|
||||
@@ -20,10 +20,10 @@ module.exports = {
|
||||
return '[' + processName + '] ' + msg
|
||||
})
|
||||
|
||||
_.forOwn(_.omitBy(wiki.config.logging.loggers, s => s.enabled === false), (loggerConfig, loggerKey) => {
|
||||
_.forOwn(_.omitBy(WIKI.config.logging.loggers, s => s.enabled === false), (loggerConfig, loggerKey) => {
|
||||
let loggerModule = require(`../modules/logging/${loggerKey}`)
|
||||
loggerModule.init(logger, loggerConfig)
|
||||
fs.readFile(path.join(wiki.ROOTPATH, `assets/svg/auth-icon-${loggerKey}.svg`), 'utf8').then(iconData => {
|
||||
fs.readFile(path.join(WIKI.ROOTPATH, `assets/svg/auth-icon-${loggerKey}.svg`), 'utf8').then(iconData => {
|
||||
logger.icon = iconData
|
||||
}).catch(err => {
|
||||
if (err.code === 'ENOENT') {
|
||||
|
@@ -1,35 +1,35 @@
|
||||
const Bull = require('bull')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
init() {
|
||||
wiki.data.queues.forEach(queueName => {
|
||||
WIKI.data.queues.forEach(queueName => {
|
||||
this[queueName] = new Bull(queueName, {
|
||||
prefix: `q-${wiki.config.ha.nodeuid}`,
|
||||
redis: wiki.config.redis
|
||||
prefix: `q-${WIKI.config.ha.nodeuid}`,
|
||||
redis: WIKI.config.redis
|
||||
})
|
||||
})
|
||||
return this
|
||||
},
|
||||
clean() {
|
||||
return Promise.each(wiki.data.queues, queueName => {
|
||||
return Promise.each(WIKI.data.queues, queueName => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let keyStream = wiki.redis.scanStream({
|
||||
match: `q-${wiki.config.ha.nodeuid}:${queueName}:*`
|
||||
let keyStream = WIKI.redis.scanStream({
|
||||
match: `q-${WIKI.config.ha.nodeuid}:${queueName}:*`
|
||||
})
|
||||
keyStream.on('data', resultKeys => {
|
||||
if (resultKeys.length > 0) {
|
||||
wiki.redis.del(resultKeys)
|
||||
WIKI.redis.del(resultKeys)
|
||||
}
|
||||
})
|
||||
keyStream.on('end', resolve)
|
||||
})
|
||||
}).then(() => {
|
||||
wiki.logger.info('Purging old queue jobs: [ OK ]')
|
||||
WIKI.logger.info('Purging old queue jobs: [ OK ]')
|
||||
}).return(true).catch(err => {
|
||||
wiki.logger.error(err)
|
||||
WIKI.logger.error(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,22 @@
|
||||
const Redis = require('ioredis')
|
||||
const { isPlainObject } = require('lodash')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
init() {
|
||||
if (isPlainObject(wiki.config.redis)) {
|
||||
let red = new Redis(wiki.config.redis)
|
||||
if (isPlainObject(WIKI.config.redis)) {
|
||||
let red = new Redis(WIKI.config.redis)
|
||||
red.on('ready', () => {
|
||||
wiki.logger.info('Redis connection: [ OK ]')
|
||||
WIKI.logger.info('Redis connection: [ OK ]')
|
||||
})
|
||||
red.on('error', () => {
|
||||
wiki.logger.error('Failed to connect to Redis instance!')
|
||||
WIKI.logger.error('Failed to connect to Redis instance!')
|
||||
process.exit(1)
|
||||
})
|
||||
return red
|
||||
} else {
|
||||
wiki.logger.error('Invalid Redis configuration!')
|
||||
WIKI.logger.error('Invalid Redis configuration!')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
@@ -2,18 +2,18 @@ const _ = require('lodash')
|
||||
const cfgHelper = require('../helpers/config')
|
||||
const Promise = require('bluebird')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Upgrade from Wiki.js 1.x - MongoDB database
|
||||
* Upgrade from WIKI.js 1.x - MongoDB database
|
||||
*
|
||||
* @param {Object} opts Options object
|
||||
*/
|
||||
async upgradeFromMongo (opts) {
|
||||
wiki.telemetry.sendEvent('setup', 'upgradeFromMongo')
|
||||
WIKI.telemetry.sendEvent('setup', 'upgradeFromMongo')
|
||||
|
||||
wiki.logger.info('Upgrading from MongoDB...')
|
||||
WIKI.logger.info('Upgrading from MongoDB...')
|
||||
|
||||
let mongo = require('mongodb').MongoClient
|
||||
let parsedMongoConStr = cfgHelper.parseConfigValue(opts.mongoCnStr)
|
||||
@@ -45,7 +45,7 @@ module.exports = {
|
||||
$not: 'guest'
|
||||
}
|
||||
}).toArray()
|
||||
await wiki.db.User.bulkCreate(_.map(userData, usr => {
|
||||
await WIKI.db.User.bulkCreate(_.map(userData, usr => {
|
||||
return {
|
||||
email: usr.email,
|
||||
name: usr.name || 'Imported User',
|
||||
|
@@ -4,27 +4,27 @@ const bugsnag = require('bugsnag')
|
||||
const path = require('path')
|
||||
const uuid = require('uuid/v4')
|
||||
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
cid: '',
|
||||
enabled: false,
|
||||
init() {
|
||||
this.cid = uuid()
|
||||
bugsnag.register(wiki.data.telemetry.BUGSNAG_ID, {
|
||||
appVersion: wiki.version,
|
||||
bugsnag.register(WIKI.data.telemetry.BUGSNAG_ID, {
|
||||
appVersion: WIKI.version,
|
||||
autoNotify: false,
|
||||
hostname: this.cid,
|
||||
notifyReleaseStages: ['production'],
|
||||
packageJSON: path.join(wiki.ROOTPATH, 'package.json'),
|
||||
projectRoot: wiki.ROOTPATH,
|
||||
packageJSON: path.join(WIKI.ROOTPATH, 'package.json'),
|
||||
projectRoot: WIKI.ROOTPATH,
|
||||
useSSL: true
|
||||
})
|
||||
bugsnag.onBeforeNotify((notification, originalError) => {
|
||||
if (!this.enabled) { return false }
|
||||
})
|
||||
|
||||
if (_.get(wiki.config, 'logging.telemetry', false) === true) {
|
||||
if (_.get(WIKI.config, 'logging.telemetry', false) === true) {
|
||||
this.enabled = true
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ module.exports = {
|
||||
if (!this.enabled) { return false }
|
||||
axios({
|
||||
method: 'post',
|
||||
url: wiki.data.telemetry.GA_REMOTE,
|
||||
url: WIKI.data.telemetry.GA_REMOTE,
|
||||
headers: {
|
||||
'Content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
params: {
|
||||
v: 1, // API version
|
||||
tid: wiki.data.telemetry.GA_ID, // Tracking ID
|
||||
tid: WIKI.data.telemetry.GA_ID, // Tracking ID
|
||||
aip: 1, // Anonymize IP
|
||||
ds: 'server', // Data source
|
||||
cid: this.cid, // Client ID
|
||||
@@ -54,10 +54,10 @@ module.exports = {
|
||||
}
|
||||
}).then(resp => {
|
||||
if (resp.status !== 200) {
|
||||
wiki.logger.warn('Unable to send analytics telemetry request.')
|
||||
WIKI.logger.warn('Unable to send analytics telemetry request.')
|
||||
}
|
||||
}, err => {
|
||||
wiki.logger.warn('Unable to send analytics telemetry request.')
|
||||
WIKI.logger.warn('Unable to send analytics telemetry request.')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user