feat: sideloading + locales nav menu
This commit is contained in:
@@ -34,6 +34,7 @@ module.exports = {
|
||||
await this.initTelemetry()
|
||||
WIKI.cache = require('./cache').init()
|
||||
WIKI.scheduler = require('./scheduler').init()
|
||||
WIKI.sideloader = require('./sideloader').init()
|
||||
WIKI.events = new EventEmitter()
|
||||
} catch (err) {
|
||||
WIKI.logger.error(err)
|
||||
|
@@ -87,7 +87,6 @@ class Job {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
jobs: [],
|
||||
init() {
|
||||
@@ -95,6 +94,11 @@ module.exports = {
|
||||
},
|
||||
start() {
|
||||
_.forOwn(WIKI.data.jobs, (queueParams, queueName) => {
|
||||
if (WIKI.config.offline && queueParams.offlineSkip) {
|
||||
WIKI.logger.warn(`Skipping job ${queueName} because offline mode is enabled. [SKIPPED]`)
|
||||
return
|
||||
}
|
||||
|
||||
const schedule = (configHelper.isValidDurationString(queueParams.schedule)) ? queueParams.schedule : _.get(WIKI.config, queueParams.schedule)
|
||||
this.registerJob({
|
||||
name: _.kebabCase(queueName),
|
||||
|
76
server/core/sideloader.js
Normal file
76
server/core/sideloader.js
Normal file
@@ -0,0 +1,76 @@
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
async init () {
|
||||
if (!WIKI.config.offline) {
|
||||
return
|
||||
}
|
||||
|
||||
const sideloadExists = await fs.pathExists(path.join(WIKI.ROOTPATH, 'data/sideload'))
|
||||
|
||||
if (!sideloadExists) {
|
||||
return
|
||||
}
|
||||
|
||||
WIKI.logger.info('Sideload directory detected. Looking for packages...')
|
||||
|
||||
try {
|
||||
await this.importLocales()
|
||||
} catch (err) {
|
||||
WIKI.logger.warn(err)
|
||||
}
|
||||
},
|
||||
async importLocales() {
|
||||
const localeExists = await fs.pathExists(path.join(WIKI.ROOTPATH, 'data/sideload/locales.json'))
|
||||
if (localeExists) {
|
||||
WIKI.logger.info('Found locales master file. Importing locale packages...')
|
||||
let importedLocales = 0
|
||||
|
||||
const locales = await fs.readJson(path.join(WIKI.ROOTPATH, 'data/sideload/locales.json'))
|
||||
if (locales && _.has(locales, 'data.localization.locales')) {
|
||||
for (const locale of locales.data.localization.locales) {
|
||||
try {
|
||||
const localeData = await fs.readJson(path.join(WIKI.ROOTPATH, `data/sideload/${locale.code}.json`))
|
||||
if (localeData) {
|
||||
WIKI.logger.info(`Importing ${locale.name} locale package...`)
|
||||
|
||||
let lcObj = {}
|
||||
_.forOwn(localeData, (value, key) => {
|
||||
if (_.includes(key, '::')) { return }
|
||||
if (_.isEmpty(value)) { value = key }
|
||||
_.set(lcObj, key.replace(':', '.'), value)
|
||||
})
|
||||
|
||||
const localeExists = await WIKI.models.locales.query().select('code').where('code', locale.code).first()
|
||||
if (localeExists) {
|
||||
await WIKI.models.locales.query().update({
|
||||
code: locale.code,
|
||||
strings: lcObj,
|
||||
isRTL: locale.isRTL,
|
||||
name: locale.name,
|
||||
nativeName: locale.nativeName
|
||||
}).where('code', locale.code)
|
||||
} else {
|
||||
await WIKI.models.locales.query().insert({
|
||||
code: locale.code,
|
||||
strings: lcObj,
|
||||
isRTL: locale.isRTL,
|
||||
name: locale.name,
|
||||
nativeName: locale.nativeName
|
||||
})
|
||||
}
|
||||
importedLocales++
|
||||
}
|
||||
} catch (err) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
WIKI.logger.info(`Imported ${importedLocales} locale packages: [COMPLETED]`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,7 +28,7 @@ module.exports = {
|
||||
})
|
||||
WIKI.telemetry = this
|
||||
|
||||
if (_.get(WIKI.config, 'telemetry.isEnabled', false) === true) {
|
||||
if (_.get(WIKI.config, 'telemetry.isEnabled', false) === true && WIKI.config.offline !== true) {
|
||||
this.enabled = true
|
||||
this.sendOSInfo()
|
||||
}
|
||||
|
Reference in New Issue
Block a user