fix api client

This commit is contained in:
grngxd 2025-06-08 20:45:35 +01:00
parent 5a54cdefb3
commit c1726f5a39

View file

@ -1,31 +1,22 @@
import ky from 'ky'; import ky from 'ky';
import { StereoFile } from './types'; import { StereoFile } from './types';
export const apiClient = ky.create({ export const client = ky.create({
prefixUrl: '/api', prefixUrl: '/api',
hooks: { credentials: 'include'
beforeRequest: [
request => {
const token = localStorage.getItem('token');
if (token) {
request.headers.set('Authorization', `Bearer ${token}`);
}
}
]
}
}); });
// TODO: make wrapper for apiclient fr // TODO: make wrapper for apiclient fr
export const api = { export const api = {
file: async (file_id: string) => await apiClient.get(file_id), file: async (file_id: string) => await client.get(file_id),
list: async () => await apiClient.get('list').json<StereoFile[]>(), list: async () => await client.get('list').json<StereoFile[]>(),
upload: async (file: File) => { upload: async (file: File) => {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
return await apiClient.post('upload', { body: formData }); return await client.post('upload', { body: formData });
}, },
delete: async (file_id: string) => { delete: async (file_id: string) => {
console.log("Deleting file with ID:", file_id); console.log("Deleting file with ID:", file_id);
return await apiClient.delete(`delete`, { return await client.delete(`delete`, {
json: { file_id } json: { file_id }
}).json(); }).json();
}, },