index.js 22 KB

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