Tweaks to versions endpoint and improve loader update data
This commit is contained in:
@@ -31,7 +31,7 @@ const app = new Elysia()
|
||||
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))
|
||||
app.get("/launcher/loader/update-data", (context) => launcherLoaderUpdateDataHandler(context, db))
|
||||
app.all("*", () => jsonResponse({ message: "No endpoint found (are you using the correct request method?)" }, 404))
|
||||
|
||||
app.listen(3342)
|
||||
@@ -1,3 +1,3 @@
|
||||
export async function handler() {
|
||||
return "1.0.0"
|
||||
return "1.0.1"
|
||||
}
|
||||
@@ -2,8 +2,41 @@ import { MySql2Database } from "drizzle-orm/mysql2";
|
||||
import { launcherUpdates } from "../../../lib/tables";
|
||||
import { 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 = null
|
||||
if (!showAll) {
|
||||
if (platform == "windows") {
|
||||
if (arch == "x86_64") platString = "windows"
|
||||
else if (arch == "aarch64") platString = "windows-arm64"
|
||||
else {
|
||||
return jsonResponse({ error: "Unsupported architecture for Windows" }, 400)
|
||||
}
|
||||
} else if (platform == "linux") {
|
||||
if (arch == "x86_64") platString = "linux"
|
||||
else {
|
||||
return jsonResponse({ error: "Unsupported architecture for Linux" }, 400)
|
||||
}
|
||||
} else if (platform == "macos") {
|
||||
if (arch == "x86_64") platString = "macos-intel"
|
||||
else if (arch == "aarch64") platString = "macos-silicon"
|
||||
else {
|
||||
return jsonResponse({ error: "Unsupported architecture for macOS" }, 400)
|
||||
}
|
||||
} else {
|
||||
return jsonResponse({ error: "Unsupported platform" }, 400)
|
||||
}
|
||||
}
|
||||
|
||||
export async function handler(db: MySql2Database) {
|
||||
const versionsRaw = await db.select({
|
||||
id: launcherUpdates.id,
|
||||
releaseDate: launcherUpdates.releaseDate,
|
||||
@@ -21,8 +54,27 @@ export async function handler(db: MySql2Database) {
|
||||
...v,
|
||||
downloadUrls: JSON.parse(v.downloadUrls),
|
||||
platforms: JSON.parse(v.platforms),
|
||||
sha512sums: JSON.parse(v.sha512sums)
|
||||
sha512sums: JSON.parse(v.sha512sums),
|
||||
downloadUrl: undefined as string | undefined,
|
||||
sha512sum: undefined as string | undefined
|
||||
}))
|
||||
.filter(v => {
|
||||
if (showAll || !platString) {
|
||||
delete v.downloadUrl
|
||||
delete v.sha512sum
|
||||
return true
|
||||
}
|
||||
const i = v.platforms.indexOf(platString)
|
||||
if (i !== -1) {
|
||||
v.downloadUrl = v.downloadUrls[i]
|
||||
v.sha512sum = v.sha512sums[i]
|
||||
delete v.downloadUrls
|
||||
delete v.platforms
|
||||
delete v.sha512sums
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
return jsonResponse(versions[0])
|
||||
}
|
||||
|
||||
@@ -19,18 +19,20 @@ export async function handler(context: Context, db: MySql2Database) {
|
||||
if (arch == "x86_64") platString = "windows"
|
||||
else if (arch == "aarch64") platString = "windows-arm64"
|
||||
else {
|
||||
return jsonResponse({ error: "Unsupported architecture for Windows" }, 400)
|
||||
return jsonResponse({ message: "Unsupported architecture for Windows", versions: null, games: null }, 400)
|
||||
}
|
||||
} else if (platform == "linux") {
|
||||
if (arch == "x86_64") platString = "linux"
|
||||
else {
|
||||
return jsonResponse({ error: "Unsupported architecture for Linux" }, 400)
|
||||
return jsonResponse({ message: "Unsupported architecture for Linux", versions: null, games: null }, 400)
|
||||
}
|
||||
} else if (platform == "macos") {
|
||||
if (arch == "x86_64" || arch == "aarch64") platString = "macos"
|
||||
else {
|
||||
return jsonResponse({ error: "Unsupported architecture for macOS" }, 400)
|
||||
return jsonResponse({ message: "Unsupported architecture for macOS", versions: null, games: null }, 400)
|
||||
}
|
||||
} else {
|
||||
return jsonResponse({ message: "Unsupported platform", versions: null, games: null }, 400)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user