|
@@ -1,26 +1,39 @@
|
|
|
|
|
+import express, { Request, Router } from 'express';
|
|
|
|
|
+
|
|
|
import { SupportedAction } from '~/interfaces/activity';
|
|
import { SupportedAction } from '~/interfaces/activity';
|
|
|
|
|
+import ErrorV3 from '~/server/models/vo/error-apiv3';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
-import { InstallerService, FailedToCreateAdminUserError } from '../service/installer';
|
|
|
|
|
|
|
+import Crowi from '../../crowi';
|
|
|
|
|
+import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
|
|
|
|
|
+import { registerValidation, registerRules } from '../../middlewares/register-form-validator';
|
|
|
|
|
+import { InstallerService, FailedToCreateAdminUserError } from '../../service/installer';
|
|
|
|
|
|
|
|
-const logger = loggerFactory('growi:routes:installer');
|
|
|
|
|
|
|
+import { ApiV3Response } from './interfaces/apiv3-response';
|
|
|
|
|
|
|
|
-module.exports = function(crowi) {
|
|
|
|
|
|
|
|
|
|
- const actions = {};
|
|
|
|
|
|
|
+const logger = loggerFactory('growi:routes:apiv3:installer');
|
|
|
|
|
|
|
|
- const activityEvent = crowi.event('activity');
|
|
|
|
|
|
|
|
|
|
- actions.index = function(req, res) {
|
|
|
|
|
- return res.render('installer');
|
|
|
|
|
- };
|
|
|
|
|
|
|
+type FormRequest = Request & { form: any };
|
|
|
|
|
|
|
|
- actions.install = async function(req, res, next) {
|
|
|
|
|
- const registerForm = req.body.registerForm || {};
|
|
|
|
|
|
|
+module.exports = (crowi: Crowi): Router => {
|
|
|
|
|
+ const adminRequired = require('../../middlewares/admin-required')(crowi);
|
|
|
|
|
+ const accessTokenParser = require('../../middlewares/access-token-parser')(crowi);
|
|
|
|
|
+ const loginRequiredStrictly = require('../../middlewares/login-required')(crowi);
|
|
|
|
|
+ const applicationNotInstalled = require('../../middlewares/application-not-installed')(crowi);
|
|
|
|
|
|
|
|
- if (!req.form.isValid) {
|
|
|
|
|
- return res.render('installer');
|
|
|
|
|
|
|
+ const activityEvent = crowi.event('activity');
|
|
|
|
|
+
|
|
|
|
|
+ const router = express.Router();
|
|
|
|
|
+
|
|
|
|
|
+ // eslint-disable-next-line max-len
|
|
|
|
|
+ router.post('/', applicationNotInstalled, accessTokenParser, loginRequiredStrictly, adminRequired, registerRules, registerValidation, apiV3FormValidator, async(req: FormRequest, res: ApiV3Response) => {
|
|
|
|
|
+ const appService = crowi.appService;
|
|
|
|
|
+ if (appService == null) {
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3('GROWI cannot be installed due to an internal error', 'app_service_not_setup'), 500);
|
|
|
}
|
|
}
|
|
|
|
|
+ const registerForm = req.body.registerForm || {};
|
|
|
|
|
|
|
|
const name = registerForm.name;
|
|
const name = registerForm.name;
|
|
|
const username = registerForm.username;
|
|
const username = registerForm.username;
|
|
@@ -46,8 +59,7 @@ module.exports = function(crowi) {
|
|
|
return res.render('installer');
|
|
return res.render('installer');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const appService = crowi.appService;
|
|
|
|
|
- appService.setupAfterInstall();
|
|
|
|
|
|
|
+ await appService.setupAfterInstall();
|
|
|
|
|
|
|
|
// login with passport
|
|
// login with passport
|
|
|
req.logIn(adminUser, (err) => {
|
|
req.logIn(adminUser, (err) => {
|
|
@@ -64,7 +76,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
return res.redirect('/');
|
|
return res.redirect('/');
|
|
|
});
|
|
});
|
|
|
- };
|
|
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- return actions;
|
|
|
|
|
|
|
+ return router;
|
|
|
};
|
|
};
|