app.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const logger = require('@alias/logger')('growi:service:AppService'); // eslint-disable-line no-unused-vars
  2. const { pathUtils } = require('growi-commons');
  3. /**
  4. * the service class of AppService
  5. */
  6. class AppService {
  7. constructor(configManager) {
  8. this.configManager = configManager;
  9. }
  10. getAppTitle() {
  11. return this.configManager.getConfig('crowi', 'app:title') || 'GROWI';
  12. }
  13. /**
  14. * get the site url
  15. *
  16. * If the config for the site url is not set, this returns a message "[The site URL is not set. Please set it!]".
  17. *
  18. * With version 3.2.3 and below, there is no config for the site URL, so the system always uses auto-generated site URL.
  19. * With version 3.2.4 to 3.3.4, the system uses the auto-generated site URL only if the config is not set.
  20. * With version 3.3.5 and above, the system use only a value from the config.
  21. */
  22. /* eslint-disable no-else-return */
  23. getSiteUrl() {
  24. const siteUrl = this.configManager.getConfig('crowi', 'app:siteUrl');
  25. if (siteUrl != null) {
  26. return pathUtils.removeTrailingSlash(siteUrl);
  27. }
  28. else {
  29. return '[The site URL is not set. Please set it!]';
  30. }
  31. }
  32. /* eslint-enable no-else-return */
  33. getTzoffset() {
  34. return -(this.configManager.getConfig('crowi', 'app:timezone') || 9) * 60;
  35. }
  36. /**
  37. * Execute only once for installing application
  38. */
  39. async initDB(globalLang) {
  40. const initialConfig = this.configManager.configModel.getConfigsObjectForInstalling();
  41. initialConfig['app:globalLang'] = globalLang;
  42. await this.configManager.updateConfigsInTheSameNamespace('crowi', initialConfig);
  43. }
  44. async isDBInitialized() {
  45. const appInstalled = await this.configManager.getConfigFromDB('crowi', 'app:installed');
  46. return appInstalled;
  47. }
  48. }
  49. module.exports = AppService;