mirror of https://github.com/Requarks/wiki.git
NGPixel
5 years ago
10 changed files with 198 additions and 119 deletions
Split View
Diff Options
-
81client/components/common/page-selector.vue
-
10server/app/data.yml
-
7server/core/scheduler.js
-
18server/graph/resolvers/asset.js
-
63server/jobs/rebuild-tree.js
-
69server/jobs/sync-git.js
-
8server/models/assets.js
-
2server/models/pages.js
-
11server/models/storage.js
-
48server/modules/storage/git/storage.js
@ -0,0 +1,63 @@ |
|||
const _ = require('lodash') |
|||
|
|||
/* global WIKI */ |
|||
|
|||
module.exports = async (pageId) => { |
|||
WIKI.logger.info(`Rebuilding page tree...`) |
|||
|
|||
try { |
|||
WIKI.models = require('../core/db').init() |
|||
await WIKI.configSvc.loadFromDb() |
|||
await WIKI.configSvc.applyFlags() |
|||
|
|||
await WIKI.models.knex.table('pageTree').truncate() |
|||
const pages = await WIKI.models.pages.query().select('id', 'path', 'localeCode', 'title', 'isPrivate', 'privateNS').orderBy(['localeCode', 'path']) |
|||
let tree = [] |
|||
let pik = 0 |
|||
|
|||
for (const page of pages) { |
|||
const pagePaths = page.path.split('/') |
|||
let currentPath = '' |
|||
let depth = 0 |
|||
let parentId = null |
|||
for (const part of pagePaths) { |
|||
depth++ |
|||
const isFolder = (depth < pagePaths.length) |
|||
currentPath = currentPath ? `${currentPath}/${part}` : part |
|||
const found = _.find(tree, { |
|||
localeCode: page.localeCode, |
|||
path: currentPath |
|||
}) |
|||
if (!found) { |
|||
pik++ |
|||
tree.push({ |
|||
id: pik, |
|||
localeCode: page.localeCode, |
|||
path: currentPath, |
|||
depth: depth, |
|||
title: isFolder ? part : page.title, |
|||
isFolder: isFolder, |
|||
isPrivate: !isFolder && page.isPrivate, |
|||
privateNS: !isFolder ? page.privateNS : null, |
|||
parent: parentId, |
|||
pageId: isFolder ? null : page.id |
|||
}) |
|||
parentId = pik |
|||
} else { |
|||
parentId = found.id |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (tree.length > 0) { |
|||
await WIKI.models.knex.table('pageTree').insert(tree) |
|||
} |
|||
|
|||
await WIKI.models.knex.destroy() |
|||
|
|||
WIKI.logger.info(`Rebuilding page tree: [ COMPLETED ]`) |
|||
} catch (err) { |
|||
WIKI.logger.error(`Rebuilding page tree: [ FAILED ]`) |
|||
WIKI.logger.error(err.message) |
|||
} |
|||
} |
@ -1,69 +0,0 @@ |
|||
'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
|
|||
// })
|
|||
} |
Write
Preview
Loading…
Cancel
Save