Add v2 launcher updater endpoint

This commit is contained in:
Lncvrt committed 2026-04-02 17:14:24 -07:00
1 parent 5aa3ed5820
commit d7befe30ca
4 files changed
+119 -1

No files matched your search

+27 -1
View File
@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Mar 29, 2026 at 12:54 AM
-- Generation Time: Apr 03, 2026 at 12:13 AM
-- Server version: 10.11.14-MariaDB-0ubuntu0.24.04.1
-- PHP Version: 8.3.30
@@ -169,6 +169,20 @@ CREATE TABLE `users` (
-- --------------------------------------------------------
--
-- Table structure for table `v2launcherupdates`
--
CREATE TABLE `v2launcherupdates` (
`id` bigint(20) NOT NULL,
`version` varchar(32) NOT NULL,
`notes` text NOT NULL,
`release_date` timestamp NOT NULL,
`download_data` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- --------------------------------------------------------
--
-- Table structure for table `verifycodes`
--
@@ -241,6 +255,12 @@ ALTER TABLE `resetcodes`
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `v2launcherupdates`
--
ALTER TABLE `v2launcherupdates`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `verifycodes`
--
@@ -281,6 +301,12 @@ ALTER TABLE `resetcodes`
ALTER TABLE `users`
MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `v2launcherupdates`
--
ALTER TABLE `v2launcherupdates`
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `verifycodes`
--
+19
View File
@@ -16,6 +16,7 @@ import { handler as canLoadClientHandler } from './routes/can-load-client'
import { handler as launcherModsGetHandler } from './routes/launcher/mods/get'
import { handler as launcherVersionsHandler } from './routes/launcher/versions/get'
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'
@@ -1011,6 +1012,24 @@ app.get('/launcher/latest', launcherLatestHandler, {
)
})
})
app.get('/launcher/update', launcherUpdateHandler, {
detail: {
description: "The endpoint for getting the launcher's update data.",
tags: ['Launcher']
},
query: t.Object({
target: t.String(),
arch: t.String(),
currentVersion: t.String()
}),
headers: t.Object({
'x-forwarded-for': t.Optional(
t.String({
hide: true
})
)
})
})
app.get('/launcher/download', context => launcherDownloadHandler(context), {
query: t.Object({
versionId: t.Optional(t.String({ hide: true })),
+9
View File
@@ -6,6 +6,7 @@ import {
longtext,
mysqlTable,
text,
timestamp,
tinyint,
varchar
} from 'drizzle-orm/mysql-core'
@@ -126,6 +127,14 @@ export const modVersions = mysqlTable('modversions', {
hidden: boolean('hidden').default(false).notNull()
})
export const v2LauncherUpdates = mysqlTable('v2launcherupdates', {
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement().notNull(),
version: varchar('version', { length: 32 }).notNull(),
notes: text('notes').notNull(),
releaseDate: timestamp('release_date').notNull(),
downloadData: text('download_data').notNull()
})
// berrydashdatabase
export const berryDashUserData = mysqlTable('userdata', {
+64
View File
@@ -0,0 +1,64 @@
import { files, v2LauncherUpdates } 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
const { connection, db } = dbResult
const target = context.query.target
const arch = context.query.arch
// const currentVersion = context.query.currentVersion
const versionsData = await db
.select({
version: v2LauncherUpdates.version,
notes: v2LauncherUpdates.notes,
releaseDate: v2LauncherUpdates.releaseDate,
downloadData: v2LauncherUpdates.downloadData
})
.from(v2LauncherUpdates)
.orderBy(desc(v2LauncherUpdates.id))
.limit(1)
.execute()
if (versionsData.length != 1) return
const downloadData = JSON.parse(versionsData[0].downloadData)[
(target + '-' + arch)
.replace('windows', 'win')
.replace('darwin', 'macos')
.replace('x86_64', 'x64')
.replace('i686', 'x86')
.replace('aarch64', 'arm64')
.replace('armv7', 'arm32')
]
if (!downloadData) return
const fileInfo = await db
.select({ path: files.path })
.from(files)
.where(eq(files.id, downloadData.download))
if (fileInfo.length != 1) return
console.log({
version: versionsData[0].version,
notes: versionsData[0].notes,
pub_date: versionsData[0].releaseDate,
url: 'https://games-r2.lncvrt.xyz/' + fileInfo[0].path,
signature: downloadData.signature
})
connection.end()
return jsonResponse({
version: versionsData[0].version,
notes: versionsData[0].notes,
pub_date: versionsData[0].releaseDate,
url: 'https://games-r2.lncvrt.xyz/' + fileInfo[0].path,
signature: downloadData.signature
})
}