index.js 23 KB

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