initial commit
This commit is contained in:
123
web/src/utils/api.js
Normal file
123
web/src/utils/api.js
Normal file
@@ -0,0 +1,123 @@
|
||||
const API_BASE = '/api';
|
||||
|
||||
export const api = {
|
||||
async get(endpoint) {
|
||||
const response = await fetch(`${API_BASE}${endpoint}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`API error: ${response.statusText}`);
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
async post(endpoint, data) {
|
||||
const response = await fetch(`${API_BASE}${endpoint}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`API error: ${response.statusText}`);
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
async delete(endpoint) {
|
||||
const response = await fetch(`${API_BASE}${endpoint}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`API error: ${response.statusText}`);
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
async uploadFile(endpoint, file) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const response = await fetch(`${API_BASE}${endpoint}`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`API error: ${response.statusText}`);
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
};
|
||||
|
||||
export const auth = {
|
||||
async getMe() {
|
||||
return api.get('/auth/me');
|
||||
},
|
||||
|
||||
async logout() {
|
||||
return api.post('/auth/logout');
|
||||
},
|
||||
};
|
||||
|
||||
export const jobs = {
|
||||
async list() {
|
||||
return api.get('/jobs');
|
||||
},
|
||||
|
||||
async get(id) {
|
||||
return api.get(`/jobs/${id}`);
|
||||
},
|
||||
|
||||
async create(jobData) {
|
||||
return api.post('/jobs', jobData);
|
||||
},
|
||||
|
||||
async cancel(id) {
|
||||
return api.delete(`/jobs/${id}`);
|
||||
},
|
||||
|
||||
async uploadFile(jobId, file) {
|
||||
return api.uploadFile(`/jobs/${jobId}/upload`, file);
|
||||
},
|
||||
|
||||
async getFiles(jobId) {
|
||||
return api.get(`/jobs/${jobId}/files`);
|
||||
},
|
||||
|
||||
async downloadFile(jobId, fileId) {
|
||||
return `${API_BASE}/jobs/${jobId}/files/${fileId}/download`;
|
||||
},
|
||||
|
||||
async getVideoUrl(jobId) {
|
||||
return `${API_BASE}/jobs/${jobId}/video`;
|
||||
},
|
||||
};
|
||||
|
||||
export const runners = {
|
||||
async list() {
|
||||
return api.get('/runners');
|
||||
},
|
||||
};
|
||||
|
||||
export const admin = {
|
||||
async generateToken(expiresInHours) {
|
||||
return api.post('/admin/runners/tokens', { expires_in_hours: expiresInHours });
|
||||
},
|
||||
|
||||
async listTokens() {
|
||||
return api.get('/admin/runners/tokens');
|
||||
},
|
||||
|
||||
async revokeToken(tokenId) {
|
||||
return api.delete(`/admin/runners/tokens/${tokenId}`);
|
||||
},
|
||||
|
||||
async listRunners() {
|
||||
return api.get('/admin/runners');
|
||||
},
|
||||
|
||||
async verifyRunner(runnerId) {
|
||||
return api.post(`/admin/runners/${runnerId}/verify`);
|
||||
},
|
||||
|
||||
async deleteRunner(runnerId) {
|
||||
return api.delete(`/admin/runners/${runnerId}`);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user