diff --git a/src/components/progress-table.svelte b/src/components/progress-table.svelte index e2ec45d..d89069e 100644 --- a/src/components/progress-table.svelte +++ b/src/components/progress-table.svelte @@ -83,7 +83,7 @@ > {@render done(entry.finished)} {/each} diff --git a/src/server/pt-api.ts b/src/server/pt-api.ts index 7e34c4e..122e7fb 100644 --- a/src/server/pt-api.ts +++ b/src/server/pt-api.ts @@ -1,16 +1,15 @@ import { env } from 'bun'; -type SelectBookmark = { +export type SelectEntry = { id: number; name: string; href: string; finished: boolean; - created_at: number; - updated_at: number; + updated_at: string; }; const baseUrl = env.API_SERVICE_URL; -const bookmarksUrl = `${baseUrl}/bookmarks`; +const entriesUrl = `${baseUrl}/api/entries`; const noBodyHeaders = new Headers({ Authorization: `Bearer ${env.BEARER_TOKEN}`, @@ -21,50 +20,50 @@ const bodyHeaders = new Headers({ Authorization: `Bearer ${env.BEARER_TOKEN}`, }); -async function query(): Promise> { +async function query(): Promise> { try { - const response = await fetch(bookmarksUrl, { + const response = await fetch(entriesUrl, { method: 'GET', signal: AbortSignal.timeout(50000), headers: noBodyHeaders, }); if (!response.ok) { - throw new Error('Failed to fetch bookmarks'); + throw new Error('Failed to fetch entries'); } const data = await response.json(); if (!Array.isArray(data)) { - throw new Error('Invalid bookmarks data'); + throw new Error('Invalid entries data'); } return data; } catch (err) { console.error(err); - throw new Error('Failed to fetch bookmarks'); + throw new Error('Failed to fetch entries'); } } async function remove(id: number) { try { - const response = await fetch(`${bookmarksUrl}/${id}`, { + const response = await fetch(`${entriesUrl}/${id}`, { method: 'DELETE', signal: AbortSignal.timeout(5000), headers: noBodyHeaders, }); if (!response.ok) { - throw new Error('Failed to remove bookmark'); + throw new Error('Failed to remove entry'); } } catch (err) { console.error(err); - throw new Error('Failed to remove bookmark'); + throw new Error('Failed to remove entry'); } } async function update(id: number, body: { name: string; href: string }) { try { - const response = await fetch(`${bookmarksUrl}/${id}`, { + const response = await fetch(`${entriesUrl}/${id}`, { method: 'PUT', body: JSON.stringify(body), signal: AbortSignal.timeout(5000), @@ -72,45 +71,45 @@ async function update(id: number, body: { name: string; href: string }) { }); if (!response.ok) { - throw new Error('Failed to update bookmark'); + throw new Error('Failed to update entry'); } } catch (err) { console.error(err); - throw new Error('Failed to update bookmark'); + throw new Error('Failed to update entry'); } } async function check(id: number, finished: boolean) { try { - const response = await fetch(`${bookmarksUrl}/${id}/check/${finished}`, { + const response = await fetch(`${entriesUrl}/${id}/check/${finished}`, { method: 'PUT', signal: AbortSignal.timeout(5000), headers: noBodyHeaders, }); if (!response.ok) { - throw new Error('Failed to check bookmark'); + throw new Error('Failed to check entry'); } } catch (err) { console.error(err); - throw new Error('Failed to check bookmark'); + throw new Error('Failed to check entry'); } } async function create(body: { name: string; href: string }) { try { - const response = await fetch(`${bookmarksUrl}`, { + const response = await fetch(`${entriesUrl}`, { method: 'POST', body: JSON.stringify(body), signal: AbortSignal.timeout(5000), headers: bodyHeaders, }); if (!response.ok) { - throw new Error('Failed to create bookmark'); + throw new Error('Failed to create entry'); } } catch (err) { if (err) { console.error(err); - throw new Error('Failed to create bookmark'); + throw new Error('Failed to create entry'); } } } diff --git a/src/util.ts b/src/util.ts index 6711ee3..5295490 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,15 +1,7 @@ import { userstate } from './shared.svelte'; +import type { SelectEntry } from './server/pt-api'; -type SelectBookmark = { - id: number; - name: string; - href: string; - finished: boolean; - created_at: number; - updated_at: number; -}; - -export async function fetchEntries(): Promise { +export async function fetchEntries(): Promise { try { const response = await fetch('/api/entries', { method: 'GET',