fix delete route

This commit is contained in:
grngxd 2025-06-15 10:13:30 +01:00
parent 7926efa222
commit 2975e6088d
2 changed files with 6 additions and 10 deletions

View file

@ -19,9 +19,9 @@ const formatSize = (bytes: number) => {
export default component$(({ file }: FileProps) => { export default component$(({ file }: FileProps) => {
const files = useNanostore$<StereoFile[]>(dashboardFiles); const files = useNanostore$<StereoFile[]>(dashboardFiles);
const deleteFile = $(async (uid: string, name: string) => { const deleteFile = $(async (id: string) => {
if (!confirm("Are you sure you want to delete this file?")) return; if (!confirm("Are you sure you want to delete this file?")) return;
console.log(await api.delete(uid, name)); await api.delete(id);
files.value = await api.list(); files.value = await api.list();
}); });
@ -93,7 +93,7 @@ export default component$(({ file }: FileProps) => {
<button <button
class="bg-red-600/50 backdrop-blur-lg hover:bg-red-600/75 transition-all duration-200 text-white p-2 rounded-lg active:scale-95" class="bg-red-600/50 backdrop-blur-lg hover:bg-red-600/75 transition-all duration-200 text-white p-2 rounded-lg active:scale-95"
onClick$={async () => await deleteFile(file.Owner, file.Name)} onClick$={async () => await deleteFile(file.ID)}
> >
<SolarTrashBin2Bold class="w-6 h-6"/> <SolarTrashBin2Bold class="w-6 h-6"/>
</button> </button>

View file

@ -5,18 +5,14 @@ export const client = ky.create({
prefixUrl: '/api', prefixUrl: '/api',
credentials: 'include' credentials: 'include'
}); });
// TODO: make wrapper for apiclient fr
export const api = { export const api = {
file: async (uid: string) => await client.get<Blob>(uid), file: async (uid: string) => await client.get<Blob>(uid),
list: async () => { list: async () => await client.get('list').json<StereoFile[]>(),
return 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 client.post('upload', { body: formData }); return await client.post('upload', { body: formData });
}, },
delete: async (uid: string, file: string) => { delete: async (uid: string) => await client.delete(uid).json(),
return await client.delete(uid).json();
},
} }