From f7fc9560d5dd98c28a1caa0377a5060c226bef3e Mon Sep 17 00:00:00 2001 From: Gabe Date: Thu, 23 Oct 2025 14:33:12 +0800 Subject: [PATCH] fix: update custom api --- custom-api_v2.md | 36 ++++++++++++++++++++++++++++++++++++ src/apis/trans.js | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/custom-api_v2.md b/custom-api_v2.md index c59aa36..34789af 100644 --- a/custom-api_v2.md +++ b/custom-api_v2.md @@ -1,5 +1,41 @@ # 自定义接口示例 +## 默认接口规范 + +如果接口的请求数据和返回数据符合以下规范, +则无需填写 `Request Hook` 或 `Response Hook`。 + +Request body + +```json +{ + "texts": ["hello"], // 需要翻译的文本列表 + "from":"auto", // 原文语言 + "to": "zh-CN" // 目标语言 +} +``` + +Response + +```json +[ + { + "text": "你好", // 译文 + "src": "zh-CN" // 原文语言 + } +] + +// v2.0.4版后亦支持以下返回格式 +{ + "translations": [ // 译文列表 + { + "text": "你好", // 译文 + "src": "zh-CN" // 原文语言 + } + ] +} +``` + ## 谷歌翻译接口 > 此接口不支持聚合 diff --git a/src/apis/trans.js b/src/apis/trans.js index 1f30d62..cbb6297 100644 --- a/src/apis/trans.js +++ b/src/apis/trans.js @@ -847,7 +847,7 @@ export const parseTransRes = async ( } return parseAIRes(modelMsg?.content); case OPT_TRANS_CUSTOMIZE: - return res?.map((item) => [item.text, item.src]); + return (res?.translations ?? res)?.map((item) => [item.text, item.src]); default: }