(message: any)
| 2 | import {config} from "@/entrypoints/utils/config"; |
| 3 | |
| 4 | async function google(message: any) { |
| 5 | let params: any = { |
| 6 | client: 'gtx', sl: config.from, tl: config.to, dt: 't', strip: 1, nonced: 1, |
| 7 | 'q': encodeURIComponent(message.origin), |
| 8 | }; |
| 9 | let queryString = Object.keys(params).map((key: string) => key + '=' + params[key]).join('&'); |
| 10 | |
| 11 | const resp = await fetch('https://translate.googleapis.com/translate_a/single?' + queryString, { |
| 12 | method: method.GET, |
| 13 | }); |
| 14 | |
| 15 | if (resp.ok) { |
| 16 | let result = await resp.json(); |
| 17 | let sentence = ''; |
| 18 | result[0].forEach((e: any) => sentence += e[0]); |
| 19 | return sentence; |
| 20 | } else { |
| 21 | console.log(resp); |
| 22 | throw new Error(`翻译失败: ${resp.status} ${resp.statusText} body: ${await resp.text()}`); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | export default google; |
nothing calls this directly
no outgoing calls
no test coverage detected