# All files / src/api external.ts

0% Statements 0/9
0% Branches 0/4
0% Functions 0/4
0% Lines 0/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

     import { api } from './client';
    import type { ExternalTranslateRequest, ExternalTranslateResponse, ExternalBatchTranslateRequest } from './types';

    export const externalApi = {
      translate: (data: ExternalTranslateRequest) =>
        api.post<ExternalTranslateResponse>('/v1/external/translate', data),
      batchTranslate: (data: ExternalBatchTranslateRequest) =>
        api.post<ExternalTranslateResponse[]>('/v1/external/batch', data),
      getModels: () =>
        api.get<Array<{ name: string; engine: string; available: boolean }>>('/v1/external/models'),
      downloadTask: async (taskId: string) => {
        const token = localStorage.getItem('authToken');
        const res = await fetch(`/v1/external/task/${taskId}/download`, {
          headers: token ? { Authorization: `Bearer ${token}` } : {},
        });
        if (!res.ok) throw new Error('Download failed');
        return res.blob();
      },
    };