index.js 23 KB

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