Refactor DeeplX URL handling in translator.ts
This commit is contained in:
@@ -128,9 +128,16 @@ async function translateMain(text:string, arg:{from:string, to:string, host:stri
|
||||
|
||||
}
|
||||
if(db.translatorType === 'deeplX'){
|
||||
// URL이 DeeplX 프로그램 실행시키면 CMD에서는 0.0.0.0:1188라고 뜨는데 https://0.0.0.0:1188/translate 로 호출 보내야함
|
||||
// 유저가 https://0.0.0.0:1188/translate라고 입력하게 할지, 아니면 0.0.0.0:1188만 입력하면 /translate를 자동으로 붙여줄지 결정필요
|
||||
let url = db.deeplXOptions.url;
|
||||
|
||||
if(url.endsWith('/')){
|
||||
url = url.slice(0, -1)
|
||||
}
|
||||
|
||||
if(!url.endsWith('/translate')){
|
||||
url += '/translate'
|
||||
}
|
||||
|
||||
let headers = { "Content-Type": "application/json" }
|
||||
|
||||
const body = {text: text, target_lang: arg.to.toLocaleUpperCase(), source_lang: arg.from.toLocaleUpperCase()}
|
||||
@@ -138,7 +145,6 @@ async function translateMain(text:string, arg:{from:string, to:string, host:stri
|
||||
|
||||
if(db.deeplXOptions.token.trim() !== '') { headers["Authorization"] = "Bearer " + db.deeplXOptions.token}
|
||||
|
||||
console.log(body)
|
||||
const f = await globalFetch(url, { method: "POST", headers: headers, body: body })
|
||||
|
||||
if(!f.ok){ return 'ERR::DeepLX API Error' + (await f.data) }
|
||||
|
||||
Reference in New Issue
Block a user