File size: 2,004 Bytes
6fc3143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const API_BASE_URL = "";

export type InputType = "text" | "url" | "pdf";
export type Category = "tech_system" | "product_startup" | "mathematical";
export type Quality = "low" | "medium" | "high" | "ultra";

export interface JobStatus {
    job_id: string;
    status: "pending" | "generating_code" | "rendering" | "completed" | "failed";
    progress: {
        percentage: number;
        message: string;
    };
    error?: string;
    output_url?: string;
    created_at: string;
}

export const api = {
    async createVideo(
        input_data: string,
        input_type: InputType,
        category: Category,
        quality: Quality = "high"
    ) {
        const response = await fetch(`/api/generate`, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify({
                input_data,
                input_type,
                category,
                quality,
            }),
        });

        if (!response.ok) {
            const error = await response.json();
            throw new Error(error.detail || "Failed to create video job");
        }

        return response.json();
    },

    async getJobStatus(jobId: string): Promise<JobStatus> {
        // Calls /api/jobs/[id]
        const response = await fetch(`${API_BASE_URL}/api/jobs/${jobId}`);

        if (!response.ok) {
            throw new Error("Failed to get job status");
        }

        return response.json();
    },

    getVideoUrl(jobId: string) {
        // Calls /api/videos/[id] (we might need to proxy this too or return direct URL)
        // For demo, we return direct URL. For real, we might need a proxy if it's not public.
        // But usually the backend returns a full URL or we proxy.
        // Let's assume the backend returns a full URL in the status, so this helper might be less used
        // or we point it to the proxy.
        return `${API_BASE_URL}/api/videos/${jobId}`;
    }
};