|
|
@@ -4,6 +4,7 @@ import { body } from 'express-validator';
|
|
|
import { i18n } from '^/config/next-i18next.config';
|
|
|
|
|
|
import { SupportedAction } from '~/interfaces/activity';
|
|
|
+import { getTranslation } from '~/server/service/i18next';
|
|
|
import { accessTokenParser } from '~/server/middlewares/access-token-parser';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
@@ -182,10 +183,26 @@ module.exports = (crowi) => {
|
|
|
body('gcsBucket').trim(),
|
|
|
body('gcsUploadNamespace').trim(),
|
|
|
body('gcsReferenceFileWithRelayMode').if(value => value != null).isBoolean(),
|
|
|
- body('s3Region').trim().if(value => value !== '').matches(/^[a-z]+-[a-z]+-\d+$/)
|
|
|
- .withMessage((value, { req }) => req.t('validation.aws_region')),
|
|
|
- body('s3CustomEndpoint').trim().if(value => value !== '').matches(/^(https?:\/\/[^/]+|)$/)
|
|
|
- .withMessage((value, { req }) => req.t('validation.aws_custom_endpoint')),
|
|
|
+ body('s3Region')
|
|
|
+ .trim()
|
|
|
+ .if(value => value !== '')
|
|
|
+ .custom(async(value) => {
|
|
|
+ const { t } = await getTranslation();
|
|
|
+ if (!/^[a-z]+-[a-z]+-\d+$/.test(value)) {
|
|
|
+ throw new Error(t('validation.aws_region'));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }),
|
|
|
+ body('s3CustomEndpoint')
|
|
|
+ .trim()
|
|
|
+ .if(value => value !== '')
|
|
|
+ .custom(async(value) => {
|
|
|
+ const { t } = await getTranslation();
|
|
|
+ if (!/^(https?:\/\/[^/]+|)$/.test(value)) {
|
|
|
+ throw new Error(t('validation.aws_custom_endpoint'));
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }),
|
|
|
body('s3Bucket').trim(),
|
|
|
body('s3AccessKeyId').trim().if(value => value !== '').matches(/^[\da-zA-Z]+$/),
|
|
|
body('s3SecretAccessKey').trim(),
|
|
|
@@ -552,6 +569,8 @@ module.exports = (crowi) => {
|
|
|
* description: Succeeded to send test mail for smtp
|
|
|
*/
|
|
|
router.post('/smtp-test', loginRequiredStrictly, adminRequired, addActivity, async(req, res) => {
|
|
|
+ const { t } = await getTranslation();
|
|
|
+
|
|
|
try {
|
|
|
await sendTestEmail(req.user.email);
|
|
|
const parameters = { action: SupportedAction.ACTION_ADMIN_MAIL_TEST_SUBMIT };
|
|
|
@@ -559,7 +578,7 @@ module.exports = (crowi) => {
|
|
|
return res.apiv3({});
|
|
|
}
|
|
|
catch (err) {
|
|
|
- const msg = req.t('validation.failed_to_send_a_test_email');
|
|
|
+ const msg = t('validation.failed_to_send_a_test_email');
|
|
|
logger.error('Error', err);
|
|
|
logger.debug('Error validate mail setting: ', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'send-email-with-smtp-failed'));
|