diff options
| author | Beebles <102569435+beebls@users.noreply.github.com> | 2024-08-31 16:41:58 -0600 |
|---|---|---|
| committer | Beebles <102569435+beebls@users.noreply.github.com> | 2024-09-13 17:22:14 -0600 |
| commit | 985dc669a11c3b4f053d60737181879b5ac811d8 (patch) | |
| tree | ffc512b723de406e25a96572192e3027408ddb98 /frontend/src/store.ts | |
| parent | 3193f71c20c5c40c2742547ec291ad06cc12e27f (diff) | |
| download | decky-loader-985dc669a11c3b4f053d60737181879b5ac811d8.tar.gz decky-loader-985dc669a11c3b4f053d60737181879b5ac811d8.zip | |
rename motd to announcements and implement new API
Diffstat (limited to 'frontend/src/store.ts')
| -rw-r--r-- | frontend/src/store.ts | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/frontend/src/store.ts b/frontend/src/store.ts index 7692a711..454c7b9a 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -40,12 +40,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 @@ -55,10 +55,13 @@ export async function getStore(): Promise<Store> { return await getSetting<Store>('store', Store.Default); } -export async function getMotd(): Promise<Motd> { +export async function getLatestAnnouncement(): Promise<Announcement | null> { let version = await window.DeckyPluginLoader.updateVersion(); let store = await getSetting<Store | null>('store', null); - let customURL = await getSetting<string>('motd-url', 'https://plugins.deckbrew.xyz/v1/motd'); + let customURL = await getSetting<string>( + 'announcements-url', + 'https://plugins.deckbrew.xyz/v1/announcements/-/current', + ); if (store === null) { console.log('Could not get store, using Default.'); @@ -69,30 +72,28 @@ export async function getMotd(): Promise<Motd> { 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( |
