Refactor Microsoft translation function arguments
Changed the call to translateWithMicrosoft to pass text, source_lang, and target_lang as separate arguments instead of a single params object. Updated the function implementation to match the new signature and inlined the request body construction.
This commit is contained in:
1 parent
bc8cc07e13
commit
6927a22b13
2 files changed
+10
-8
No files matched your search
+9
-4
@@ -164,10 +164,15 @@ async function handleTranslation(
|
||||
clientIP,
|
||||
});
|
||||
} else if (provider === "microsoft") {
|
||||
result = await translateWithMicrosoft(validatedParams, {
|
||||
env,
|
||||
clientIP,
|
||||
});
|
||||
result = await translateWithMicrosoft(
|
||||
validatedParams.text,
|
||||
validatedParams.source_lang,
|
||||
validatedParams.target_lang,
|
||||
{
|
||||
env,
|
||||
clientIP,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// Use DeepL as default
|
||||
result = await query(validatedParams, {
|
||||
|
||||
@@ -64,9 +64,6 @@ export async function translateWithMicrosoft(
|
||||
const translateUrl =
|
||||
"https://api-edge.cognitive.microsofttranslator.com/translate";
|
||||
|
||||
// Prepare request body
|
||||
const requestBody = [{ Text: text }];
|
||||
|
||||
// Build query parameters
|
||||
const queryParams = new URLSearchParams({
|
||||
"api-version": "3.0",
|
||||
@@ -101,7 +98,7 @@ export async function translateWithMicrosoft(
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.42",
|
||||
},
|
||||
body: JSON.stringify(requestBody),
|
||||
body: JSON.stringify([{ Text: text }]),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in new issue
Block a user