2018-03-18 04:34:32 +00:00
|
|
|
const _ = require('lodash')
|
2018-05-06 21:33:41 +00:00
|
|
|
const Promise = require('bluebird')
|
|
|
|
const getos = Promise.promisify(require('getos'))
|
2018-03-18 04:34:32 +00:00
|
|
|
const os = require('os')
|
|
|
|
const filesize = require('filesize')
|
2018-05-06 21:33:41 +00:00
|
|
|
const path = require('path')
|
2018-11-11 04:40:55 +00:00
|
|
|
const fs = require('fs-extra')
|
2018-03-18 04:34:32 +00:00
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
2018-05-06 21:33:41 +00:00
|
|
|
const dbTypes = {
|
2018-09-08 19:49:36 +00:00
|
|
|
mysql: 'MySQL',
|
|
|
|
mariadb: 'MariaDB',
|
2018-05-06 21:33:41 +00:00
|
|
|
postgres: 'PostgreSQL',
|
2018-05-19 20:40:07 +00:00
|
|
|
sqlite: 'SQLite',
|
|
|
|
mssql: 'MS SQL Server'
|
2018-05-06 21:33:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-18 04:34:32 +00:00
|
|
|
module.exports = {
|
|
|
|
Query: {
|
|
|
|
async system() { return {} }
|
|
|
|
},
|
|
|
|
SystemQuery: {
|
2018-09-04 00:58:54 +00:00
|
|
|
async info() { return {} }
|
|
|
|
},
|
|
|
|
SystemInfo: {
|
|
|
|
configFile() {
|
|
|
|
return path.join(process.cwd(), 'config.yml')
|
|
|
|
},
|
|
|
|
currentVersion() {
|
|
|
|
return WIKI.version
|
|
|
|
},
|
|
|
|
dbType() {
|
|
|
|
return _.get(dbTypes, WIKI.config.db.type, 'Unknown DB')
|
|
|
|
},
|
2018-09-08 19:49:36 +00:00
|
|
|
async dbVersion() {
|
|
|
|
let version = 'Unknown Version'
|
|
|
|
switch (WIKI.config.db.type) {
|
|
|
|
case 'mariadb':
|
|
|
|
case 'mysql':
|
|
|
|
const resultMYSQL = await WIKI.models.knex.raw('SELECT VERSION() as version;')
|
|
|
|
version = _.get(resultMYSQL, '[0][0].version', 'Unknown Version')
|
|
|
|
break
|
|
|
|
case 'mssql':
|
|
|
|
const resultMSSQL = await WIKI.models.knex.raw('SELECT @@VERSION as version;')
|
|
|
|
version = _.get(resultMSSQL, '[0].version', 'Unknown Version')
|
|
|
|
break
|
|
|
|
case 'postgres':
|
|
|
|
version = _.get(WIKI.models, 'knex.client.version', 'Unknown Version')
|
|
|
|
break
|
|
|
|
case 'sqlite':
|
|
|
|
version = _.get(WIKI.models, 'knex.client.driver.VERSION', 'Unknown Version')
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return version
|
2018-09-04 00:58:54 +00:00
|
|
|
},
|
|
|
|
dbHost() {
|
2018-09-08 19:49:36 +00:00
|
|
|
if (WIKI.config.db.type === 'sqlite') {
|
|
|
|
return WIKI.config.db.storage
|
|
|
|
} else {
|
|
|
|
return WIKI.config.db.host
|
|
|
|
}
|
2018-09-04 00:58:54 +00:00
|
|
|
},
|
|
|
|
latestVersion() {
|
|
|
|
return '2.0.0' // TODO
|
|
|
|
},
|
|
|
|
latestVersionReleaseDate() {
|
|
|
|
return new Date() // TODO
|
|
|
|
},
|
|
|
|
async operatingSystem() {
|
2018-05-06 21:33:41 +00:00
|
|
|
let osLabel = `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`
|
|
|
|
if (os.platform() === 'linux') {
|
|
|
|
const osInfo = await getos()
|
|
|
|
osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
|
|
|
|
}
|
2018-12-30 02:30:51 +00:00
|
|
|
return osLabel
|
|
|
|
},
|
|
|
|
async platform () {
|
2018-11-11 04:40:55 +00:00
|
|
|
const isDockerized = await fs.pathExists('/.dockerenv')
|
|
|
|
if (isDockerized) {
|
2018-12-30 02:30:51 +00:00
|
|
|
return 'docker'
|
2018-11-11 04:40:55 +00:00
|
|
|
}
|
2018-12-30 02:30:51 +00:00
|
|
|
return os.platform()
|
2018-09-04 00:58:54 +00:00
|
|
|
},
|
|
|
|
hostname() {
|
|
|
|
return os.hostname()
|
|
|
|
},
|
|
|
|
cpuCores() {
|
|
|
|
return os.cpus().length
|
|
|
|
},
|
|
|
|
ramTotal() {
|
|
|
|
return filesize(os.totalmem())
|
|
|
|
},
|
|
|
|
workingDirectory() {
|
|
|
|
return process.cwd()
|
|
|
|
},
|
|
|
|
nodeVersion() {
|
|
|
|
return process.version.substr(1)
|
|
|
|
},
|
|
|
|
redisVersion() {
|
|
|
|
return WIKI.redis.serverInfo.redis_version
|
|
|
|
},
|
|
|
|
redisUsedRAM() {
|
|
|
|
return WIKI.redis.serverInfo.used_memory_human
|
|
|
|
},
|
|
|
|
redisTotalRAM() {
|
|
|
|
return _.get(WIKI.redis.serverInfo, 'total_system_memory_human', 'N/A')
|
|
|
|
},
|
|
|
|
redisHost() {
|
|
|
|
return WIKI.redis.options.host
|
|
|
|
},
|
|
|
|
async groupsTotal() {
|
|
|
|
const total = await WIKI.models.groups.query().count('* as total').first().pluck('total')
|
|
|
|
return _.toSafeInteger(total)
|
|
|
|
},
|
|
|
|
async pagesTotal() {
|
|
|
|
const total = await WIKI.models.pages.query().count('* as total').first().pluck('total')
|
|
|
|
return _.toSafeInteger(total)
|
|
|
|
},
|
|
|
|
async usersTotal() {
|
|
|
|
const total = await WIKI.models.users.query().count('* as total').first().pluck('total')
|
|
|
|
return _.toSafeInteger(total)
|
2018-03-18 04:34:32 +00:00
|
|
|
}
|
2018-09-04 00:58:54 +00:00
|
|
|
}
|
2018-03-18 04:34:32 +00:00
|
|
|
}
|