back
This commit is contained in:
94
frontend/src/services/api.js
Normal file
94
frontend/src/services/api.js
Normal file
@@ -0,0 +1,94 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
withCredentials: false,
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
const unwrap = (promise) => promise.then((r) => r.data);
|
||||
|
||||
// --- Task Management ---
|
||||
export const pollTaskStatus = (statusUrl) => unwrap(api.get(statusUrl));
|
||||
export const stopTask = (taskId) => unwrap(api.post(`/task/${taskId}/stop`));
|
||||
export const downloadFile = async (filename) => {
|
||||
const res = await api.get(`/download/${filename}`, { responseType: 'blob' });
|
||||
const blob = new Blob([res.data], { type: res.headers['content-type'] });
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.setAttribute('download', filename);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
};
|
||||
|
||||
|
||||
// --- Authentication ---
|
||||
export const login = (username, password) =>
|
||||
unwrap(api.post('/login', { username, password }));
|
||||
|
||||
export const register = (username, password) =>
|
||||
unwrap(api.post('/register', { username, password }));
|
||||
|
||||
// --- Admin ---
|
||||
export const getUsers = () => unwrap(api.get('/admin/users')); // For Admin Page
|
||||
export const getAllUsers = () => unwrap(api.get('/users')); // For dropdowns
|
||||
export const createUser = (userData) => unwrap(api.post('/admin/users', userData));
|
||||
export const deleteUser = (userId) => unwrap(api.delete(`/admin/users/${userId}`));
|
||||
export const changeUserPassword = (userId, password) =>
|
||||
unwrap(api.put(`/admin/users/${userId}/password`, { password }));
|
||||
|
||||
// --- Meetings ---
|
||||
export const getMeetings = () => unwrap(api.get('/meetings'));
|
||||
export const createMeeting = (topic, meetingDate) => unwrap(api.post('/meetings', { topic, meeting_date: meetingDate }));
|
||||
export const getMeetingDetails = (meetingId) => unwrap(api.get(`/meetings/${meetingId}`));
|
||||
export const updateMeeting = (meetingId, data) => unwrap(api.put(`/meetings/${meetingId}`, data));
|
||||
export const deleteMeeting = (meetingId) => unwrap(api.delete(`/meetings/${meetingId}`));
|
||||
export const summarizeMeeting = (meetingId) => unwrap(api.post(`/meetings/${meetingId}/summarize`));
|
||||
|
||||
// --- Independent Tools ---
|
||||
const startFileUploadTask = async (endpoint, file, options = {}) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
for (const key in options) {
|
||||
formData.append(key, options[key]);
|
||||
}
|
||||
return unwrap(api.post(endpoint, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
}));
|
||||
};
|
||||
|
||||
export const extractAudio = (file) =>
|
||||
startFileUploadTask('/tools/extract_audio', file);
|
||||
|
||||
export const transcribeAudio = (file) =>
|
||||
startFileUploadTask('/tools/transcribe_audio', file);
|
||||
|
||||
export const translateText = (text, target_language) =>
|
||||
unwrap(api.post('/tools/translate_text', { text, target_language }));
|
||||
|
||||
// --- AI Previews (for Meeting Page) ---
|
||||
export const previewActionItems = (text) =>
|
||||
unwrap(api.post('/action-items/preview', { text }));
|
||||
|
||||
// --- Action Items ---
|
||||
export const getActionItemsForMeeting = (meetingId) => unwrap(api.get(`/meetings/${meetingId}/action_items`));
|
||||
export const createActionItem = (payload) => unwrap(api.post('/action-items', payload));
|
||||
export const batchSaveActionItems = (meetingId, items) => unwrap(api.post(`/meetings/${meetingId}/action-items/batch`, { items }));
|
||||
export const updateActionItem = (itemId, updateData) => unwrap(api.put(`/action_items/${itemId}`, updateData));
|
||||
export const deleteActionItem = (itemId) => unwrap(api.delete(`/action_items/${itemId}`));
|
||||
export const uploadActionItemAttachment = (itemId, file) => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return unwrap(api.post(`/action_items/${itemId}/upload`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
}));
|
||||
};
|
Reference in New Issue
Block a user