From b7fc596d0608c7ecc5712816afad020c6abc032d Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Sat, 29 Nov 2025 20:28:50 -0600 Subject: [PATCH 1/2] fix expose --- src/api/routes/users/@me/settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts index 1973b8e48..d220b859d 100644 --- a/src/api/routes/users/@me/settings.ts +++ b/src/api/routes/users/@me/settings.ts @@ -86,7 +86,7 @@ router.patch( event: "PRESENCE_UPDATE", user_id: user.id, data: { - user: user, + user: user.toPublicUser(), activities: session.activities, client_status: session?.client_status, status: session.getPublicStatus(), From 7a40124e9e97723ffa2902a5eec6577a132ae8a3 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 29 Nov 2025 23:46:33 +0100 Subject: [PATCH 2/2] Tell browsers to cache applications/games detectable response in accordance of internal cache --- .idea/workspace.xml | 2 +- src/api/routes/applications/detectable.ts | 12 +++++++----- src/api/routes/games/detectable.ts | 12 +++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4b0adf537..c52fdde44 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -161,7 +161,7 @@ - + diff --git a/src/api/routes/applications/detectable.ts b/src/api/routes/applications/detectable.ts index aadb4a0e2..cea0e0756 100644 --- a/src/api/routes/applications/detectable.ts +++ b/src/api/routes/applications/detectable.ts @@ -23,7 +23,7 @@ import { ApplicationDetectableResponse } from "@spacebar/schemas*"; const router: Router = Router({ mergeParams: true }); const cache = { data: {}, - lastUpdated: 0 + expires: 0 } router.get( @@ -37,14 +37,16 @@ router.get( }), async (req: Request, res: Response) => { // 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 + if (Date.now() > cache.expires) { + const response = await fetch("https://discord.com/api/v10/games/detectable"); // because, well, it's unauthenticated anyways const data = await response.json(); cache.data = data as ApplicationDetectableResponse; - cache.lastUpdated = Date.now(); + cache.expires = Date.now() + 6 * 60 * 60 * 1000; } - res.status(200).json(cache.data); + res.set("Cache-Control", `public, max-age=${Math.floor((cache.expires - Date.now()) / 1000)}, s-maxage=${Math.floor((cache.expires - Date.now()) / 1000)}, immutable`) + .status(200) + .json(cache.data); }, ); diff --git a/src/api/routes/games/detectable.ts b/src/api/routes/games/detectable.ts index 167720c14..d5183b924 100644 --- a/src/api/routes/games/detectable.ts +++ b/src/api/routes/games/detectable.ts @@ -23,8 +23,8 @@ import { ApplicationDetectableResponse } from "@spacebar/schemas*"; const router: Router = Router({ mergeParams: true }); const cache = { data: {}, - lastUpdated: 0 -} + expires: 0, +}; // modern dclients call this, is /applications/detectable deprecated? router.get( @@ -38,14 +38,16 @@ router.get( }), async (req: Request, res: Response) => { // cache for 6 hours - if (Date.now() - cache.lastUpdated > 6 * 60 * 60 * 1000) { + if (Date.now() > cache.expires) { const response = await fetch("https://discord.com/api/v10/games/detectable"); // because, well, it's unauthenticated anyways const data = await response.json(); cache.data = data as ApplicationDetectableResponse; - cache.lastUpdated = Date.now(); + cache.expires = Date.now() + 6 * 60 * 60 * 1000; } - res.status(200).json(cache.data); + res.set("Cache-Control", `public, max-age=${Math.floor((cache.expires - Date.now()) / 1000)}, s-maxage=${Math.floor((cache.expires - Date.now()) / 1000)}, immutable`) + .status(200) + .json(cache.data); }, );