Edits history of script submission #12107 for ' Create a Glossary (deepl)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Deepl = {
      apiKey: string;
      baseUrl: string;
    };
    /**
     * Create a Glossary
     *
     */
    export async function main(
      auth: Deepl,
      body: {
        name: string;
        source_lang:
          | "da"
          | "de"
          | "en"
          | "es"
          | "fr"
          | "it"
          | "ja"
          | "ko"
          | "nb"
          | "nl"
          | "pl"
          | "pt"
          | "ro"
          | "ru"
          | "sv"
          | "zh";
        target_lang:
          | "da"
          | "de"
          | "en"
          | "es"
          | "fr"
          | "it"
          | "ja"
          | "ko"
          | "nb"
          | "nl"
          | "pl"
          | "pt"
          | "ro"
          | "ru"
          | "sv"
          | "zh";
        entries: string;
        entries_format: "tsv" | "csv";
      },
    ) {
      const url = new URL(`${auth.baseUrl}/v2/glossaries`);
    
      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.json();
    }
    

    Submitted by hugo697 428 days ago