Change the way stuff works with launcher endpoint
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
-- https://www.phpmyadmin.net/
|
-- https://www.phpmyadmin.net/
|
||||||
--
|
--
|
||||||
-- Host: localhost
|
-- Host: localhost
|
||||||
-- Generation Time: Nov 03, 2025 at 05:02 AM
|
-- Generation Time: Nov 03, 2025 at 05:06 PM
|
||||||
-- Server version: 12.0.2-MariaDB
|
-- Server version: 12.0.2-MariaDB
|
||||||
-- PHP Version: 8.4.14
|
-- PHP Version: 8.4.14
|
||||||
|
|
||||||
@@ -67,7 +67,8 @@ CREATE TABLE `launcherversions` (
|
|||||||
`executables` text NOT NULL,
|
`executables` text NOT NULL,
|
||||||
`hidden` tinyint(1) NOT NULL DEFAULT 1,
|
`hidden` tinyint(1) NOT NULL DEFAULT 1,
|
||||||
`game` int(11) NOT NULL DEFAULT 0,
|
`game` int(11) NOT NULL DEFAULT 0,
|
||||||
`place` int(11) NOT NULL DEFAULT 0
|
`place` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`sha512sums` text NOT NULL DEFAULT '[]'
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const app = new Elysia()
|
|||||||
methods: ["POST", "GET"]
|
methods: ["POST", "GET"]
|
||||||
}))
|
}))
|
||||||
|
|
||||||
app.get("/launcher/versions", () => launcherVersionsHandler(db))
|
app.get("/launcher/versions", (context) => launcherVersionsHandler(context, db))
|
||||||
app.get("/launcher/latest", () => launcherLatestHandler(db))
|
app.get("/launcher/latest", () => launcherLatestHandler(db))
|
||||||
app.get("/launcher/loader/latest", launcherLoaderLatestHandler)
|
app.get("/launcher/loader/latest", launcherLoaderLatestHandler)
|
||||||
app.get("/launcher/loader/update-data", () => launcherLoaderUpdateDataHandler(db))
|
app.get("/launcher/loader/update-data", () => launcherLoaderUpdateDataHandler(db))
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ export const launcherVersions = mysqlTable('launcherversions', {
|
|||||||
executables: text('executables').notNull(),
|
executables: text('executables').notNull(),
|
||||||
hidden: boolean('hidden').notNull().default(true),
|
hidden: boolean('hidden').notNull().default(true),
|
||||||
game: int('game').notNull().default(0).references(() => launcherGames.id),
|
game: int('game').notNull().default(0).references(() => launcherGames.id),
|
||||||
place: int('place').notNull().default(0)
|
place: int('place').notNull().default(0),
|
||||||
|
sha512sums: text('sha512sums').notNull().default("[]")
|
||||||
})
|
})
|
||||||
|
|
||||||
export const launcherUpdates = mysqlTable('launcherupdates', {
|
export const launcherUpdates = mysqlTable('launcherupdates', {
|
||||||
|
|||||||
@@ -1,9 +1,26 @@
|
|||||||
import { MySql2Database } from "drizzle-orm/mysql2";
|
import { MySql2Database } from "drizzle-orm/mysql2";
|
||||||
import { launcherGames, launcherVersions } from "../../lib/tables";
|
import { launcherGames, launcherVersions } from "../../lib/tables";
|
||||||
import { eq } from "drizzle-orm";
|
import { asc, desc, eq } from "drizzle-orm";
|
||||||
import { jsonResponse } from "../../lib/util";
|
import { jsonResponse } from "../../lib/util";
|
||||||
|
import { Context } from "elysia";
|
||||||
|
|
||||||
|
export async function handler(context: Context, db: MySql2Database) {
|
||||||
|
const platform = context.query.platform as string | undefined
|
||||||
|
const arch = context.query.arch as string | undefined
|
||||||
|
let showAll = false
|
||||||
|
|
||||||
|
if (!platform || !arch) {
|
||||||
|
showAll = true
|
||||||
|
}
|
||||||
|
|
||||||
|
let platString = platform
|
||||||
|
if (!showAll) {
|
||||||
|
if (platform == "windows") {
|
||||||
|
if (arch == "x86_64") platString = "windows"
|
||||||
|
else if (arch == "aarch64") platString = "windows-arm64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function handler(db: MySql2Database) {
|
|
||||||
const versionsRaw = await db.select({
|
const versionsRaw = await db.select({
|
||||||
id: launcherVersions.id,
|
id: launcherVersions.id,
|
||||||
versionName: launcherVersions.versionName,
|
versionName: launcherVersions.versionName,
|
||||||
@@ -11,16 +28,36 @@ export async function handler(db: MySql2Database) {
|
|||||||
downloadUrls: launcherVersions.downloadUrls,
|
downloadUrls: launcherVersions.downloadUrls,
|
||||||
platforms: launcherVersions.platforms,
|
platforms: launcherVersions.platforms,
|
||||||
executables: launcherVersions.executables,
|
executables: launcherVersions.executables,
|
||||||
game: launcherVersions.game,
|
game: launcherVersions.game
|
||||||
place: launcherVersions.place
|
}).from(launcherVersions)
|
||||||
}).from(launcherVersions).where(eq(launcherVersions.hidden, false)).execute()
|
.where(eq(launcherVersions.hidden, false))
|
||||||
|
.orderBy(
|
||||||
|
asc(launcherVersions.game),
|
||||||
|
desc(launcherVersions.place)
|
||||||
|
)
|
||||||
|
.execute()
|
||||||
|
|
||||||
const versions = versionsRaw.map(v => ({
|
const versions = versionsRaw.map(v => ({
|
||||||
...v,
|
...v,
|
||||||
downloadUrls: JSON.parse(v.downloadUrls),
|
downloadUrls: JSON.parse(v.downloadUrls),
|
||||||
platforms: JSON.parse(v.platforms),
|
platforms: JSON.parse(v.platforms),
|
||||||
executables: JSON.parse(v.executables)
|
executables: JSON.parse(v.executables),
|
||||||
|
downloadUrl: null as string | null,
|
||||||
|
executable: null as string | null
|
||||||
}))
|
}))
|
||||||
|
.filter(v => {
|
||||||
|
if (showAll) return true
|
||||||
|
const i = v.platforms.indexOf(platString)
|
||||||
|
if (i !== -1) {
|
||||||
|
v.downloadUrl = v.downloadUrls[i]
|
||||||
|
v.executable = v.executables[i]
|
||||||
|
delete v.downloadUrls
|
||||||
|
delete v.platforms
|
||||||
|
delete v.executables
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
const gamesRaw = await db.select().from(launcherGames).execute()
|
const gamesRaw = await db.select().from(launcherGames).execute()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user