index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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 } = 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. // setup Express Routes
  392. this.setupRoutesForPlugins();
  393. this.setupRoutesAtLast();
  394. // setup Global Error Handlers
  395. this.setupGlobalErrorHandlers();
  396. // Execute this asynchronously after the express server is ready so it does not block the ongoing process
  397. this.asyncAfterExpressServerReady();
  398. return serverListening;
  399. };
  400. Crowi.prototype.buildServer = async function() {
  401. const env = this.node_env;
  402. const express = require('express')();
  403. require('./express-init')(this, express);
  404. // use bunyan
  405. if (env === 'production') {
  406. const expressBunyanLogger = require('express-bunyan-logger');
  407. const logger = loggerFactory('express');
  408. express.use(expressBunyanLogger({
  409. logger,
  410. excludes: ['*'],
  411. }));
  412. }
  413. // use morgan
  414. else {
  415. const morgan = require('morgan');
  416. express.use(morgan('dev'));
  417. }
  418. this.express = express;
  419. };
  420. Crowi.prototype.setupTerminus = function(server) {
  421. createTerminus(server, {
  422. signals: ['SIGINT', 'SIGTERM'],
  423. onSignal: async() => {
  424. logger.info('Server is starting cleanup');
  425. await mongoose.disconnect();
  426. return;
  427. },
  428. onShutdown: async() => {
  429. logger.info('Cleanup finished, server is shutting down');
  430. },
  431. });
  432. };
  433. Crowi.prototype.setupRoutesForPlugins = function() {
  434. lsxRoutes(this, this.express);
  435. attachmentRoutes(this, this.express);
  436. };
  437. /**
  438. * setup Express Routes
  439. * !! this must be at last because it includes '/*' route !!
  440. */
  441. Crowi.prototype.setupRoutesAtLast = function() {
  442. require('../routes')(this, this.express);
  443. };
  444. /**
  445. * setup global error handlers
  446. * !! this must be after the Routes setup !!
  447. */
  448. Crowi.prototype.setupGlobalErrorHandlers = function() {
  449. this.express.use(httpErrorHandler);
  450. };
  451. /**
  452. * require API for plugins
  453. *
  454. * @param {string} modulePath relative path from /lib/crowi/index.js
  455. * @return {module}
  456. *
  457. * @memberof Crowi
  458. */
  459. Crowi.prototype.require = function(modulePath) {
  460. return require(modulePath);
  461. };
  462. /**
  463. * setup GlobalNotificationService
  464. */
  465. Crowi.prototype.setUpGlobalNotification = async function() {
  466. const GlobalNotificationService = require('../service/global-notification');
  467. if (this.globalNotificationService == null) {
  468. this.globalNotificationService = new GlobalNotificationService(this);
  469. }
  470. };
  471. /**
  472. * setup UserNotificationService
  473. */
  474. Crowi.prototype.setUpUserNotification = async function() {
  475. if (this.userNotificationService == null) {
  476. this.userNotificationService = new UserNotificationService(this);
  477. }
  478. };
  479. /**
  480. * setup XssService
  481. */
  482. Crowi.prototype.setUpXss = async function() {
  483. const XssService = require('../service/xss');
  484. if (this.xssService == null) {
  485. this.xssService = new XssService(this.configManager);
  486. }
  487. };
  488. /**
  489. * setup AclService
  490. */
  491. Crowi.prototype.setUpAcl = async function() {
  492. this.aclService = aclServiceSingletonInstance;
  493. };
  494. /**
  495. * setup CustomizeService
  496. */
  497. Crowi.prototype.setUpCustomize = async function() {
  498. const CustomizeService = require('../service/customize');
  499. if (this.customizeService == null) {
  500. this.customizeService = new CustomizeService(this);
  501. this.customizeService.initCustomCss();
  502. this.customizeService.initCustomTitle();
  503. this.customizeService.initGrowiTheme();
  504. // add as a message handler
  505. if (this.s2sMessagingService != null) {
  506. this.s2sMessagingService.addMessageHandler(this.customizeService);
  507. }
  508. }
  509. };
  510. /**
  511. * setup AppService
  512. */
  513. Crowi.prototype.setUpApp = async function() {
  514. if (this.appService == null) {
  515. this.appService = new AppService(this);
  516. // add as a message handler
  517. const isInstalled = this.configManager.getConfig('crowi', 'app:installed');
  518. if (this.s2sMessagingService != null && !isInstalled) {
  519. this.s2sMessagingService.addMessageHandler(this.appService);
  520. }
  521. }
  522. };
  523. /**
  524. * setup FileUploadService
  525. */
  526. Crowi.prototype.setUpFileUpload = async function(isForceUpdate = false) {
  527. if (this.fileUploadService == null || isForceUpdate) {
  528. this.fileUploadService = require('../service/file-uploader')(this);
  529. }
  530. };
  531. /**
  532. * setup FileUploaderSwitchService
  533. */
  534. Crowi.prototype.setUpFileUploaderSwitchService = async function() {
  535. const FileUploaderSwitchService = require('../service/file-uploader-switch');
  536. this.fileUploaderSwitchService = new FileUploaderSwitchService(this);
  537. // add as a message handler
  538. if (this.s2sMessagingService != null) {
  539. this.s2sMessagingService.addMessageHandler(this.fileUploaderSwitchService);
  540. }
  541. };
  542. /**
  543. * setup AttachmentService
  544. */
  545. Crowi.prototype.setupAttachmentService = async function() {
  546. if (this.attachmentService == null) {
  547. this.attachmentService = new AttachmentService(this);
  548. }
  549. };
  550. /**
  551. * setup RestQiitaAPIService
  552. */
  553. Crowi.prototype.setUpRestQiitaAPI = async function() {
  554. const RestQiitaAPIService = require('../service/rest-qiita-API');
  555. if (this.restQiitaAPIService == null) {
  556. this.restQiitaAPIService = new RestQiitaAPIService(this);
  557. }
  558. };
  559. Crowi.prototype.setupUserGroupService = async function() {
  560. const UserGroupService = require('../service/user-group');
  561. if (this.userGroupService == null) {
  562. this.userGroupService = new UserGroupService(this);
  563. return this.userGroupService.init();
  564. }
  565. };
  566. Crowi.prototype.setUpGrowiBridge = async function() {
  567. const GrowiBridgeService = require('../service/growi-bridge');
  568. if (this.growiBridgeService == null) {
  569. this.growiBridgeService = new GrowiBridgeService(this);
  570. }
  571. };
  572. Crowi.prototype.setupExport = async function() {
  573. const ExportService = require('../service/export');
  574. if (this.exportService == null) {
  575. this.exportService = new ExportService(this);
  576. }
  577. };
  578. Crowi.prototype.setupImport = async function() {
  579. const ImportService = require('../service/import');
  580. if (this.importService == null) {
  581. this.importService = new ImportService(this);
  582. }
  583. };
  584. Crowi.prototype.setupGrowiPluginService = async function() {
  585. const growiPluginService = await import('~/features/growi-plugin/server/services').then(mod => mod.growiPluginService);
  586. // download plugin repositories, if document exists but there is no repository
  587. // TODO: Cannot download unless connected to the Internet at setup.
  588. await growiPluginService.downloadNotExistPluginRepositories();
  589. };
  590. Crowi.prototype.setupPageService = async function() {
  591. if (this.pageService == null) {
  592. this.pageService = new PageService(this);
  593. }
  594. if (this.pageGrantService == null) {
  595. this.pageGrantService = new PageGrantService(this);
  596. }
  597. if (this.pageOperationService == null) {
  598. this.pageOperationService = new PageOperationService(this);
  599. await this.pageOperationService.init();
  600. }
  601. };
  602. Crowi.prototype.setupInAppNotificationService = async function() {
  603. const InAppNotificationService = require('../service/in-app-notification');
  604. if (this.inAppNotificationService == null) {
  605. this.inAppNotificationService = new InAppNotificationService(this);
  606. }
  607. };
  608. Crowi.prototype.setupActivityService = async function() {
  609. const ActivityService = require('../service/activity');
  610. if (this.activityService == null) {
  611. this.activityService = new ActivityService(this);
  612. await this.activityService.createTtlIndex();
  613. }
  614. };
  615. Crowi.prototype.setupCommentService = async function() {
  616. const CommentService = require('../service/comment');
  617. if (this.commentService == null) {
  618. this.commentService = new CommentService(this);
  619. }
  620. };
  621. Crowi.prototype.setupSyncPageStatusService = async function() {
  622. const SyncPageStatusService = require('../service/system-events/sync-page-status');
  623. if (this.syncPageStatusService == null) {
  624. this.syncPageStatusService = new SyncPageStatusService(this, this.s2sMessagingService, this.socketIoService);
  625. // add as a message handler
  626. if (this.s2sMessagingService != null) {
  627. this.s2sMessagingService.addMessageHandler(this.syncPageStatusService);
  628. }
  629. }
  630. };
  631. Crowi.prototype.setupSlackIntegrationService = async function() {
  632. if (this.slackIntegrationService == null) {
  633. this.slackIntegrationService = new SlackIntegrationService(this);
  634. }
  635. // add as a message handler
  636. if (this.s2sMessagingService != null) {
  637. this.s2sMessagingService.addMessageHandler(this.slackIntegrationService);
  638. }
  639. };
  640. Crowi.prototype.setupG2GTransferService = async function() {
  641. if (this.g2gTransferPusherService == null) {
  642. this.g2gTransferPusherService = new G2GTransferPusherService(this);
  643. }
  644. if (this.g2gTransferReceiverService == null) {
  645. this.g2gTransferReceiverService = new G2GTransferReceiverService(this);
  646. }
  647. };
  648. export default Crowi;