You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.2 KiB

  1. const _ = require('lodash')
  2. const Promise = require('bluebird')
  3. const getos = Promise.promisify(require('getos'))
  4. const os = require('os')
  5. const filesize = require('filesize')
  6. const path = require('path')
  7. const fs = require('fs-extra')
  8. const moment = require('moment')
  9. /* global WIKI */
  10. const dbTypes = {
  11. mysql: 'MySQL',
  12. mariadb: 'MariaDB',
  13. postgres: 'PostgreSQL',
  14. sqlite: 'SQLite',
  15. mssql: 'MS SQL Server'
  16. }
  17. module.exports = {
  18. Query: {
  19. async system() { return {} }
  20. },
  21. SystemQuery: {
  22. async info() { return {} }
  23. },
  24. SystemInfo: {
  25. configFile() {
  26. return path.join(process.cwd(), 'config.yml')
  27. },
  28. currentVersion() {
  29. return WIKI.version
  30. },
  31. dbType() {
  32. return _.get(dbTypes, WIKI.config.db.type, 'Unknown DB')
  33. },
  34. async dbVersion() {
  35. let version = 'Unknown Version'
  36. switch (WIKI.config.db.type) {
  37. case 'mariadb':
  38. case 'mysql':
  39. const resultMYSQL = await WIKI.models.knex.raw('SELECT VERSION() as version;')
  40. version = _.get(resultMYSQL, '[0][0].version', 'Unknown Version')
  41. break
  42. case 'mssql':
  43. const resultMSSQL = await WIKI.models.knex.raw('SELECT @@VERSION as version;')
  44. version = _.get(resultMSSQL, '[0].version', 'Unknown Version')
  45. break
  46. case 'postgres':
  47. version = _.get(WIKI.models, 'knex.client.version', 'Unknown Version')
  48. break
  49. case 'sqlite':
  50. version = _.get(WIKI.models, 'knex.client.driver.VERSION', 'Unknown Version')
  51. break
  52. }
  53. return version
  54. },
  55. dbHost() {
  56. if (WIKI.config.db.type === 'sqlite') {
  57. return WIKI.config.db.storage
  58. } else {
  59. return WIKI.config.db.host
  60. }
  61. },
  62. latestVersion() {
  63. return WIKI.system.updates.version
  64. },
  65. latestVersionReleaseDate() {
  66. return moment.utc(WIKI.system.updates.releaseDate)
  67. },
  68. async operatingSystem() {
  69. let osLabel = `${os.type()} (${os.platform()}) ${os.release()} ${os.arch()}`
  70. if (os.platform() === 'linux') {
  71. const osInfo = await getos()
  72. osLabel = `${os.type()} - ${osInfo.dist} (${osInfo.codename || os.platform()}) ${osInfo.release || os.release()} ${os.arch()}`
  73. }
  74. return osLabel
  75. },
  76. async platform () {
  77. const isDockerized = await fs.pathExists('/.dockerenv')
  78. if (isDockerized) {
  79. return 'docker'
  80. }
  81. return os.platform()
  82. },
  83. hostname() {
  84. return os.hostname()
  85. },
  86. cpuCores() {
  87. return os.cpus().length
  88. },
  89. ramTotal() {
  90. return filesize(os.totalmem())
  91. },
  92. workingDirectory() {
  93. return process.cwd()
  94. },
  95. nodeVersion() {
  96. return process.version.substr(1)
  97. },
  98. async groupsTotal() {
  99. const total = await WIKI.models.groups.query().count('* as total').first().pluck('total')
  100. return _.toSafeInteger(total)
  101. },
  102. async pagesTotal() {
  103. const total = await WIKI.models.pages.query().count('* as total').first().pluck('total')
  104. return _.toSafeInteger(total)
  105. },
  106. async usersTotal() {
  107. const total = await WIKI.models.users.query().count('* as total').first().pluck('total')
  108. return _.toSafeInteger(total)
  109. }
  110. }
  111. }