File size: 1,964 Bytes
a601b1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d35734f
 
a601b1d
d35734f
 
 
a601b1d
d35734f
 
a601b1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
/**
 * API Communication Service
 */

import { APP_CONFIG } from '../core/config.js';

export class APIService {
    constructor(baseURL = APP_CONFIG.API_BASE_URL) {
        this.baseURL = baseURL;
    }
    
    async uploadVideo(file) {
        const formData = new FormData();
        formData.append('file', file);
        
        const response = await fetch(`${this.baseURL}/api/upload`, {
            method: 'POST',
            body: formData
        });
        
        if (!response.ok) {
            const error = await response.json();
            throw new Error(error.detail || 'Upload failed');
        }
        
        return await response.json();
    }
    
    async startAnalysis(sessionId) {
        const response = await fetch(`${this.baseURL}/api/analyze/${sessionId}`, {
            method: 'POST'
        });
        
        if (!response.ok) {
            const error = await response.json();
            throw new Error(error.detail || 'Analysis failed to start');
        }
        
        return await response.json();
    }
    
    // async getTaskStatus(taskId) {
    //     const response = await fetch(`${this.baseURL}/api/task/${taskId}`);
        
    //     if (!response.ok) {
    //         throw new Error('Failed to get task status');
    //     }
        
    //     return await response.json();
    // }
    
    async getResults(sessionId) {
        const response = await fetch(`${this.baseURL}/api/results/${sessionId}`);
        
        if (!response.ok) {
            throw new Error('Failed to get results');
        }
        
        return await response.json();
    }
    
    getDownloadURL(sessionId) {
        return `${this.baseURL}/api/download/${sessionId}`;
    }
    
    async getStorageStats() {
        const response = await fetch(`${this.baseURL}/api/admin/storage`);
        return await response.json();
    }
}

// Global API service instance
export const apiService = new APIService();