refactor: ♻️ force patrons update on about-calckey

This commit is contained in:
ThatOneCalculator 2023-06-30 23:33:54 -07:00
parent 8c406df3da
commit 55393b9f1f
2 changed files with 11 additions and 5 deletions

View file

@ -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);
}

View file

@ -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([]);