Fully switch to new launcher & updater
This commit is contained in:
4 files changed
+8
-168
No files matched your search
@@ -19,7 +19,6 @@ import { handler as launcherLatestHandler } from './routes/launcher/latest/get'
|
||||
import { handler as launcherUpdateHandler } from './routes/launcher/update/get'
|
||||
import { handler as launcherDownloadHandler } from './routes/launcher/download/get'
|
||||
import { handler as launcherLoaderLatestHandler } from './routes/launcher/loader/latest/get'
|
||||
import { handler as launcherLoaderUpdateDataHandler } from './routes/launcher/loader/update-data/get'
|
||||
|
||||
import { handler as accountLoginPostHandler } from './routes/account/login/post'
|
||||
import { handler as accountRegisterPostHandler } from './routes/account/register/post'
|
||||
@@ -1058,31 +1057,6 @@ app.get('/launcher/loader/latest', launcherLoaderLatestHandler, {
|
||||
)
|
||||
})
|
||||
})
|
||||
app.get(
|
||||
'/launcher/loader/update-data',
|
||||
context => launcherLoaderUpdateDataHandler(context),
|
||||
{
|
||||
detail: {
|
||||
description:
|
||||
'The endpoint for getting Launcher Update data for when a new Update is released. It will be send & read by the updater.\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_64', 'aarch64'] }))
|
||||
}),
|
||||
headers: t.Object({
|
||||
'x-forwarded-for': t.Optional(
|
||||
t.String({
|
||||
description:
|
||||
'Ignore this header. It cannot be set or overridden and is required for endpoints to work properly'
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
app.post('/account/login', context => accountLoginPostHandler(context), {
|
||||
detail: {
|
||||
description:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { launcherUpdates } from '../../../lib/tables'
|
||||
import { desc, eq } from 'drizzle-orm'
|
||||
import { v2LauncherUpdates } from '../../../lib/tables'
|
||||
import { desc } from 'drizzle-orm'
|
||||
import {
|
||||
generateSignature,
|
||||
getDatabaseConnection,
|
||||
@@ -14,19 +14,18 @@ export const handler = async () => {
|
||||
|
||||
const version = await db
|
||||
.select({
|
||||
id: launcherUpdates.id
|
||||
version: v2LauncherUpdates.version
|
||||
})
|
||||
.from(launcherUpdates)
|
||||
.where(eq(launcherUpdates.hidden, false))
|
||||
.orderBy(desc(launcherUpdates.place))
|
||||
.from(v2LauncherUpdates)
|
||||
.orderBy(desc(v2LauncherUpdates.id))
|
||||
.limit(1)
|
||||
|
||||
connection.end()
|
||||
|
||||
return new Response(version[0].id, {
|
||||
return new Response(version[0].version, {
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
'X-Signature': generateSignature(version[0].id)
|
||||
'X-Signature': generateSignature(version[0].version)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,32 +1,3 @@
|
||||
import { loaderUpdates } from '../../../../lib/tables'
|
||||
import { desc, eq } from 'drizzle-orm'
|
||||
import {
|
||||
generateSignature,
|
||||
getDatabaseConnection,
|
||||
jsonResponse
|
||||
} from '../../../../lib/util'
|
||||
|
||||
export const handler = async () => {
|
||||
const dbResult = getDatabaseConnection(0)
|
||||
if (!dbResult)
|
||||
return jsonResponse({ error: 'Failed to connect to database' }, 500)
|
||||
const { connection, db } = dbResult
|
||||
|
||||
const version = await db
|
||||
.select({
|
||||
id: loaderUpdates.id
|
||||
})
|
||||
.from(loaderUpdates)
|
||||
.where(eq(loaderUpdates.hidden, false))
|
||||
.orderBy(desc(loaderUpdates.place))
|
||||
.limit(1)
|
||||
|
||||
connection.end()
|
||||
|
||||
return new Response(version[0].id, {
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
'X-Signature': generateSignature(version[0].id)
|
||||
}
|
||||
})
|
||||
return '-1'
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
import { launcherUpdates } from '../../../../lib/tables'
|
||||
import { desc, eq } from 'drizzle-orm'
|
||||
import { getDatabaseConnection, jsonResponse } from '../../../../lib/util'
|
||||
import { Context } from 'elysia'
|
||||
|
||||
export const handler = async (context: Context) => {
|
||||
const dbResult = getDatabaseConnection(0)
|
||||
if (!dbResult)
|
||||
return jsonResponse({ error: 'Failed to connect to database' }, 500)
|
||||
const { connection, db } = dbResult
|
||||
|
||||
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') platString = 'windows-x86'
|
||||
else if (arch == 'x86_64') platString = 'windows-x64'
|
||||
else if (arch == 'aarch64') platString = 'windows-arm64'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{ error: 'Unsupported architecture for Windows' },
|
||||
400
|
||||
)
|
||||
}
|
||||
} else if (platform == 'linux') {
|
||||
if (arch == 'x86') platString = 'linux-x86'
|
||||
else if (arch == 'x86_64') platString = 'linux-x64'
|
||||
else if (arch == 'aarch64') platString = 'linux-arm64'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{ error: 'Unsupported architecture for Linux' },
|
||||
400
|
||||
)
|
||||
}
|
||||
} else if (platform == 'macos') {
|
||||
if (arch == 'x86_64') platString = 'macos-x64'
|
||||
else if (arch == 'aarch64') platString = 'macos-arm64'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{ error: 'Unsupported architecture for macOS' },
|
||||
400
|
||||
)
|
||||
}
|
||||
} else {
|
||||
connection.end()
|
||||
return jsonResponse({ error: 'Unsupported platform' }, 400)
|
||||
}
|
||||
}
|
||||
|
||||
const versionsRaw = await db
|
||||
.select({
|
||||
id: launcherUpdates.id,
|
||||
releaseDate: launcherUpdates.releaseDate,
|
||||
downloadUrls: launcherUpdates.downloadUrls,
|
||||
platforms: launcherUpdates.platforms,
|
||||
sha512sums: launcherUpdates.sha512sums
|
||||
})
|
||||
.from(launcherUpdates)
|
||||
.where(eq(launcherUpdates.hidden, false))
|
||||
.orderBy(desc(launcherUpdates.place))
|
||||
.limit(1)
|
||||
.execute()
|
||||
|
||||
const versions = versionsRaw
|
||||
.map(v => ({
|
||||
...v,
|
||||
downloadUrls: JSON.parse(v.downloadUrls),
|
||||
platforms: JSON.parse(v.platforms),
|
||||
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
|
||||
})
|
||||
|
||||
connection.end()
|
||||
|
||||
return jsonResponse(versions[0])
|
||||
}
|
||||
Reference in new issue
Block a user