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