diff --git a/src/components/Controlbar.tsx b/src/components/Controlbar.tsx index fc22766..1e7911d 100644 --- a/src/components/Controlbar.tsx +++ b/src/components/Controlbar.tsx @@ -32,7 +32,7 @@ export default component$(() => { } }) return ( -
+
{ const formatSize = (bytes: number) => { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; - return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; + if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; + return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`; } export default component$(({ file }: FileProps) => { + const files = useNanostore$(DashboardFiles); + + const deleteFile = $(async (id: string) => { + if (!confirm("Are you sure you want to delete this file?")) return; + console.log(await api.delete(id)) + files.value = await api.list(); + }); + return ( - -
- { file.Base64 && (file.ID.endsWith(".png") || file.ID.endsWith(".jpg") || file.ID.endsWith(".jpeg")) && ( - {file.ID} - )} +
+

- {file.ID.split("_").slice(1).join("_") || "Untitled"} + { file.ID.split("_").slice(1).join("_") || "Untitled" }

- {formatSize(getBase64Size(file.Base64))} + { formatSize(getBase64Size(file.Base64)) } -

Uploaded on {new Date(file.CreatedAt).toLocaleDateString()}

+

Uploaded on { new Date(file.CreatedAt).toLocaleDateString() }

- ) }) \ No newline at end of file diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index 8bc6dc0..b68990c 100644 --- a/src/components/Icons.tsx +++ b/src/components/Icons.tsx @@ -4,4 +4,11 @@ export function SolarUploadLinear(props: QwikIntrinsicElements['svg'], key: stri return ( ) +} + + +export function SolarTrashBin2Bold(props: QwikIntrinsicElements['svg'], key: string) { + return ( + + ) } \ No newline at end of file diff --git a/src/lib/api.ts b/src/lib/api.ts index 6fdb9d9..d75807b 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -2,24 +2,30 @@ import ky from 'ky'; import { StereoFile } from './types'; export const apiClient = ky.create({ - prefixUrl: '/api', - hooks: { - beforeRequest: [ - request => { - const token = localStorage.getItem('token'); - if (token) { - request.headers.set('Authorization', `Bearer ${token}`); - } - } - ] - } + prefixUrl: '/api', + hooks: { + beforeRequest: [ + request => { + const token = localStorage.getItem('token'); + if (token) { + request.headers.set('Authorization', `Bearer ${token}`); + } + } + ] + } }); // TODO: make wrapper for apiclient fr export const api = { - list: async () => await apiClient.get('list').json(), - upload: async (file: File) => { - const formData = new FormData(); - formData.append('file', file); - return await apiClient.post('upload', { body: formData }); - } + list: async () => await apiClient.get('list').json(), + upload: async (file: File) => { + const formData = new FormData(); + formData.append('file', file); + return await apiClient.post('upload', { body: formData }); + }, + delete: async (file_id: string) => { + console.log("Deleting file with ID:", file_id); + return await apiClient.delete(`delete`, { + json: { file_id } + }).json(); + }, } \ No newline at end of file diff --git a/src/routes/api/[path]/index.tsx b/src/routes/api/[path]/index.tsx index 033f1d0..170201c 100644 --- a/src/routes/api/[path]/index.tsx +++ b/src/routes/api/[path]/index.tsx @@ -27,4 +27,5 @@ const proxy = async ({ send, url, pathname, request }: RequestEvent) => { }; export const onGet: RequestHandler = proxy; -export const onPost: RequestHandler = proxy; \ No newline at end of file +export const onPost: RequestHandler = proxy; +export const onDelete: RequestHandler = proxy; \ No newline at end of file