//native
type Deepl = {
apiKey: string;
baseUrl: string;
};
/**
* Download Translated Document
* Once the status of the document translation process is `done`, the result can be downloaded.
For privacy reasons the translated document is automatically removed from the server once it was downloaded and cannot be downloaded again.
*/
export async function main(
auth: Deepl,
document_id: string,
body: { document_key: string },
) {
const url = new URL(
`${auth.baseUrl}/v2/document/${document_id}/result`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "DeepL-Auth-Key " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago