index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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 { modelsDependsOnCrowi } from '../models';
  18. import { aclService as aclServiceSingletonInstance } from '../service/acl';
  19. import AppService from '../service/app';
  20. import AttachmentService from '../service/attachment';
  21. import { configManager as configManagerSingletonInstance } from '../service/config-manager';
  22. import { FileUploader, getUploader } from '../service/file-uploader'; // eslint-disable-line no-unused-vars
  23. import { G2GTransferPusherService, G2GTransferReceiverService } from '../service/g2g-transfer';
  24. import { InstallerService } from '../service/installer';
  25. import PageService from '../service/page';
  26. import PageGrantService from '../service/page-grant';
  27. import PageOperationService from '../service/page-operation';
  28. import SearchService from '../service/search';
  29. import { SlackIntegrationService } from '../service/slack-integration';
  30. import { UserNotificationService } from '../service/user-notification';
  31. import { getMongoUri, mongoOptions } from '../util/mongoose-utils';
  32. const logger = loggerFactory('growi:crowi');
  33. const httpErrorHandler = require('../middlewares/http-error-handler');
  34. const sep = path.sep;
  35. class Crowi {
  36. /** @type {AppService} */
  37. appService;
  38. /** @type {FileUploader} */
  39. fileUploadService;
  40. constructor() {
  41. this.version = pkg.version;
  42. this.runtimeVersions = undefined; // initialized by scanRuntimeVersions()
  43. this.publicDir = path.join(projectRoot, 'public') + sep;
  44. this.resourceDir = path.join(projectRoot, 'resource') + sep;
  45. this.localeDir = path.join(this.resourceDir, 'locales') + sep;
  46. this.viewsDir = path.resolve(__dirname, '../views') + sep;
  47. this.tmpDir = path.join(projectRoot, 'tmp') + sep;
  48. this.cacheDir = path.join(this.tmpDir, 'cache');
  49. this.express = null;
  50. this.config = {};
  51. this.configManager = null;
  52. this.s2sMessagingService = null;
  53. this.g2gTransferPusherService = null;
  54. this.g2gTransferReceiverService = null;
  55. this.mailService = null;
  56. this.passportService = null;
  57. this.globalNotificationService = null;
  58. this.userNotificationService = null;
  59. this.xssService = null;
  60. this.aclService = null;
  61. this.appService = null;
  62. this.fileUploadService = null;
  63. this.restQiitaAPIService = null;
  64. this.growiBridgeService = null;
  65. this.exportService = null;
  66. this.importService = null;
  67. this.pluginService = null;
  68. this.searchService = null;
  69. this.socketIoService = null;
  70. this.pageService = null;
  71. this.syncPageStatusService = null;
  72. this.cdnResourcesService = new CdnResourcesService();
  73. this.slackIntegrationService = null;
  74. this.inAppNotificationService = null;
  75. this.activityService = null;
  76. this.commentService = null;
  77. this.xss = new Xss();
  78. this.questionnaireService = null;
  79. this.questionnaireCronService = null;
  80. this.tokens = null;
  81. this.models = {};
  82. this.env = process.env;
  83. this.node_env = this.env.NODE_ENV || 'development';
  84. this.port = this.env.PORT || 3000;
  85. this.events = {
  86. user: new UserEvent(this),
  87. page: new (require('../events/page'))(this),
  88. activity: new (require('../events/activity'))(this),
  89. bookmark: new (require('../events/bookmark'))(this),
  90. comment: new (require('../events/comment'))(this),
  91. tag: new (require('../events/tag'))(this),
  92. admin: new (require('../events/admin'))(this),
  93. };
  94. }
  95. }
  96. Crowi.prototype.init = async function() {
  97. await this.setupDatabase();
  98. await this.setupModels();
  99. await this.setupConfigManager();
  100. await this.setupSessionConfig();
  101. this.setupCron();
  102. // setup messaging services
  103. await this.setupS2sMessagingService();
  104. await this.setupSocketIoService();
  105. // customizeService depends on AppService and XssService
  106. // passportService depends on appService
  107. // export and import depends on setUpGrowiBridge
  108. await Promise.all([
  109. this.setUpApp(),
  110. this.setUpXss(),
  111. this.setUpGrowiBridge(),
  112. ]);
  113. await Promise.all([
  114. this.scanRuntimeVersions(),
  115. this.setupPassport(),
  116. this.setupSearcher(),
  117. this.setupMailer(),
  118. this.setupSlackIntegrationService(),
  119. this.setupG2GTransferService(),
  120. this.setUpFileUpload(),
  121. this.setUpFileUploaderSwitchService(),
  122. this.setupAttachmentService(),
  123. this.setUpAcl(),
  124. this.setUpRestQiitaAPI(),
  125. this.setupUserGroupService(),
  126. this.setupExport(),
  127. this.setupImport(),
  128. this.setupGrowiPluginService(),
  129. this.setupPageService(),
  130. this.setupInAppNotificationService(),
  131. this.setupActivityService(),
  132. this.setupCommentService(),
  133. this.setupSyncPageStatusService(),
  134. this.setupQuestionnaireService(),
  135. this.setUpCustomize(), // depends on pluginService
  136. ]);
  137. // globalNotification depends on slack and mailer
  138. await Promise.all([
  139. this.setUpGlobalNotification(),
  140. this.setUpUserNotification(),
  141. ]);
  142. await this.autoInstall();
  143. };
  144. /**
  145. * Execute functions that should be run after the express server is ready.
  146. */
  147. Crowi.prototype.asyncAfterExpressServerReady = async function() {
  148. if (this.pageOperationService != null) {
  149. await this.pageOperationService.afterExpressServerReady();
  150. }
  151. };
  152. Crowi.prototype.isPageId = function(pageId) {
  153. if (!pageId) {
  154. return false;
  155. }
  156. if (typeof pageId === 'string' && pageId.match(/^[\da-f]{24}$/)) {
  157. return true;
  158. }
  159. return false;
  160. };
  161. Crowi.prototype.setConfig = function(config) {
  162. this.config = config;
  163. };
  164. Crowi.prototype.getConfig = function() {
  165. return this.config;
  166. };
  167. Crowi.prototype.getEnv = function() {
  168. return this.env;
  169. };
  170. // getter/setter of model instance
  171. //
  172. Crowi.prototype.model = function(name, model) {
  173. if (model != null) {
  174. this.models[name] = model;
  175. }
  176. return this.models[name];
  177. };
  178. // getter/setter of event instance
  179. Crowi.prototype.event = function(name, event) {
  180. if (event) {
  181. this.events[name] = event;
  182. }
  183. return this.events[name];
  184. };
  185. Crowi.prototype.setupDatabase = function() {
  186. mongoose.Promise = global.Promise;
  187. // mongoUri = mongodb://user:password@host/dbname
  188. const mongoUri = getMongoUri();
  189. return mongoose.connect(mongoUri, mongoOptions);
  190. };
  191. Crowi.prototype.setupSessionConfig = async function() {
  192. const session = require('express-session');
  193. const sessionMaxAge = this.configManager.getConfig('crowi', 'security:sessionMaxAge') || 2592000000; // default: 30days
  194. const redisUrl = this.env.REDISTOGO_URL || this.env.REDIS_URI || this.env.REDIS_URL || null;
  195. const uid = require('uid-safe').sync;
  196. // generate pre-defined uid for healthcheck
  197. const healthcheckUid = uid(24);
  198. const sessionConfig = {
  199. rolling: true,
  200. secret: this.env.SECRET_TOKEN || 'this is default session secret',
  201. resave: false,
  202. saveUninitialized: true,
  203. cookie: {
  204. maxAge: sessionMaxAge,
  205. },
  206. genid(req) {
  207. // return pre-defined uid when healthcheck
  208. if (req.path === '/_api/v3/healthcheck') {
  209. return healthcheckUid;
  210. }
  211. return uid(24);
  212. },
  213. };
  214. if (this.env.SESSION_NAME) {
  215. sessionConfig.name = this.env.SESSION_NAME;
  216. }
  217. // use Redis for session store
  218. if (redisUrl) {
  219. const redis = require('redis');
  220. const redisClient = redis.createClient({ url: redisUrl });
  221. const RedisStore = require('connect-redis')(session);
  222. sessionConfig.store = new RedisStore({ client: redisClient });
  223. }
  224. // use MongoDB for session store
  225. else {
  226. const MongoStore = require('connect-mongo');
  227. sessionConfig.store = MongoStore.create({ client: mongoose.connection.getClient() });
  228. }
  229. this.sessionConfig = sessionConfig;
  230. };
  231. Crowi.prototype.setupConfigManager = async function() {
  232. this.configManager = configManagerSingletonInstance;
  233. return this.configManager.loadConfigs();
  234. };
  235. Crowi.prototype.setupS2sMessagingService = async function() {
  236. const s2sMessagingService = require('../service/s2s-messaging')(this);
  237. if (s2sMessagingService != null) {
  238. s2sMessagingService.subscribe();
  239. this.configManager.setS2sMessagingService(s2sMessagingService);
  240. // add as a message handler
  241. s2sMessagingService.addMessageHandler(this.configManager);
  242. this.s2sMessagingService = s2sMessagingService;
  243. }
  244. };
  245. Crowi.prototype.setupSocketIoService = async function() {
  246. const SocketIoService = require('../service/socket-io');
  247. if (this.socketIoService == null) {
  248. this.socketIoService = new SocketIoService(this);
  249. }
  250. };
  251. Crowi.prototype.setupModels = async function() {
  252. Object.keys(modelsDependsOnCrowi).forEach((key) => {
  253. const factory = modelsDependsOnCrowi[key];
  254. if (!(factory instanceof Function)) {
  255. logger.warn(`modelsDependsOnCrowi['${key}'] is not a function. skipped.`);
  256. return;
  257. }
  258. return this.model(key, modelsDependsOnCrowi[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 = getUploader(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;