index.js 23 KB

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