From ffe3d99a9f6324d8037cd7875e2c5d8185a96f5f Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Sun, 26 Apr 2026 18:15:26 -0700 Subject: [PATCH] Switch to headers for mods manifest & version manifest --- src/index.ts | 17 ++++------------ src/routes/launcher/mods/get.ts | 5 +++-- src/routes/launcher/versions/get.ts | 31 ++++++++++------------------- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src/index.ts b/src/index.ts index f40494d..5fd6959 100644 --- a/src/index.ts +++ b/src/index.ts @@ -963,8 +963,6 @@ app.get('/launcher/mods', context => launcherModsGetHandler(context), { tags: ['Launcher'] }, query: t.Object({ - platform: t.String({ examples: ['windows', 'macos', 'linux'] }), - arch: t.String({ examples: ['x86', 'x64', 'arm64'] }), version: t.String() }), headers: t.Object({ @@ -972,7 +970,8 @@ app.get('/launcher/mods', context => launcherModsGetHandler(context), { t.String({ hide: true }) - ) + ), + clientplatform: t.String() }) }) app.get('/launcher/versions', context => launcherVersionsHandler(context), { @@ -981,21 +980,13 @@ app.get('/launcher/versions', context => launcherVersionsHandler(context), { 'The endpoint for getting the launcher manifest.\n\nNote: if going to use the params, both must be provided at the same time.', tags: ['Launcher'] }, - query: t.Object({ - platform: t.Optional(t.String({ examples: ['windows', 'macos', 'linux'] })), - arch: t.Optional(t.String({ examples: ['x86', 'x64', 'arm64'] })), - game: t.Optional( - t.String({ - description: "Adding this will make it only show a Game ID's versions" - }) - ) - }), headers: t.Object({ 'x-forwarded-for': t.Optional( t.String({ hide: true }) - ) + ), + clientplatform: t.Optional(t.String()) }) }) app.get('/launcher/latest', launcherLatestHandler, { diff --git a/src/routes/launcher/mods/get.ts b/src/routes/launcher/mods/get.ts index ce3bff9..ad61ad1 100644 --- a/src/routes/launcher/mods/get.ts +++ b/src/routes/launcher/mods/get.ts @@ -9,8 +9,9 @@ export const handler = async (context: Context) => { return jsonResponse({ error: 'Failed to connect to database' }, 500) const { connection, db } = dbResult - const platform = context.query.platform - const arch = context.query.arch + const clientplatform = context.headers.clientplatform + const platform = clientplatform?.split('-')[0] + const arch = clientplatform?.split('-')[1] const version = context.query.version let platformsToShow: string[] | null = null diff --git a/src/routes/launcher/versions/get.ts b/src/routes/launcher/versions/get.ts index 7d3020b..f53dc96 100644 --- a/src/routes/launcher/versions/get.ts +++ b/src/routes/launcher/versions/get.ts @@ -9,9 +9,9 @@ export const handler = async (context: Context) => { return jsonResponse({ error: 'Failed to connect to database' }, 500) const { connection, db } = dbResult - const platform = context.query.platform - const arch = context.query.arch - const game = context.query.game + const clientplatform = context.headers.clientplatform + const platform = clientplatform?.split('-')[0] + const arch = clientplatform?.split('-')[1] let showAll = false if (!platform || !arch) showAll = true @@ -100,14 +100,7 @@ export const handler = async (context: Context) => { lastRevision: launcherVersionManifest.lastRevision }) .from(launcherVersionManifest) - .where( - game != null - ? and( - eq(launcherVersionManifest.game, Number(game)), - eq(launcherVersionManifest.hidden, false) - ) - : eq(launcherVersionManifest.hidden, false) - ) + .where(eq(launcherVersionManifest.hidden, false)) .orderBy( asc(launcherVersionManifest.game), desc(launcherVersionManifest.place) @@ -167,15 +160,13 @@ export const handler = async (context: Context) => { return v.download !== undefined }) - if (!game) { - const gamesListRaw = await db.select().from(games).execute() - const gamesList = gamesListRaw.map(v => ({ - ...v, - categoryNames: JSON.parse(v.categoryNames) - })) + const gamesListRaw = await db.select().from(games).execute() + const gamesList = gamesListRaw.map(v => ({ + ...v, + categoryNames: JSON.parse(v.categoryNames) + })) - connection.end() + connection.end() - return jsonResponse({ versions: versions, games: gamesList }) - } else return jsonResponse(versions) + return jsonResponse({ versions: versions, games: gamesList }) }