feat: add baidu suggest

This commit is contained in:
Gabe Yuan
2024-03-19 11:48:30 +08:00
parent bc4b4a2171
commit fbc70e43e3
4 changed files with 54 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ import {
URL_CACHE_TRAN,
KV_SALT_SYNC,
URL_BAIDU_LANGDETECT,
URL_BAIDU_SUGGEST,
OPT_LANGS_BAIDU,
URL_TENCENT_TRANSMART,
OPT_LANGS_TENCENT,
@@ -70,6 +71,30 @@ export const apiBaiduLangdetect = async (text) => {
return "";
};
/**
* 百度翻译建议
* @param {*} text
* @returns
*/
export const apiBaiduSuggest = async (text) => {
const res = await fetchPolyfill(URL_BAIDU_SUGGEST, {
headers: {
"Content-type": "application/json",
},
method: "POST",
body: JSON.stringify({
kw: text,
}),
useCache: true,
});
if (res.errno === 0) {
return res.data;
}
return [];
};
/**
* 腾讯语言识别
* @param {*} text