feat: locales remote fetch+ deps update + fixes
This commit is contained in:
33
server/jobs/purge-uploads.js
Normal file
33
server/jobs/purge-uploads.js
Normal file
@@ -0,0 +1,33 @@
|
||||
require('../core/worker')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
const Promise = require('bluebird')
|
||||
const fs = Promise.promisifyAll(require('fs-extra'))
|
||||
const moment = require('moment')
|
||||
const path = require('path')
|
||||
|
||||
module.exports = async (job) => {
|
||||
WIKI.logger.info('Purging orphaned upload files...')
|
||||
|
||||
try {
|
||||
const uplTempPath = path.resolve(process.cwd(), WIKI.config.paths.data, 'temp-upload')
|
||||
const ls = await fs.readdirAsync(uplTempPath)
|
||||
const fifteenAgo = moment().subtract(15, 'minutes')
|
||||
|
||||
await Promise.map(ls, (f) => {
|
||||
return fs.statAsync(path.join(uplTempPath, f)).then((s) => { return { filename: f, stat: s } })
|
||||
}).filter((s) => { return s.stat.isFile() }).then((arrFiles) => {
|
||||
return Promise.map(arrFiles, (f) => {
|
||||
if (moment(f.stat.ctime).isBefore(fifteenAgo, 'minute')) {
|
||||
return fs.unlinkAsync(path.join(uplTempPath, f.filename))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
WIKI.logger.info('Purging orphaned upload files: [ COMPLETED ]')
|
||||
} catch (err) {
|
||||
WIKI.logger.error('Purging orphaned upload files: [ FAILED ]')
|
||||
WIKI.logger.error(err.message)
|
||||
}
|
||||
}
|
||||
69
server/jobs/sync-git.js
Normal file
69
server/jobs/sync-git.js
Normal file
@@ -0,0 +1,69 @@
|
||||
'use strict'
|
||||
|
||||
// /* global WIKI */
|
||||
|
||||
// const Promise = require('bluebird')
|
||||
// const fs = Promise.promisifyAll(require('fs-extra'))
|
||||
// const klaw = require('klaw')
|
||||
// const moment = require('moment')
|
||||
// const path = require('path')
|
||||
// const entryHelper = require('../helpers/entry')
|
||||
|
||||
module.exports = (job) => {
|
||||
return true
|
||||
// return WIKI.git.resync().then(() => {
|
||||
// // -> Stream all documents
|
||||
|
||||
// let cacheJobs = []
|
||||
// let jobCbStreamDocsResolve = null
|
||||
// let jobCbStreamDocs = new Promise((resolve, reject) => {
|
||||
// jobCbStreamDocsResolve = resolve
|
||||
// })
|
||||
|
||||
// klaw(WIKI.REPOPATH).on('data', function (item) {
|
||||
// if (path.extname(item.path) === '.md' && path.basename(item.path) !== 'README.md') {
|
||||
// let entryPath = entryHelper.parsePath(entryHelper.getEntryPathFromFullPath(item.path))
|
||||
// let cachePath = entryHelper.getCachePath(entryPath)
|
||||
|
||||
// // -> Purge outdated cache
|
||||
|
||||
// cacheJobs.push(
|
||||
// fs.statAsync(cachePath).then((st) => {
|
||||
// return moment(st.mtime).isBefore(item.stats.mtime) ? 'expired' : 'active'
|
||||
// }).catch((err) => {
|
||||
// return (err.code !== 'EEXIST') ? err : 'new'
|
||||
// }).then((fileStatus) => {
|
||||
// // -> Delete expired cache file
|
||||
|
||||
// if (fileStatus === 'expired') {
|
||||
// return fs.unlinkAsync(cachePath).return(fileStatus)
|
||||
// }
|
||||
|
||||
// return fileStatus
|
||||
// }).then((fileStatus) => {
|
||||
// // -> Update cache and search index
|
||||
|
||||
// if (fileStatus !== 'active') {
|
||||
// return global.entries.updateCache(entryPath).then(entry => {
|
||||
// process.send({
|
||||
// action: 'searchAdd',
|
||||
// content: entry
|
||||
// })
|
||||
// return true
|
||||
// })
|
||||
// }
|
||||
|
||||
// return true
|
||||
// })
|
||||
// )
|
||||
// }
|
||||
// }).on('end', () => {
|
||||
// jobCbStreamDocsResolve(Promise.all(cacheJobs))
|
||||
// })
|
||||
|
||||
// return jobCbStreamDocs
|
||||
// }).then(() => {
|
||||
// WIKI.logger.info('Git remote repository sync: DONE')
|
||||
// return true
|
||||
// })
|
||||
}
|
||||
38
server/jobs/sync-graph-locales.js
Normal file
38
server/jobs/sync-graph-locales.js
Normal file
@@ -0,0 +1,38 @@
|
||||
require('../core/worker')
|
||||
const _ = require('lodash')
|
||||
const { createApolloFetch } = require('apollo-fetch')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
WIKI.redis = require('../core/redis').init()
|
||||
const apollo = createApolloFetch({
|
||||
uri: 'https://graph.requarks.io'
|
||||
})
|
||||
|
||||
module.exports = async (job) => {
|
||||
WIKI.logger.info('Syncing locales with Graph endpoint...')
|
||||
|
||||
try {
|
||||
const resp = await apollo({
|
||||
query: `{
|
||||
localization {
|
||||
locales {
|
||||
code
|
||||
name
|
||||
nativeName
|
||||
isRTL
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}`
|
||||
})
|
||||
const locales = _.sortBy(_.get(resp, 'data.localization.locales', []), 'name').map(lc => ({...lc, isInstalled: (lc.code === 'en')}))
|
||||
WIKI.redis.set('locales', JSON.stringify(locales))
|
||||
|
||||
WIKI.logger.info('Syncing locales with Graph endpoint: [ COMPLETED ]')
|
||||
} catch (err) {
|
||||
WIKI.logger.error('Syncing locales with Graph endpoint: [ FAILED ]')
|
||||
WIKI.logger.error(err.message)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user