index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /* eslint-disable @typescript-eslint/no-this-alias */
  2. import http from 'http';
  3. import path from 'path';
  4. import { createTerminus } from '@godaddy/terminus';
  5. import attachmentRoutes from '@growi/remark-attachment-refs/dist/server';
  6. import lsxRoutes from '@growi/remark-lsx/dist/server/index.cjs';
  7. import mongoose from 'mongoose';
  8. import next from 'next';
  9. import pkg from '^/package.json';
  10. import QuestionnaireService from '~/features/questionnaire/server/service/questionnaire';
  11. import QuestionnaireCronService from '~/features/questionnaire/server/service/questionnaire-cron';
  12. import CdnResourcesService from '~/services/cdn-resources-service';
  13. import Xss from '~/services/xss';
  14. import loggerFactory from '~/utils/logger';
  15. import { projectRoot } from '~/utils/project-dir-utils';
  16. import UserEvent from '../events/user';
  17. import Activity from '../models/activity';
  18. import PageRedirect from '../models/page-redirect';
  19. import Tag from '../models/tag';
  20. import UserGroup from '../models/user-group';
  21. import { aclService as aclServiceSingletonInstance } from '../service/acl';
  22. import AppService from '../service/app';
  23. import AttachmentService from '../service/attachment';
  24. import { configManager as configManagerSingletonInstance } from '../service/config-manager';
  25. import { G2GTransferPusherService, G2GTransferReceiverService } from '../service/g2g-transfer';
  26. import { InstallerService } from '../service/installer';
  27. import PageService from '../service/page';
  28. import PageGrantService from '../service/page-grant';
  29. import PageOperationService from '../service/page-operation';
  30. import SearchService from '../service/search';
  31. import { SlackIntegrationService } from '../service/slack-integration';
  32. import { UserNotificationService } from '../service/user-notification';
  33. import { getMongoUri, mongoOptions } from '../util/mongoose-utils';
  34. const logger = loggerFactory('growi:crowi');
  35. const httpErrorHandler = require('../middlewares/http-error-handler');
  36. const models = require('../models');
  37. const sep = path.sep;
  38. function Crowi() {
  39. this.version = pkg.version;
  40. this.runtimeVersions = undefined; // initialized by scanRuntimeVersions()
  41. this.publicDir = path.join(projectRoot, 'public') + sep;
  42. this.resourceDir = path.join(projectRoot, 'resource') + sep;
  43. this.localeDir = path.join(this.resourceDir, 'locales') + sep;
  44. this.viewsDir = path.resolve(__dirname, '../views') + sep;
  45. this.tmpDir = path.join(projectRoot, 'tmp') + sep;
  46. this.cacheDir = path.join(this.tmpDir, 'cache');
  47. this.express = null;
  48. this.config = {};
  49. this.configManager = null;
  50. this.s2sMessagingService = null;
  51. this.g2gTransferPusherService = null;
  52. this.g2gTransferReceiverService = null;
  53. this.mailService = null;
  54. this.passportService = null;
  55. this.globalNotificationService = null;
  56. this.userNotificationService = null;
  57. this.xssService = null;
  58. this.aclService = null;
  59. this.appService = null;
  60. this.fileUploadService = null;
  61. this.restQiitaAPIService = null;
  62. this.growiBridgeService = null;
  63. this.exportService = null;
  64. this.importService = null;
  65. this.pluginService = null;
  66. this.searchService = null;
  67. this.socketIoService = null;
  68. this.pageService = null;
  69. this.syncPageStatusService = null;
  70. this.cdnResourcesService = new CdnResourcesService();
  71. this.slackIntegrationService = null;
  72. this.inAppNotificationService = null;
  73. this.activityService = null;
  74. this.commentService = null;
  75. this.xss = new Xss();
  76. this.questionnaireService = null;
  77. this.questionnaireCronService = null;
  78. this.tokens = null;
  79. this.models = {};
  80. this.env = process.env;
  81. this.node_env = this.env.NODE_ENV || 'development';
  82. this.port = this.env.PORT || 3000;
  83. this.events = {
  84. user: new UserEvent(this),
  85. page: new (require('../events/page'))(this),
  86. activity: new (require('../events/activity'))(this),
  87. bookmark: new (require('../events/bookmark'))(this),
  88. comment: new (require('../events/comment'))(this),
  89. tag: new (require('../events/tag'))(this),
  90. admin: new (require('../events/admin'))(this),
  91. };
  92. }
  93. Crowi.prototype.init = async function() {
  94. await this.setupDatabase();
  95. await this.setupModels();
  96. await this.setupConfigManager();
  97. await this.setupSessionConfig();
  98. this.setupCron();
  99. // setup messaging services
  100. await this.setupS2sMessagingService();
  101. await this.setupSocketIoService();
  102. // customizeService depends on AppService and XssService
  103. // passportService depends on appService
  104. // export and import depends on setUpGrowiBridge
  105. await Promise.all([
  106. this.setUpApp(),
  107. this.setUpXss(),
  108. this.setUpGrowiBridge(),
  109. ]);
  110. await Promise.all([
  111. this.scanRuntimeVersions(),
  112. this.setupPassport(),
  113. this.setupSearcher(),
  114. this.setupMailer(),
  115. this.setupSlackIntegrationService(),
  116. this.setupG2GTransferService(),
  117. this.setUpFileUpload(),
  118. this.setUpFileUploaderSwitchService(),
  119. this.setupAttachmentService(),
  120. this.setUpAcl(),
  121. this.setUpRestQiitaAPI(),
  122. this.setupUserGroupService(),
  123. this.setupExport(),
  124. this.setupImport(),
  125. this.setupGrowiPluginService(),
  126. this.setupPageService(),
  127. this.setupInAppNotificationService(),
  128. this.setupActivityService(),
  129. this.setupCommentService(),
  130. this.setupSyncPageStatusService(),
  131. this.setupQuestionnaireService(),
  132. this.setUpCustomize(), // depends on pluginService
  133. ]);
  134. // globalNotification depends on slack and mailer
  135. await Promise.all([
  136. this.setUpGlobalNotification(),
  137. this.setUpUserNotification(),
  138. ]);
  139. await this.autoInstall();
  140. };
  141. /**
  142. * Execute functions that should be run after the express server is ready.
  143. */
  144. Crowi.prototype.asyncAfterExpressServerReady = async function() {
  145. if (this.pageOperationService != null) {
  146. await this.pageOperationService.afterExpressServerReady();
  147. }
  148. };
  149. Crowi.prototype.isPageId = function(pageId) {
  150. if (!pageId) {
  151. return false;
  152. }
  153. if (typeof pageId === 'string' && pageId.match(/^[\da-f]{24}$/)) {
  154. return true;
  155. }
  156. return false;
  157. };
  158. Crowi.prototype.setConfig = function(config) {
  159. this.config = config;
  160. };
  161. Crowi.prototype.getConfig = function() {
  162. return this.config;
  163. };
  164. Crowi.prototype.getEnv = function() {
  165. return this.env;
  166. };
  167. // getter/setter of model instance
  168. //
  169. Crowi.prototype.model = function(name, model) {
  170. if (model != null) {
  171. this.models[name] = model;
  172. }
  173. return this.models[name];
  174. };
  175. // getter/setter of event instance
  176. Crowi.prototype.event = function(name, event) {
  177. if (event) {
  178. this.events[name] = event;
  179. }
  180. return this.events[name];
  181. };
  182. Crowi.prototype.setupDatabase = function() {
  183. mongoose.Promise = global.Promise;
  184. // mongoUri = mongodb://user:password@host/dbname
  185. const mongoUri = getMongoUri();
  186. return mongoose.connect(mongoUri, mongoOptions);
  187. };
  188. Crowi.prototype.setupSessionConfig = async function() {
  189. const session = require('express-session');
  190. const sessionMaxAge = this.configManager.getConfig('crowi', 'security:sessionMaxAge') || 2592000000; // default: 30days
  191. const redisUrl = this.env.REDISTOGO_URL || this.env.REDIS_URI || this.env.REDIS_URL || null;
  192. const uid = require('uid-safe').sync;
  193. // generate pre-defined uid for healthcheck
  194. const healthcheckUid = uid(24);
  195. const sessionConfig = {
  196. rolling: true,
  197. secret: this.env.SECRET_TOKEN || 'this is default session secret',
  198. resave: false,
  199. saveUninitialized: true,
  200. cookie: {
  201. maxAge: sessionMaxAge,
  202. },
  203. genid(req) {
  204. // return pre-defined uid when healthcheck
  205. if (req.path === '/_api/v3/healthcheck') {
  206. return healthcheckUid;
  207. }
  208. return uid(24);
  209. },
  210. };
  211. if (this.env.SESSION_NAME) {
  212. sessionConfig.name = this.env.SESSION_NAME;
  213. }
  214. // use Redis for session store
  215. if (redisUrl) {
  216. const redis = require('redis');
  217. const redisClient = redis.createClient({ url: redisUrl });
  218. const RedisStore = require('connect-redis')(session);
  219. sessionConfig.store = new RedisStore({ client: redisClient });
  220. }
  221. // use MongoDB for session store
  222. else {
  223. const MongoStore = require('connect-mongo');
  224. sessionConfig.store = MongoStore.create({ client: mongoose.connection.getClient() });
  225. }
  226. this.sessionConfig = sessionConfig;
  227. };
  228. Crowi.prototype.setupConfigManager = async function() {
  229. this.configManager = configManagerSingletonInstance;
  230. return this.configManager.loadConfigs();
  231. };
  232. Crowi.prototype.setupS2sMessagingService = async function() {
  233. const s2sMessagingService = require('../service/s2s-messaging')(this);
  234. if (s2sMessagingService != null) {
  235. s2sMessagingService.subscribe();
  236. this.configManager.setS2sMessagingService(s2sMessagingService);
  237. // add as a message handler
  238. s2sMessagingService.addMessageHandler(this.configManager);
  239. this.s2sMessagingService = s2sMessagingService;
  240. }
  241. };
  242. Crowi.prototype.setupSocketIoService = async function() {
  243. const SocketIoService = require('../service/socket-io');
  244. if (this.socketIoService == null) {
  245. this.socketIoService = new SocketIoService(this);
  246. }
  247. };
  248. Crowi.prototype.setupModels = async function() {
  249. let allModels = {};
  250. // include models that dependent on crowi
  251. allModels = models;
  252. // include models that independent from crowi
  253. allModels.Activity = Activity;
  254. allModels.Tag = Tag;
  255. allModels.UserGroup = UserGroup;
  256. allModels.PageRedirect = PageRedirect;
  257. Object.keys(allModels).forEach((key) => {
  258. return this.model(key, models[key](this));
  259. });
  260. };
  261. Crowi.prototype.setupCron = function() {
  262. this.questionnaireCronService = new QuestionnaireCronService(this);
  263. this.questionnaireCronService.startCron();
  264. };
  265. Crowi.prototype.setupQuestionnaireService = function() {
  266. this.questionnaireService = new QuestionnaireService(this);
  267. };
  268. Crowi.prototype.scanRuntimeVersions = async function() {
  269. const self = this;
  270. const check = require('check-node-version');
  271. return new Promise((resolve, reject) => {
  272. check((err, result) => {
  273. if (err) {
  274. reject(err);
  275. }
  276. self.runtimeVersions = result;
  277. resolve();
  278. });
  279. });
  280. };
  281. Crowi.prototype.getSlack = function() {
  282. return this.slack;
  283. };
  284. Crowi.prototype.getSlackLegacy = function() {
  285. return this.slackLegacy;
  286. };
  287. Crowi.prototype.getGlobalNotificationService = function() {
  288. return this.globalNotificationService;
  289. };
  290. Crowi.prototype.getUserNotificationService = function() {
  291. return this.userNotificationService;
  292. };
  293. Crowi.prototype.getRestQiitaAPIService = function() {
  294. return this.restQiitaAPIService;
  295. };
  296. Crowi.prototype.setupPassport = async function() {
  297. logger.debug('Passport is enabled');
  298. // initialize service
  299. const PassportService = require('../service/passport');
  300. if (this.passportService == null) {
  301. this.passportService = new PassportService(this);
  302. }
  303. this.passportService.setupSerializer();
  304. // setup strategies
  305. try {
  306. this.passportService.setupStrategyById('local');
  307. this.passportService.setupStrategyById('ldap');
  308. this.passportService.setupStrategyById('saml');
  309. this.passportService.setupStrategyById('oidc');
  310. this.passportService.setupStrategyById('google');
  311. this.passportService.setupStrategyById('github');
  312. }
  313. catch (err) {
  314. logger.error(err);
  315. }
  316. // add as a message handler
  317. if (this.s2sMessagingService != null) {
  318. this.s2sMessagingService.addMessageHandler(this.passportService);
  319. }
  320. return Promise.resolve();
  321. };
  322. Crowi.prototype.setupSearcher = async function() {
  323. this.searchService = new SearchService(this);
  324. };
  325. Crowi.prototype.setupMailer = async function() {
  326. const MailService = require('~/server/service/mail');
  327. this.mailService = new MailService(this);
  328. // add as a message handler
  329. if (this.s2sMessagingService != null) {
  330. this.s2sMessagingService.addMessageHandler(this.mailService);
  331. }
  332. };
  333. Crowi.prototype.autoInstall = function() {
  334. const isInstalled = this.configManager.getConfig('crowi', 'app:installed');
  335. const username = this.configManager.getConfig('crowi', 'autoInstall:adminUsername');
  336. if (isInstalled || username == null) {
  337. return;
  338. }
  339. logger.info('Start automatic installation');
  340. const firstAdminUserToSave = {
  341. username,
  342. name: this.configManager.getConfig('crowi', 'autoInstall:adminName'),
  343. email: this.configManager.getConfig('crowi', 'autoInstall:adminEmail'),
  344. password: this.configManager.getConfig('crowi', 'autoInstall:adminPassword'),
  345. admin: true,
  346. };
  347. const globalLang = this.configManager.getConfig('crowi', 'autoInstall:globalLang');
  348. const allowGuestMode = this.configManager.getConfig('crowi', 'autoInstall:allowGuestMode');
  349. const serverDate = this.configManager.getConfig('crowi', 'autoInstall:serverDate');
  350. const installerService = new InstallerService(this);
  351. try {
  352. installerService.install(firstAdminUserToSave, globalLang ?? 'en_US', {
  353. allowGuestMode,
  354. serverDate,
  355. });
  356. }
  357. catch (err) {
  358. logger.warn('Automatic installation failed.', err);
  359. }
  360. };
  361. Crowi.prototype.getTokens = function() {
  362. return this.tokens;
  363. };
  364. Crowi.prototype.start = async function() {
  365. const dev = process.env.NODE_ENV !== 'production';
  366. await this.init();
  367. await this.buildServer();
  368. // setup Next.js
  369. this.nextApp = next({ dev });
  370. await this.nextApp.prepare();
  371. // setup CrowiDev
  372. if (dev) {
  373. const CrowiDev = require('./dev');
  374. this.crowiDev = new CrowiDev(this);
  375. this.crowiDev.init();
  376. }
  377. const { express, configManager } = this;
  378. const app = (this.node_env === 'development') ? this.crowiDev.setupServer(express) : express;
  379. const httpServer = http.createServer(app);
  380. // setup terminus
  381. this.setupTerminus(httpServer);
  382. // attach to socket.io
  383. this.socketIoService.attachServer(httpServer);
  384. // listen
  385. const serverListening = httpServer.listen(this.port, () => {
  386. logger.info(`[${this.node_env}] Express server is listening on port ${this.port}`);
  387. if (this.node_env === 'development') {
  388. this.crowiDev.setupExpressAfterListening(express);
  389. }
  390. });
  391. // listen for promster
  392. if (configManager.getConfig('crowi', 'promster:isEnabled')) {
  393. const { createServer } = require('@promster/server');
  394. const promsterPort = configManager.getConfig('crowi', 'promster:port');
  395. createServer({ port: promsterPort }).then(() => {
  396. logger.info(`[${this.node_env}] Promster server is listening on port ${promsterPort}`);
  397. });
  398. }
  399. // setup Express Routes
  400. this.setupRoutesForPlugins();
  401. this.setupRoutesAtLast();
  402. // setup Global Error Handlers
  403. this.setupGlobalErrorHandlers();
  404. // Execute this asynchronously after the express server is ready so it does not block the ongoing process
  405. this.asyncAfterExpressServerReady();
  406. return serverListening;
  407. };
  408. Crowi.prototype.buildServer = async function() {
  409. const env = this.node_env;
  410. const express = require('express')();
  411. require('./express-init')(this, express);
  412. // use bunyan
  413. if (env === 'production') {
  414. const expressBunyanLogger = require('express-bunyan-logger');
  415. const logger = loggerFactory('express');
  416. express.use(expressBunyanLogger({
  417. logger,
  418. excludes: ['*'],
  419. }));
  420. }
  421. // use morgan
  422. else {
  423. const morgan = require('morgan');
  424. express.use(morgan('dev'));
  425. }
  426. this.express = express;
  427. };
  428. Crowi.prototype.setupTerminus = function(server) {
  429. createTerminus(server, {
  430. signals: ['SIGINT', 'SIGTERM'],
  431. onSignal: async() => {
  432. logger.info('Server is starting cleanup');
  433. await mongoose.disconnect();
  434. return;
  435. },
  436. onShutdown: async() => {
  437. logger.info('Cleanup finished, server is shutting down');
  438. },
  439. });
  440. };
  441. Crowi.prototype.setupRoutesForPlugins = function() {
  442. lsxRoutes(this, this.express);
  443. attachmentRoutes(this, this.express);
  444. };
  445. /**
  446. * setup Express Routes
  447. * !! this must be at last because it includes '/*' route !!
  448. */
  449. Crowi.prototype.setupRoutesAtLast = function() {
  450. require('../routes')(this, this.express);
  451. };
  452. /**
  453. * setup global error handlers
  454. * !! this must be after the Routes setup !!
  455. */
  456. Crowi.prototype.setupGlobalErrorHandlers = function() {
  457. this.express.use(httpErrorHandler);
  458. };
  459. /**
  460. * require API for plugins
  461. *
  462. * @param {string} modulePath relative path from /lib/crowi/index.js
  463. * @return {module}
  464. *
  465. * @memberof Crowi
  466. */
  467. Crowi.prototype.require = function(modulePath) {
  468. return require(modulePath);
  469. };
  470. /**
  471. * setup GlobalNotificationService
  472. */
  473. Crowi.prototype.setUpGlobalNotification = async function() {
  474. const GlobalNotificationService = require('../service/global-notification');
  475. if (this.globalNotificationService == null) {
  476. this.globalNotificationService = new GlobalNotificationService(this);
  477. }
  478. };
  479. /**
  480. * setup UserNotificationService
  481. */
  482. Crowi.prototype.setUpUserNotification = async function() {
  483. if (this.userNotificationService == null) {
  484. this.userNotificationService = new UserNotificationService(this);
  485. }
  486. };
  487. /**
  488. * setup XssService
  489. */
  490. Crowi.prototype.setUpXss = async function() {
  491. const XssService = require('../service/xss');
  492. if (this.xssService == null) {
  493. this.xssService = new XssService(this.configManager);
  494. }
  495. };
  496. /**
  497. * setup AclService
  498. */
  499. Crowi.prototype.setUpAcl = async function() {
  500. this.aclService = aclServiceSingletonInstance;
  501. };
  502. /**
  503. * setup CustomizeService
  504. */
  505. Crowi.prototype.setUpCustomize = async function() {
  506. const CustomizeService = require('../service/customize');
  507. if (this.customizeService == null) {
  508. this.customizeService = new CustomizeService(this);
  509. this.customizeService.initCustomCss();
  510. this.customizeService.initCustomTitle();
  511. this.customizeService.initGrowiTheme();
  512. // add as a message handler
  513. if (this.s2sMessagingService != null) {
  514. this.s2sMessagingService.addMessageHandler(this.customizeService);
  515. }
  516. }
  517. };
  518. /**
  519. * setup AppService
  520. */
  521. Crowi.prototype.setUpApp = async function() {
  522. if (this.appService == null) {
  523. this.appService = new AppService(this);
  524. // add as a message handler
  525. const isInstalled = this.configManager.getConfig('crowi', 'app:installed');
  526. if (this.s2sMessagingService != null && !isInstalled) {
  527. this.s2sMessagingService.addMessageHandler(this.appService);
  528. }
  529. }
  530. };
  531. /**
  532. * setup FileUploadService
  533. */
  534. Crowi.prototype.setUpFileUpload = async function(isForceUpdate = false) {
  535. if (this.fileUploadService == null || isForceUpdate) {
  536. this.fileUploadService = require('../service/file-uploader')(this);
  537. }
  538. };
  539. /**
  540. * setup FileUploaderSwitchService
  541. */
  542. Crowi.prototype.setUpFileUploaderSwitchService = async function() {
  543. const FileUploaderSwitchService = require('../service/file-uploader-switch');
  544. this.fileUploaderSwitchService = new FileUploaderSwitchService(this);
  545. // add as a message handler
  546. if (this.s2sMessagingService != null) {
  547. this.s2sMessagingService.addMessageHandler(this.fileUploaderSwitchService);
  548. }
  549. };
  550. /**
  551. * setup AttachmentService
  552. */
  553. Crowi.prototype.setupAttachmentService = async function() {
  554. if (this.attachmentService == null) {
  555. this.attachmentService = new AttachmentService(this);
  556. }
  557. };
  558. /**
  559. * setup RestQiitaAPIService
  560. */
  561. Crowi.prototype.setUpRestQiitaAPI = async function() {
  562. const RestQiitaAPIService = require('../service/rest-qiita-API');
  563. if (this.restQiitaAPIService == null) {
  564. this.restQiitaAPIService = new RestQiitaAPIService(this);
  565. }
  566. };
  567. Crowi.prototype.setupUserGroupService = async function() {
  568. const UserGroupService = require('../service/user-group');
  569. if (this.userGroupService == null) {
  570. this.userGroupService = new UserGroupService(this);
  571. return this.userGroupService.init();
  572. }
  573. };
  574. Crowi.prototype.setUpGrowiBridge = async function() {
  575. const GrowiBridgeService = require('../service/growi-bridge');
  576. if (this.growiBridgeService == null) {
  577. this.growiBridgeService = new GrowiBridgeService(this);
  578. }
  579. };
  580. Crowi.prototype.setupExport = async function() {
  581. const ExportService = require('../service/export');
  582. if (this.exportService == null) {
  583. this.exportService = new ExportService(this);
  584. }
  585. };
  586. Crowi.prototype.setupImport = async function() {
  587. const ImportService = require('../service/import');
  588. if (this.importService == null) {
  589. this.importService = new ImportService(this);
  590. }
  591. };
  592. Crowi.prototype.setupGrowiPluginService = async function() {
  593. const growiPluginService = await import('~/features/growi-plugin/server/services').then(mod => mod.growiPluginService);
  594. // download plugin repositories, if document exists but there is no repository
  595. // TODO: Cannot download unless connected to the Internet at setup.
  596. await growiPluginService.downloadNotExistPluginRepositories();
  597. };
  598. Crowi.prototype.setupPageService = async function() {
  599. if (this.pageService == null) {
  600. this.pageService = new PageService(this);
  601. }
  602. if (this.pageGrantService == null) {
  603. this.pageGrantService = new PageGrantService(this);
  604. }
  605. if (this.pageOperationService == null) {
  606. this.pageOperationService = new PageOperationService(this);
  607. await this.pageOperationService.init();
  608. }
  609. };
  610. Crowi.prototype.setupInAppNotificationService = async function() {
  611. const InAppNotificationService = require('../service/in-app-notification');
  612. if (this.inAppNotificationService == null) {
  613. this.inAppNotificationService = new InAppNotificationService(this);
  614. }
  615. };
  616. Crowi.prototype.setupActivityService = async function() {
  617. const ActivityService = require('../service/activity');
  618. if (this.activityService == null) {
  619. this.activityService = new ActivityService(this);
  620. await this.activityService.createTtlIndex();
  621. }
  622. };
  623. Crowi.prototype.setupCommentService = async function() {
  624. const CommentService = require('../service/comment');
  625. if (this.commentService == null) {
  626. this.commentService = new CommentService(this);
  627. }
  628. };
  629. Crowi.prototype.setupSyncPageStatusService = async function() {
  630. const SyncPageStatusService = require('../service/system-events/sync-page-status');
  631. if (this.syncPageStatusService == null) {
  632. this.syncPageStatusService = new SyncPageStatusService(this, this.s2sMessagingService, this.socketIoService);
  633. // add as a message handler
  634. if (this.s2sMessagingService != null) {
  635. this.s2sMessagingService.addMessageHandler(this.syncPageStatusService);
  636. }
  637. }
  638. };
  639. Crowi.prototype.setupSlackIntegrationService = async function() {
  640. if (this.slackIntegrationService == null) {
  641. this.slackIntegrationService = new SlackIntegrationService(this);
  642. }
  643. // add as a message handler
  644. if (this.s2sMessagingService != null) {
  645. this.s2sMessagingService.addMessageHandler(this.slackIntegrationService);
  646. }
  647. };
  648. Crowi.prototype.setupG2GTransferService = async function() {
  649. if (this.g2gTransferPusherService == null) {
  650. this.g2gTransferPusherService = new G2GTransferPusherService(this);
  651. }
  652. if (this.g2gTransferReceiverService == null) {
  653. this.g2gTransferReceiverService = new G2GTransferReceiverService(this);
  654. }
  655. };
  656. export default Crowi;