Change the way stuff works with launcher endpoint
This commit is contained in:
@@ -28,7 +28,7 @@ const app = new Elysia()
|
||||
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/loader/latest", launcherLoaderLatestHandler)
|
||||
app.get("/launcher/loader/update-data", () => launcherLoaderUpdateDataHandler(db))
|
||||
|
||||
@@ -18,7 +18,8 @@ export const launcherVersions = mysqlTable('launcherversions', {
|
||||
executables: text('executables').notNull(),
|
||||
hidden: boolean('hidden').notNull().default(true),
|
||||
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', {
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
import { MySql2Database } from "drizzle-orm/mysql2";
|
||||
import { launcherGames, launcherVersions } from "../../lib/tables";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { asc, desc, eq } from "drizzle-orm";
|
||||
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({
|
||||
id: launcherVersions.id,
|
||||
versionName: launcherVersions.versionName,
|
||||
@@ -11,16 +28,36 @@ export async function handler(db: MySql2Database) {
|
||||
downloadUrls: launcherVersions.downloadUrls,
|
||||
platforms: launcherVersions.platforms,
|
||||
executables: launcherVersions.executables,
|
||||
game: launcherVersions.game,
|
||||
place: launcherVersions.place
|
||||
}).from(launcherVersions).where(eq(launcherVersions.hidden, false)).execute()
|
||||
game: launcherVersions.game
|
||||
}).from(launcherVersions)
|
||||
.where(eq(launcherVersions.hidden, false))
|
||||
.orderBy(
|
||||
asc(launcherVersions.game),
|
||||
desc(launcherVersions.place)
|
||||
)
|
||||
.execute()
|
||||
|
||||
const versions = versionsRaw.map(v => ({
|
||||
...v,
|
||||
downloadUrls: JSON.parse(v.downloadUrls),
|
||||
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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user