fix: update JSONEditor to default to manual mode for invalid JSON and add error message for invalid data
This commit is contained in:
@@ -108,11 +108,10 @@ func GeminiTextGenerationStreamHandler(c *gin.Context, info *relaycommon.RelayIn
|
|||||||
|
|
||||||
// 直接发送 GeminiChatResponse 响应
|
// 直接发送 GeminiChatResponse 响应
|
||||||
err = helper.StringData(c, data)
|
err = helper.StringData(c, data)
|
||||||
info.SendResponseCount++
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogError(c, err.Error())
|
common.LogError(c, err.Error())
|
||||||
}
|
}
|
||||||
|
info.SendResponseCount++
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ const JSONEditor = ({
|
|||||||
const keyCount = Object.keys(parsed).length;
|
const keyCount = Object.keys(parsed).length;
|
||||||
return keyCount > 10 ? 'manual' : 'visual';
|
return keyCount > 10 ? 'manual' : 'visual';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return 'visual';
|
// JSON无效时默认显示手动编辑模式
|
||||||
|
return 'manual';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 'visual';
|
return 'visual';
|
||||||
@@ -201,6 +202,18 @@ const JSONEditor = ({
|
|||||||
|
|
||||||
// 渲染键值对编辑器
|
// 渲染键值对编辑器
|
||||||
const renderKeyValueEditor = () => {
|
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);
|
const entries = Object.entries(jsonData);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user