Преглед изворни кода

fix: update JSONEditor to default to manual mode for invalid JSON and add error message for invalid data

CaIon пре 7 месеци
родитељ
комит
8df3de9ae5
2 измењених фајлова са 15 додато и 3 уклоњено
  1. 1 2
      relay/channel/gemini/relay-gemini-native.go
  2. 14 1
      web/src/components/common/JSONEditor.js

+ 1 - 2
relay/channel/gemini/relay-gemini-native.go

@@ -108,11 +108,10 @@ func GeminiTextGenerationStreamHandler(c *gin.Context, info *relaycommon.RelayIn
 
 		// 直接发送 GeminiChatResponse 响应
 		err = helper.StringData(c, data)
-		info.SendResponseCount++
 		if err != nil {
 			common.LogError(c, err.Error())
 		}
-
+		info.SendResponseCount++
 		return true
 	})
 

+ 14 - 1
web/src/components/common/JSONEditor.js

@@ -65,7 +65,8 @@ const JSONEditor = ({
         const keyCount = Object.keys(parsed).length;
         return keyCount > 10 ? 'manual' : 'visual';
       } catch (error) {
-        return 'visual';
+        // JSON无效时默认显示手动编辑模式
+        return 'manual';
       }
     }
     return 'visual';
@@ -201,6 +202,18 @@ const JSONEditor = ({
 
   // 渲染键值对编辑器
   const renderKeyValueEditor = () => {
+    if (typeof jsonData !== 'object' || jsonData === null) {
+      return (
+        <div className="text-center py-6 px-4">
+          <div className="text-gray-400 mb-2">
+            <IconCode size={32} />
+          </div>
+          <Text type="tertiary" className="text-gray-500 text-sm">
+            {t('无效的JSON数据,请检查格式')}
+          </Text>
+        </div>
+      );
+    }
     const entries = Object.entries(jsonData);
     
     return (