From 6fbe508403530bc12e7fcd86a13292228e0c4ccb Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Fri, 30 Jun 2023 23:33:54 -0700 Subject: [PATCH] refactor: :recycle: force patrons update on about-calckey --- .../backend/src/server/api/endpoints/patrons.ts | 14 ++++++++++---- packages/client/src/pages/about-calckey.vue | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/patrons.ts b/packages/backend/src/server/api/endpoints/patrons.ts index 944858694a..ac914daa12 100644 --- a/packages/backend/src/server/api/endpoints/patrons.ts +++ b/packages/backend/src/server/api/endpoints/patrons.ts @@ -11,19 +11,25 @@ export const meta = { export const paramDef = { type: "object", - properties: {}, + properties: { + forceUpdate: { type: "boolean", default: false }, + }, required: [], } as const; -export default define(meta, paramDef, async () => { +export default define(meta, paramDef, async (ps) => { let patrons; const cachedPatrons = await redisClient.get("patrons"); - if (cachedPatrons) { + if (!ps.forceUpdate && cachedPatrons) { patrons = JSON.parse(cachedPatrons); } else { patrons = await fetch( "https://codeberg.org/calckey/calckey/raw/branch/develop/patrons.json", - ).then((response) => response.json()); + ) + .then((response) => response.json()) + .catch(() => { + patrons = cachedPatrons ? JSON.parse(cachedPatrons) : []; + }); await redisClient.set("patrons", JSON.stringify(patrons), "EX", 3600); } diff --git a/packages/client/src/pages/about-calckey.vue b/packages/client/src/pages/about-calckey.vue index 1e16356a51..6071a2c2d9 100644 --- a/packages/client/src/pages/about-calckey.vue +++ b/packages/client/src/pages/about-calckey.vue @@ -164,7 +164,7 @@ import { defaultStore } from "@/store"; import * as os from "@/os"; import { definePageMetadata } from "@/scripts/page-metadata"; -const patrons = await os.api("patrons"); +const patrons = await os.api("patrons", { forceUpdate: true }); let easterEggReady = false; let easterEggEmojis = $ref([]);