shironegi39 пре 1 година
родитељ
комит
22bcbab7f1

+ 0 - 8
apps/app/src/server/crowi/express-init.js

@@ -134,12 +134,4 @@ module.exports = function(crowi, app) {
   app.use(registerSafeRedirect);
   app.use(injectCurrentuserToLocalvars);
   app.use(autoReconnectToS2sMsgServer);
-
-  // TODO: Remove this workaround implementation when i18n works correctly.
-  //       For now, req.t returns string given to req.t(string)
-  app.use((req, res, next) => {
-    req.t = str => (typeof str === 'string' ? str : '');
-
-    next();
-  });
 };

+ 20 - 4
apps/app/src/server/routes/apiv3/app-settings.js

@@ -190,10 +190,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(),