app.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. getAppConfidential() {
  37. return this.configManager.getConfig('crowi', 'app:confidential');
  38. }
  39. /**
  40. * Execute only once for installing application
  41. */
  42. async initDB(globalLang) {
  43. const initialConfig = this.configManager.configModel.getConfigsObjectForInstalling();
  44. initialConfig['app:globalLang'] = globalLang;
  45. await this.configManager.updateConfigsInTheSameNamespace('crowi', initialConfig);
  46. }
  47. async isDBInitialized() {
  48. const appInstalled = await this.configManager.getConfigFromDB('crowi', 'app:installed');
  49. return appInstalled;
  50. }
  51. }
  52. module.exports = AppService;