feat: deepl translate

This commit is contained in:
2023-11-02 06:11:00 +09:00
parent f994f8722d
commit 83a085a343
4 changed files with 30 additions and 24 deletions

View File

@ -55,6 +55,18 @@ export interface PushNotifications {
scope: string;
}
export interface TranslationRequest {
text: Array<string>;
target_lang: string;
}
export interface TranslationResponse {
translations: Array<{
detected_source_language: string;
text: string;
}>;
}
export default class SnortApi {
#url: string;
#publisher?: EventPublisher;
@ -104,6 +116,10 @@ export default class SnortApi {
return this.#getJsonAuthd<void>("api/v1/notifications/register", "POST", sub);
}
translate(tx: TranslationRequest) {
return this.#getJson<TranslationResponse>("api/v1/translate", "POST", tx);
}
async #getJsonAuthd<T>(
path: string,
method?: "GET" | string,