summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-10-16 18:41:52 +0200
committerRory& <root@rory.gay>2025-10-16 18:41:52 +0200
commitaff39e4b1bfa56fda4125d38c3c5298433c156a2 (patch)
tree9030bd2bb62766803c2295aebee4c279082fd19c /src/api
parentAdd application command schema (diff)
downloadserver-ts-aff39e4b1bfa56fda4125d38c3c5298433c156a2.tar.xz
Local changes
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/applications/detectable.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/api/routes/applications/detectable.ts b/src/api/routes/applications/detectable.ts

index 1a111f427..aadb4a0e2 100644 --- a/src/api/routes/applications/detectable.ts +++ b/src/api/routes/applications/detectable.ts
@@ -18,8 +18,13 @@ import { route } from "@spacebar/api"; import { Request, Response, Router } from "express"; +import { ApplicationDetectableResponse } from "@spacebar/schemas*"; const router: Router = Router({ mergeParams: true }); +const cache = { + data: {}, + lastUpdated: 0 +} router.get( "/", @@ -31,8 +36,15 @@ router.get( }, }), async (req: Request, res: Response) => { - //TODO - res.send([]).status(200); + // cache for 6 hours + if (Date.now() - cache.lastUpdated > 6 * 60 * 60 * 1000) { + const response = await fetch("https://discord.com/api/v10/applications/detectable"); // because, well, it's unauthenticated anyways + const data = await response.json(); + cache.data = data as ApplicationDetectableResponse; + cache.lastUpdated = Date.now(); + } + + res.status(200).json(cache.data); }, );