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: }