index.js 22 KB

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