summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorCyber <cyber.hf18@gmail.com>2025-12-01 07:49:37 +0100
committerGitHub <noreply@github.com>2025-12-01 07:49:37 +0100
commitdfab4904be7689e0a05da6dfa47bab0977c6c1fd (patch)
tree69bf47610dd876dd73f6e17b7fe058cf93e366e8 /src/api
parentfix other bug (diff)
parentMerge pull request #1415 from MathMan05/dupedEvents (diff)
downloadserver-ts-dfab4904be7689e0a05da6dfa47bab0977c6c1fd.tar.xz
Merge branch 'master' into channelSearch
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/applications/detectable.ts12
-rw-r--r--src/api/routes/games/detectable.ts12
-rw-r--r--src/api/routes/users/@me/guilds.ts22
-rw-r--r--src/api/routes/users/@me/settings.ts2
4 files changed, 16 insertions, 32 deletions
diff --git a/src/api/routes/applications/detectable.ts b/src/api/routes/applications/detectable.ts

index aadb4a0e..cea0e075 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 167720c1..d5183b92 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); }, ); diff --git a/src/api/routes/users/@me/guilds.ts b/src/api/routes/users/@me/guilds.ts
index 641180f3..df71f46e 100644 --- a/src/api/routes/users/@me/guilds.ts +++ b/src/api/routes/users/@me/guilds.ts
@@ -76,27 +76,7 @@ router.delete( throw new HTTPError("You can't leave instance auto join guilds", 400); } - await Promise.all([ - Member.removeFromGuild(req.user_id, guild_id), - emitEvent({ - event: "GUILD_DELETE", - data: { - id: guild_id, - }, - user_id: req.user_id, - } as GuildDeleteEvent), - ]); - - const user = await User.getPublicUser(req.user_id); - - await emitEvent({ - event: "GUILD_MEMBER_REMOVE", - data: { - guild_id: guild_id, - user: user.toPublicUser(), - }, - guild_id: guild_id, - } as GuildMemberRemoveEvent); + await Member.removeFromGuild(req.user_id, guild_id); return res.sendStatus(204); }, diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts
index 1973b8e4..d220b859 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(),