index.js 23 KB

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