| import axios from 'axios';
|
|
|
| const API_BASE = '/api';
|
|
|
| const api = axios.create({
|
| baseURL: API_BASE,
|
| headers: { 'Content-Type': 'application/json' },
|
| });
|
|
|
|
|
| api.interceptors.request.use((config) => {
|
| const token = localStorage.getItem('director_token');
|
| if (token && config.headers) {
|
| config.headers.Authorization = `Bearer ${token}`;
|
| }
|
| return config;
|
| });
|
|
|
|
|
| api.interceptors.response.use(
|
| (response) => response,
|
| (error) => {
|
| if (error.response?.status === 401) {
|
| localStorage.removeItem('director_token');
|
| localStorage.removeItem('director_user');
|
| window.location.href = '/login';
|
| }
|
| return Promise.reject(error);
|
| }
|
| );
|
|
|
|
|
| export const authAPI = {
|
| register: (email: string, password: string) =>
|
| api.post('/auth/register', { email, password }),
|
| login: (email: string, password: string) =>
|
| api.post('/auth/login', { email, password }),
|
| };
|
|
|
|
|
| export const projectsAPI = {
|
| list: () => api.get('/projects'),
|
| get: (id: string) => api.get(`/projects/${id}`),
|
| create: (data: { name: string; defaultPlatform: string; defaultFormat: string }) =>
|
| api.post('/projects', data),
|
| delete: (id: string) => api.delete(`/projects/${id}`),
|
| };
|
|
|
|
|
| export const videosAPI = {
|
| create: (projectId: string, data: any) =>
|
| api.post(`/videos/${projectId}`, data),
|
| get: (id: string) => api.get(`/videos/${id}`),
|
| generate: (id: string) => api.post(`/videos/${id}/generate`),
|
| status: (id: string) => api.get(`/videos/${id}/status`),
|
| export: (id: string, data: { formats: string[]; quality: string }) =>
|
| api.post(`/videos/${id}/export`, data),
|
| };
|
|
|
|
|
| export const presetsAPI = {
|
| list: () => api.get('/presets'),
|
| create: (data: any) => api.post('/presets', data),
|
| update: (id: string, data: any) => api.put(`/presets/${id}`, data),
|
| delete: (id: string) => api.delete(`/presets/${id}`),
|
| };
|
|
|
|
|
| export const assetsAPI = {
|
| upload: (files: FileList | File[]) => {
|
| const formData = new FormData();
|
| Array.from(files).forEach((file) => formData.append('files', file));
|
| return api.post('/assets/upload', formData, {
|
| headers: { 'Content-Type': 'multipart/form-data' },
|
| });
|
| },
|
| };
|
|
|
| export default api;
|
|
|