From 1a231bf03e5db38ba99edb6903757ce2f8172b8f Mon Sep 17 00:00:00 2001 From: Beebles <102569435+beebls@users.noreply.github.com> Date: Sat, 31 Aug 2024 16:41:58 -0600 Subject: rename motd to announcements and implement new API --- frontend/src/store.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'frontend/src/store.ts') diff --git a/frontend/src/store.ts b/frontend/src/store.ts index e64de8d5..1cfe36cd 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -42,12 +42,12 @@ export interface PluginInstallRequest { installType: InstallType; } -export interface Motd { +export interface Announcement { id: string; - name: string; - description: string; - date: string; - severity: 'High' | 'Medium' | 'Low'; + title: string; + text: string; + created: string; + updated: string; } // name: version @@ -57,10 +57,13 @@ export async function getStore(): Promise { return await getSetting('store', Store.Default); } -export async function getMotd(): Promise { +export async function getLatestAnnouncement(): Promise { let version = await window.DeckyPluginLoader.updateVersion(); let store = await getSetting('store', null); - let customURL = await getSetting('motd-url', 'https://plugins.deckbrew.xyz/v1/motd'); + let customURL = await getSetting( + 'announcements-url', + 'https://plugins.deckbrew.xyz/v1/announcements/-/current', + ); if (store === null) { console.log('Could not get store, using Default.'); @@ -71,30 +74,28 @@ export async function getMotd(): Promise { let resolvedURL; switch (store) { case Store.Default: - resolvedURL = 'https://plugins.deckbrew.xyz/v1/motd'; + resolvedURL = 'https://plugins.deckbrew.xyz/v1/announcements/-/current'; break; case Store.Testing: - resolvedURL = 'https://testing.deckbrew.xyz/v1/motd'; + resolvedURL = 'https://testing.deckbrew.xyz/v1/announcements/-/current'; break; case Store.Custom: resolvedURL = customURL; break; default: console.error('Somehow you ended up without a standard URL, using the default URL.'); - resolvedURL = 'https://plugins.deckbrew.xyz/v1/motd'; + resolvedURL = 'https://plugins.deckbrew.xyz/v1/announcements/-/current'; break; } - return fetch(resolvedURL, { + const res = await fetch(resolvedURL, { method: 'GET', headers: { 'X-Decky-Version': version.current, }, - }).then((r) => { - if (r.status === 200) { - return r.json(); - } - return null; }); + if (res.status !== 200) return null; + const json = await res.json(); + return json?.[0] ?? null; } export async function getPluginList( -- cgit v1.2.3