Parcourir la source

feat: add validation for invalid status code entries in channel modal

- Introduced a new function to collect invalid status code entries from the status code mapping.
- Updated the EditChannelModal to display an error message if invalid status codes are detected.
- Enhanced localization files to include new error messages for invalid status codes in multiple languages.
- Removed unused styles from the RiskAcknowledgementModal for cleaner UI.
CaIon il y a 1 semaine
Parent
commit
af2831ce31

+ 0 - 11
web/src/components/common/modals/RiskAcknowledgementModal.jsx

@@ -44,8 +44,6 @@ const RiskMarkdownBlock = React.memo(function RiskMarkdownBlock({
       className='rounded-lg'
       style={{
         border: '1px solid var(--semi-color-warning-light-hover)',
-        background:
-          'linear-gradient(180deg, var(--semi-color-warning-light-default) 0%, var(--semi-color-fill-0) 100%)',
         padding: '12px',
         contentVisibility: 'auto',
       }}
@@ -136,15 +134,6 @@ const RiskAcknowledgementModal = React.memo(function RiskAcknowledgementModal({
       }
     >
       <div className='flex flex-col gap-4'>
-        <div
-          className='rounded-lg'
-          style={{
-            border: '1px solid var(--semi-color-warning-light-hover)',
-            background: 'var(--semi-color-warning-light-default)',
-            padding: isMobile ? '10px 12px' : '12px 14px',
-          }}
-        >
-        </div>
 
         <RiskMarkdownBlock markdownContent={markdownContent} />
 

+ 14 - 1
web/src/components/table/channels/modals/EditChannelModal.jsx

@@ -65,7 +65,10 @@ import StatusCodeRiskGuardModal from './StatusCodeRiskGuardModal';
 import ChannelKeyDisplay from '../../../common/ui/ChannelKeyDisplay';
 import { useSecureVerification } from '../../../../hooks/common/useSecureVerification';
 import { createApiCalls } from '../../../../services/secureVerification';
-import { collectNewDisallowedStatusCodeRedirects } from './statusCodeRiskGuard';
+import {
+  collectInvalidStatusCodeEntries,
+  collectNewDisallowedStatusCodeRedirects,
+} from './statusCodeRiskGuard';
 import {
   IconSave,
   IconClose,
@@ -1377,6 +1380,16 @@ const EditChannelModal = (props) => {
       }
     }
 
+    const invalidStatusCodeEntries = collectInvalidStatusCodeEntries(
+      localInputs.status_code_mapping,
+    );
+    if (invalidStatusCodeEntries.length > 0) {
+      showError(
+        `${t('状态码复写包含无效的状态码')}: ${invalidStatusCodeEntries.join(', ')}`,
+      );
+      return;
+    }
+
     const riskyStatusCodeRedirects = collectNewDisallowedStatusCodeRedirects(
       initialStatusCodeMappingRef.current,
       localInputs.status_code_mapping,

+ 31 - 0
web/src/components/table/channels/modals/statusCodeRiskGuard.js

@@ -44,6 +44,37 @@ function parseStatusCodeMappingTarget(rawValue) {
   return null;
 }
 
+export function collectInvalidStatusCodeEntries(statusCodeMappingStr) {
+  if (
+    typeof statusCodeMappingStr !== 'string' ||
+    statusCodeMappingStr.trim() === ''
+  ) {
+    return [];
+  }
+
+  let parsed;
+  try {
+    parsed = JSON.parse(statusCodeMappingStr);
+  } catch {
+    return [];
+  }
+
+  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
+    return [];
+  }
+
+  const invalid = [];
+  for (const [rawKey, rawValue] of Object.entries(parsed)) {
+    const fromCode = parseStatusCodeKey(rawKey);
+    const toCode = parseStatusCodeMappingTarget(rawValue);
+    if (fromCode === null || toCode === null) {
+      invalid.push(`${rawKey} → ${rawValue}`);
+    }
+  }
+
+  return invalid;
+}
+
 export function collectDisallowedStatusCodeRedirects(statusCodeMappingStr) {
   if (
     typeof statusCodeMappingStr !== 'string' ||

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 0
web/src/i18n/locales/en.json


+ 1 - 0
web/src/i18n/locales/fr.json

@@ -1650,6 +1650,7 @@
     "版权所有": "Tous droits réservés",
     "状态": "Statut",
     "状态码复写": "Remplacement du code d'état",
+    "状态码复写包含无效的状态码": "Le remplacement du code d'état contient des codes d'état invalides",
     "状态筛选": "Filtre d'état",
     "状态页面Slug": "Slug de la page d'état",
     "环境变量": "Environment Variables",

+ 1 - 0
web/src/i18n/locales/ja.json

@@ -1635,6 +1635,7 @@
     "版权所有": "All rights reserved",
     "状态": "ステータス",
     "状态码复写": "ステータスコードの上書き",
+    "状态码复写包含无效的状态码": "ステータスコードの上書きに無効なステータスコードが含まれています",
     "状态筛选": "ステータスフィルター",
     "状态页面Slug": "ステータスページスラッグ",
     "环境变量": "Environment Variables",

+ 1 - 0
web/src/i18n/locales/ru.json

@@ -1661,6 +1661,7 @@
     "版权所有": "Все права защищены",
     "状态": "Статус",
     "状态码复写": "Перезапись кода состояния",
+    "状态码复写包含无效的状态码": "Перезапись кода состояния содержит недопустимые коды состояния",
     "状态筛选": "Фильтр по статусу",
     "状态页面Slug": "Slug страницы статуса",
     "环境变量": "Environment Variables",

+ 1 - 0
web/src/i18n/locales/vi.json

@@ -1782,6 +1782,7 @@
     "状态": "Trạng thái",
     "状态更新时间": "Thời gian cập nhật trạng thái",
     "状态码复写": "Ghi đè mã trạng thái",
+    "状态码复写包含无效的状态码": "Ghi đè mã trạng thái chứa mã trạng thái không hợp lệ",
     "状态筛选": "Lọc trạng thái",
     "状态页面Slug": "Slug trang trạng thái",
     "环境变量": "Environment Variables",

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 0
web/src/i18n/locales/zh-CN.json


Fichier diff supprimé car celui-ci est trop grand
+ 1 - 0
web/src/i18n/locales/zh-TW.json


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff