mirror of https://github.com/Requarks/wiki.git
10 changed files with 129 additions and 266 deletions
Unified View
Diff Options
-
3.eslintrc.yml
-
9assets/svg/config-bg.svg
-
5client/js/components/config-manager.component.js
-
33client/scss/components/config-manager.scss
-
2client/scss/components/form.scss
-
12config.sample.yml
-
3server/app/data.yml
-
161server/configure.js
-
159server/modules/system.js
-
8server/views/configure/index.pug
@ -0,0 +1,9 @@ |
|||||
|
<svg |
||||
|
xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'> |
||||
|
<g fill-rule='evenodd'> |
||||
|
<g fill='#1976d2' fill-opacity='0.52'> |
||||
|
<path opacity='.5' d='M96 95h4v1h-4v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4h-9v4h-1v-4H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15v-9H0v-1h15V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h9V0h1v15h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9h4v1h-4v9zm-1 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm9-10v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm9-10v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm9-10v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-10 0v-9h-9v9h9zm-9-10h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9zm10 0h9v-9h-9v9z'/> |
||||
|
<path d='M6 5V0H5v5H0v1h5v94h1V6h94V5H6z'/> |
||||
|
</g> |
||||
|
</g> |
||||
|
</svg> |
@ -1,136 +1,53 @@ |
|||||
'use strict' |
|
||||
|
|
||||
/* global winston, ROOTPATH, appconfig */ |
|
||||
|
/* global wiki */ |
||||
|
|
||||
const Promise = require('bluebird') |
const Promise = require('bluebird') |
||||
const crypto = require('crypto') |
|
||||
const fs = Promise.promisifyAll(require('fs-extra')) |
|
||||
const https = require('follow-redirects').https |
|
||||
const klaw = require('klaw') |
|
||||
const path = require('path') |
|
||||
const pm2 = Promise.promisifyAll(require('pm2')) |
|
||||
const tar = require('tar') |
|
||||
const through2 = require('through2') |
|
||||
const zlib = require('zlib') |
|
||||
const _ = require('lodash') |
|
||||
|
// const pm2 = Promise.promisifyAll(require('pm2'))
|
||||
|
// const _ = require('lodash')
|
||||
|
const cfgHelper = require('../helpers/config') |
||||
|
|
||||
module.exports = { |
module.exports = { |
||||
|
|
||||
_remoteFile: 'https://github.com/Requarks/wiki/releases/download/{0}/wiki-js.tar.gz', |
|
||||
_installDir: '', |
|
||||
|
|
||||
/** |
/** |
||||
* Install a version of Wiki.js |
|
||||
|
* Upgrade from Wiki.js 1.x - MongoDB database |
||||
* |
* |
||||
* @param {any} targetTag The version to install |
|
||||
* @returns {Promise} Promise of the operation |
|
||||
|
* @param {Object} opts Options object |
||||
*/ |
*/ |
||||
install (targetTag) { |
|
||||
let self = this |
|
||||
|
async upgradeFromMongo (opts) { |
||||
|
wiki.telemetry.sendEvent('setup', 'upgradeFromMongo') |
||||
|
|
||||
self._installDir = path.resolve(ROOTPATH, appconfig.paths.data, 'install') |
|
||||
|
let mongo = require('mongodb').MongoClient |
||||
|
let parsedMongoConStr = cfgHelper.parseConfigValue(opts.mongoCnStr) |
||||
|
|
||||
return fs.ensureDirAsync(self._installDir).then(() => { |
|
||||
return fs.emptyDirAsync(self._installDir) |
|
||||
}).then(() => { |
|
||||
let remoteURL = _.replace(self._remoteFile, '{0}', targetTag) |
|
||||
|
|
||||
return new Promise((resolve, reject) => { |
|
||||
/** |
|
||||
* Fetch tarball and extract to temporary folder |
|
||||
*/ |
|
||||
https.get(remoteURL, resp => { |
|
||||
if (resp.statusCode !== 200) { |
|
||||
return reject(new Error('Remote file not found')) |
|
||||
|
return new Promise((resolve, reject) => { |
||||
|
// Connect to MongoDB
|
||||
|
|
||||
|
return mongo.connect(parsedMongoConStr, { |
||||
|
autoReconnect: false, |
||||
|
reconnectTries: 2, |
||||
|
reconnectInterval: 1000, |
||||
|
connectTimeoutMS: 5000, |
||||
|
socketTimeoutMS: 5000 |
||||
|
}, async (err, db) => { |
||||
|
try { |
||||
|
if (err !== null) { throw err } |
||||
|
|
||||
|
let users = db.collection('users') |
||||
|
|
||||
|
// Check if users table is populated
|
||||
|
let userCount = await users.count() |
||||
|
if (userCount < 1) { |
||||
|
throw new Error('Users table is empty or invalid!') |
||||
} |
} |
||||
winston.info('[SERVER.System] Install tarball found. Downloading...') |
|
||||
|
|
||||
resp.pipe(zlib.createGunzip()) |
|
||||
.pipe(tar.Extract({ path: self._installDir })) |
|
||||
.on('error', err => reject(err)) |
|
||||
.on('end', () => { |
|
||||
winston.info('[SERVER.System] Tarball extracted. Comparing files...') |
|
||||
/** |
|
||||
* Replace old files |
|
||||
*/ |
|
||||
klaw(self._installDir) |
|
||||
.on('error', err => reject(err)) |
|
||||
.on('end', () => { |
|
||||
winston.info('[SERVER.System] All files were updated successfully.') |
|
||||
resolve(true) |
|
||||
}) |
|
||||
.pipe(self.replaceFile()) |
|
||||
}) |
|
||||
}) |
|
||||
}) |
|
||||
}).then(() => { |
|
||||
winston.info('[SERVER.System] Cleaning install leftovers...') |
|
||||
return fs.removeAsync(self._installDir).then(() => { |
|
||||
winston.info('[SERVER.System] Restarting Wiki.js...') |
|
||||
return pm2.restartAsync('wiki').catch(err => { // eslint-disable-line handle-callback-err
|
|
||||
winston.error('Unable to restart Wiki.js via pm2... Do a manual restart!') |
|
||||
process.exit() |
|
||||
}) |
|
||||
}) |
|
||||
}).catch(err => { |
|
||||
winston.warn(err) |
|
||||
}) |
|
||||
}, |
|
||||
|
// Fetch all users
|
||||
|
let userData = await users.find({}).toArray() |
||||
|
console.info(userData) |
||||
|
|
||||
/** |
|
||||
* Replace file if different |
|
||||
*/ |
|
||||
replaceFile () { |
|
||||
let self = this |
|
||||
return through2.obj((item, enc, next) => { |
|
||||
if (!item.stats.isDirectory()) { |
|
||||
self.digestFile(item.path).then(sourceHash => { |
|
||||
let destFilePath = _.replace(item.path, self._installDir, ROOTPATH) |
|
||||
return self.digestFile(destFilePath).then(targetHash => { |
|
||||
if (sourceHash === targetHash) { |
|
||||
winston.log('verbose', '[SERVER.System] Skipping ' + destFilePath) |
|
||||
return fs.removeAsync(item.path).then(() => { |
|
||||
return next() || true |
|
||||
}) |
|
||||
} else { |
|
||||
winston.log('verbose', '[SERVER.System] Updating ' + destFilePath + '...') |
|
||||
return fs.moveAsync(item.path, destFilePath, { overwrite: true }).then(() => { |
|
||||
return next() || true |
|
||||
}) |
|
||||
} |
|
||||
}) |
|
||||
}).catch(err => { |
|
||||
throw err |
|
||||
}) |
|
||||
} else { |
|
||||
next() |
|
||||
} |
|
||||
}) |
|
||||
}, |
|
||||
|
|
||||
/** |
|
||||
* Generate the hash of a file |
|
||||
* |
|
||||
* @param {String} filePath The absolute path of the file |
|
||||
* @return {Promise<String>} Promise of the hash result |
|
||||
*/ |
|
||||
digestFile: (filePath) => { |
|
||||
return new Promise((resolve, reject) => { |
|
||||
let hash = crypto.createHash('sha1') |
|
||||
hash.setEncoding('hex') |
|
||||
fs.createReadStream(filePath) |
|
||||
.on('error', err => { reject(err) }) |
|
||||
.on('end', () => { |
|
||||
hash.end() |
|
||||
resolve(hash.read()) |
|
||||
}) |
|
||||
.pipe(hash) |
|
||||
}).catch(err => { |
|
||||
if (err.code === 'ENOENT') { |
|
||||
return '0' |
|
||||
} else { |
|
||||
throw err |
|
||||
} |
|
||||
|
resolve(true) |
||||
|
} catch (err) { |
||||
|
reject(err) |
||||
|
db.close() |
||||
|
} |
||||
|
}) |
||||
}) |
}) |
||||
} |
} |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save