Finish reworking launcher manifest stuff
This commit is contained in:
10 files changed
+251
-229
No files matched your search
@@ -3,7 +3,7 @@
|
|||||||
-- https://www.phpmyadmin.net/
|
-- https://www.phpmyadmin.net/
|
||||||
--
|
--
|
||||||
-- Host: localhost
|
-- Host: localhost
|
||||||
-- Generation Time: Feb 22, 2026 at 03:13 PM
|
-- Generation Time: Feb 27, 2026 at 05:46 AM
|
||||||
-- Server version: 11.8.6-MariaDB-log
|
-- Server version: 11.8.6-MariaDB-log
|
||||||
-- PHP Version: 8.5.3
|
-- PHP Version: 8.5.3
|
||||||
|
|
||||||
@@ -23,6 +23,20 @@ SET time_zone = "+00:00";
|
|||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `cdnfiles`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `cdnfiles` (
|
||||||
|
`id` bigint(20) NOT NULL,
|
||||||
|
`path` varchar(4096) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||||
|
`hash` char(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||||
|
`size` bigint(20) NOT NULL,
|
||||||
|
`mimeType` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `games`
|
-- Table structure for table `games`
|
||||||
--
|
--
|
||||||
@@ -61,20 +75,16 @@ CREATE TABLE `launcherupdates` (
|
|||||||
CREATE TABLE `launcherversionmanifest` (
|
CREATE TABLE `launcherversionmanifest` (
|
||||||
`id` varchar(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
`id` varchar(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||||
`displayName` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
`displayName` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||||
|
`versionName` text NOT NULL,
|
||||||
|
`downloads` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '\'\\\'{}\\\'\'',
|
||||||
`releaseDate` bigint(20) NOT NULL,
|
`releaseDate` bigint(20) NOT NULL,
|
||||||
`downloadUrlVersion` text NOT NULL,
|
|
||||||
`downloadUrls` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
|
||||||
`platforms` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
|
||||||
`executables` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
|
||||||
`hidden` tinyint(1) NOT NULL DEFAULT 1,
|
`hidden` tinyint(1) NOT NULL DEFAULT 1,
|
||||||
`game` bigint(20) NOT NULL DEFAULT 0,
|
`game` bigint(20) NOT NULL DEFAULT 0,
|
||||||
`place` bigint(20) NOT NULL DEFAULT 0,
|
`place` bigint(20) NOT NULL DEFAULT 0,
|
||||||
`sha512sums` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '[]',
|
|
||||||
`sizes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '[]',
|
|
||||||
`changelog` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
|
`changelog` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
|
||||||
`category` int(11) NOT NULL DEFAULT -1,
|
`category` int(11) NOT NULL DEFAULT -1,
|
||||||
`lastRevision` bigint(20) NOT NULL DEFAULT 0,
|
`lastRevision` bigint(20) NOT NULL DEFAULT 0,
|
||||||
`downloads` bigint(20) NOT NULL DEFAULT 0
|
`downloadCount` bigint(20) NOT NULL DEFAULT 0
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
@@ -142,6 +152,12 @@ CREATE TABLE `verifycodes` (
|
|||||||
-- Indexes for dumped tables
|
-- Indexes for dumped tables
|
||||||
--
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indexes for table `cdnfiles`
|
||||||
|
--
|
||||||
|
ALTER TABLE `cdnfiles`
|
||||||
|
ADD PRIMARY KEY (`id`);
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Indexes for table `games`
|
-- Indexes for table `games`
|
||||||
--
|
--
|
||||||
@@ -189,6 +205,12 @@ ALTER TABLE `verifycodes`
|
|||||||
-- AUTO_INCREMENT for dumped tables
|
-- AUTO_INCREMENT for dumped tables
|
||||||
--
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- AUTO_INCREMENT for table `cdnfiles`
|
||||||
|
--
|
||||||
|
ALTER TABLE `cdnfiles`
|
||||||
|
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- AUTO_INCREMENT for table `games`
|
-- AUTO_INCREMENT for table `games`
|
||||||
--
|
--
|
||||||
|
|||||||
+13
-10
@@ -12,11 +12,11 @@ import { handler as getVerifyCodeHandler } from './routes/get-verify-code'
|
|||||||
|
|
||||||
import { handler as canLoadClientHandler } from './routes/can-load-client'
|
import { handler as canLoadClientHandler } from './routes/can-load-client'
|
||||||
|
|
||||||
import { handler as launcherVersionsHandler } from './routes/launcher/versions'
|
import { handler as launcherVersionsHandler } from './routes/launcher/versions/get'
|
||||||
import { handler as launcherLatestHandler } from './routes/launcher/latest'
|
import { handler as launcherLatestHandler } from './routes/launcher/latest/get'
|
||||||
import { handler as launcherDownloadHandler } from './routes/launcher/download'
|
import { handler as launcherDownloadHandler } from './routes/launcher/download/get'
|
||||||
import { handler as launcherLoaderLatestHandler } from './routes/launcher/loader/latest'
|
import { handler as launcherLoaderLatestHandler } from './routes/launcher/loader/latest/get'
|
||||||
import { handler as launcherLoaderUpdateDataHandler } from './routes/launcher/loader/update-data'
|
import { handler as launcherLoaderUpdateDataHandler } from './routes/launcher/loader/update-data/get'
|
||||||
|
|
||||||
import { handler as accountLoginPostHandler } from './routes/account/login/post'
|
import { handler as accountLoginPostHandler } from './routes/account/login/post'
|
||||||
import { handler as accountRegisterPostHandler } from './routes/account/register/post'
|
import { handler as accountRegisterPostHandler } from './routes/account/register/post'
|
||||||
@@ -576,7 +576,12 @@ app.get('/launcher/versions', context => launcherVersionsHandler(context), {
|
|||||||
},
|
},
|
||||||
query: t.Object({
|
query: t.Object({
|
||||||
platform: t.Optional(t.String({ examples: ['windows', 'macos', 'linux'] })),
|
platform: t.Optional(t.String({ examples: ['windows', 'macos', 'linux'] })),
|
||||||
arch: t.Optional(t.String({ examples: ['x86_64', 'aarch64'] }))
|
arch: t.Optional(t.String({ examples: ['x86', 'x64', 'arm64'] })),
|
||||||
|
game: t.Optional(
|
||||||
|
t.String({
|
||||||
|
description: "Adding this will make it only show a Game ID's versions"
|
||||||
|
})
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
headers: t.Object({
|
headers: t.Object({
|
||||||
'x-forwarded-for': t.Optional(
|
'x-forwarded-for': t.Optional(
|
||||||
@@ -600,11 +605,9 @@ app.get('/launcher/latest', launcherLatestHandler, {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
app.get('/launcher/download', context => launcherDownloadHandler(context), {
|
app.get('/launcher/download', context => launcherDownloadHandler(context), {
|
||||||
detail: {
|
|
||||||
hide: true
|
|
||||||
},
|
|
||||||
query: t.Object({
|
query: t.Object({
|
||||||
id: t.String()
|
versionId: t.Optional(t.String({ hide: true })),
|
||||||
|
downloadId: t.String()
|
||||||
}),
|
}),
|
||||||
headers: t.Object({
|
headers: t.Object({
|
||||||
'x-forwarded-for': t.Optional(
|
'x-forwarded-for': t.Optional(
|
||||||
|
|||||||
+14
-7
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
bigint,
|
bigint,
|
||||||
boolean,
|
boolean,
|
||||||
|
char,
|
||||||
int,
|
int,
|
||||||
longtext,
|
longtext,
|
||||||
mysqlTable,
|
mysqlTable,
|
||||||
@@ -53,23 +54,21 @@ export const games = mysqlTable('games', {
|
|||||||
export const launcherVersionManifest = mysqlTable('launcherversionmanifest', {
|
export const launcherVersionManifest = mysqlTable('launcherversionmanifest', {
|
||||||
id: varchar('id', { length: 24 }).primaryKey().notNull(),
|
id: varchar('id', { length: 24 }).primaryKey().notNull(),
|
||||||
displayName: text('displayName').notNull(),
|
displayName: text('displayName').notNull(),
|
||||||
|
versionName: text('versionName').notNull(),
|
||||||
|
downloads: text('downloads').default('[]').notNull(),
|
||||||
releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(),
|
releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(),
|
||||||
downloadUrlVersion: text('downloadUrlVersion').notNull(),
|
|
||||||
downloadUrls: text('downloadUrls').notNull(),
|
|
||||||
platforms: text('platforms').notNull(),
|
|
||||||
executables: text('executables').notNull(),
|
|
||||||
hidden: boolean('hidden').default(false).notNull(),
|
hidden: boolean('hidden').default(false).notNull(),
|
||||||
game: bigint('game', { mode: 'number' })
|
game: bigint('game', { mode: 'number' })
|
||||||
.default(0)
|
.default(0)
|
||||||
.references(() => games.id)
|
.references(() => games.id)
|
||||||
.notNull(),
|
.notNull(),
|
||||||
place: bigint('place', { mode: 'number' }).default(0).notNull(),
|
place: bigint('place', { mode: 'number' }).default(0).notNull(),
|
||||||
sha512sums: text('sha512sums').default('[]').notNull(),
|
|
||||||
sizes: text('sizes').default('[]').notNull(),
|
|
||||||
changelog: text('changelog'),
|
changelog: text('changelog'),
|
||||||
category: int('category').notNull().default(-1),
|
category: int('category').notNull().default(-1),
|
||||||
lastRevision: bigint('lastRevision', { mode: 'number' }).notNull().default(0),
|
lastRevision: bigint('lastRevision', { mode: 'number' }).notNull().default(0),
|
||||||
downloads: bigint('downloads', { mode: 'number' }).notNull().default(0)
|
downloadCount: bigint('downloadCount', { mode: 'number' })
|
||||||
|
.notNull()
|
||||||
|
.default(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const verifyCodes = mysqlTable('verifycodes', {
|
export const verifyCodes = mysqlTable('verifycodes', {
|
||||||
@@ -94,6 +93,14 @@ export const resetCodes = mysqlTable('resetcodes', {
|
|||||||
type: int('type').notNull()
|
type: int('type').notNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const cdnFiles = mysqlTable('cdnfiles', {
|
||||||
|
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement().notNull(),
|
||||||
|
path: varchar('path', { length: 4096 }).notNull(),
|
||||||
|
hash: char('hash', { length: 128 }).notNull(),
|
||||||
|
size: bigint('size', { mode: 'number' }).notNull(),
|
||||||
|
mimeType: varchar('mimeType', { length: 255 })
|
||||||
|
})
|
||||||
|
|
||||||
// berrydashdatabase
|
// berrydashdatabase
|
||||||
|
|
||||||
export const berryDashUserData = mysqlTable('userdata', {
|
export const berryDashUserData = mysqlTable('userdata', {
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import { Context } from 'elysia'
|
|
||||||
import { launcherVersionManifest } from '../../lib/tables'
|
|
||||||
import { getDatabaseConnection } from '../../lib/util'
|
|
||||||
import { eq, sql } from 'drizzle-orm'
|
|
||||||
|
|
||||||
export const handler = async (context: Context) => {
|
|
||||||
const dbResult = getDatabaseConnection(0)
|
|
||||||
if (!dbResult) return null
|
|
||||||
const { connection, db } = dbResult
|
|
||||||
|
|
||||||
await db
|
|
||||||
.update(launcherVersionManifest)
|
|
||||||
.set({
|
|
||||||
downloads: sql`${launcherVersionManifest.downloads} + 1`
|
|
||||||
})
|
|
||||||
.where(eq(launcherVersionManifest.id, context.query.id))
|
|
||||||
|
|
||||||
connection.end()
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { Context } from 'elysia'
|
||||||
|
import { cdnFiles, launcherVersionManifest } from '../../../lib/tables'
|
||||||
|
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||||
|
import { eq, sql } from 'drizzle-orm'
|
||||||
|
|
||||||
|
export const handler = async (context: Context) => {
|
||||||
|
const dbResult = getDatabaseConnection(0)
|
||||||
|
if (!dbResult) return jsonResponse({ success: false, data: null }, 400)
|
||||||
|
const { connection, db } = dbResult
|
||||||
|
|
||||||
|
const gameId = context.query.gameId
|
||||||
|
const downloadId = Number(context.query.downloadId)
|
||||||
|
|
||||||
|
const result = await db
|
||||||
|
.select({ path: cdnFiles.path, hash: cdnFiles.hash })
|
||||||
|
.from(cdnFiles)
|
||||||
|
.where(eq(cdnFiles.id, downloadId))
|
||||||
|
.execute()
|
||||||
|
|
||||||
|
if (result.length != 1)
|
||||||
|
return jsonResponse({ success: false, data: null }, 400)
|
||||||
|
|
||||||
|
if (gameId)
|
||||||
|
await db
|
||||||
|
.update(launcherVersionManifest)
|
||||||
|
.set({
|
||||||
|
downloads: sql`${launcherVersionManifest.downloads} + 1`
|
||||||
|
})
|
||||||
|
.where(eq(launcherVersionManifest.id, gameId))
|
||||||
|
|
||||||
|
connection.end()
|
||||||
|
|
||||||
|
return jsonResponse({
|
||||||
|
success: true,
|
||||||
|
data: {
|
||||||
|
url: 'https://games-r2.lncvrt.xyz/' + result[0].path,
|
||||||
|
hash: result[0].hash
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { launcherUpdates } from '../../lib/tables'
|
import { launcherUpdates } from '../../../lib/tables'
|
||||||
import { desc, eq } from 'drizzle-orm'
|
import { desc, eq } from 'drizzle-orm'
|
||||||
import { getDatabaseConnection, jsonResponse } from '../../lib/util'
|
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||||
|
|
||||||
export const handler = async () => {
|
export const handler = async () => {
|
||||||
const dbResult = getDatabaseConnection(0)
|
const dbResult = getDatabaseConnection(0)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { loaderUpdates } from '../../../lib/tables'
|
import { loaderUpdates } from '../../../../lib/tables'
|
||||||
import { desc, eq } from 'drizzle-orm'
|
import { desc, eq } from 'drizzle-orm'
|
||||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
import { getDatabaseConnection, jsonResponse } from '../../../../lib/util'
|
||||||
|
|
||||||
export const handler = async () => {
|
export const handler = async () => {
|
||||||
const dbResult = getDatabaseConnection(0)
|
const dbResult = getDatabaseConnection(0)
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import { launcherUpdates } from '../../../lib/tables'
|
import { launcherUpdates } from '../../../../lib/tables'
|
||||||
import { desc, eq } from 'drizzle-orm'
|
import { desc, eq } from 'drizzle-orm'
|
||||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
import { getDatabaseConnection, jsonResponse } from '../../../../lib/util'
|
||||||
import { Context } from 'elysia'
|
import { Context } from 'elysia'
|
||||||
|
|
||||||
export const handler = async (context: Context) => {
|
export const handler = async (context: Context) => {
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
import { games, launcherVersionManifest } from '../../lib/tables'
|
|
||||||
import { asc, 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_64' || arch == 'x64') platString = 'windows'
|
|
||||||
else if (arch == 'aarch64' || arch == 'arm64')
|
|
||||||
platString = 'windows-arm64'
|
|
||||||
else {
|
|
||||||
connection.end()
|
|
||||||
return jsonResponse(
|
|
||||||
{
|
|
||||||
message: 'Unsupported architecture for Windows',
|
|
||||||
versions: null,
|
|
||||||
games: null
|
|
||||||
},
|
|
||||||
400
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (platform == 'linux') {
|
|
||||||
if (arch == 'x86_64' || arch == 'x64') platString = 'linux'
|
|
||||||
else {
|
|
||||||
connection.end()
|
|
||||||
return jsonResponse(
|
|
||||||
{
|
|
||||||
message: 'Unsupported architecture for Linux',
|
|
||||||
versions: null,
|
|
||||||
games: null
|
|
||||||
},
|
|
||||||
400
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (platform == 'macos') {
|
|
||||||
if (arch == 'x86_64' || arch == 'x64') platString = 'macos'
|
|
||||||
else if (arch == 'aarch64' || arch == 'arm64') platString = 'macos'
|
|
||||||
else {
|
|
||||||
connection.end()
|
|
||||||
return jsonResponse(
|
|
||||||
{
|
|
||||||
message: 'Unsupported architecture for macOS',
|
|
||||||
versions: null,
|
|
||||||
games: null
|
|
||||||
},
|
|
||||||
400
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (platform == 'android') platString = 'android'
|
|
||||||
else if (platform == 'ios') platString = 'ios'
|
|
||||||
else {
|
|
||||||
connection.end()
|
|
||||||
return jsonResponse(
|
|
||||||
{ message: 'Unsupported platform', versions: null, games: null },
|
|
||||||
400
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// const versionsRaw = await db
|
|
||||||
// .select({
|
|
||||||
// id: launcherVersionManifest.id,
|
|
||||||
// displayName: launcherVersionManifest.displayName,
|
|
||||||
// releaseDate: launcherVersionManifest.releaseDate,
|
|
||||||
// game: launcherVersionManifest.game,
|
|
||||||
// downloadUrlVersion: launcherVersionManifest.downloadUrlVersion,
|
|
||||||
// downloadUrls: launcherVersionManifest.downloadUrls,
|
|
||||||
// platforms: launcherVersionManifest.platforms,
|
|
||||||
// executables: launcherVersionManifest.executables,
|
|
||||||
// sha512sums: launcherVersionManifest.sha512sums,
|
|
||||||
// sizes: launcherVersionManifest.sizes,
|
|
||||||
// place: launcherVersionManifest.place,
|
|
||||||
// changelog: launcherVersionManifest.changelog,
|
|
||||||
// category: launcherVersionManifest.category,
|
|
||||||
// lastRevision: launcherVersionManifest.lastRevision
|
|
||||||
// })
|
|
||||||
// .from(launcherVersionManifest)
|
|
||||||
// .where(eq(launcherVersionManifest.hidden, false))
|
|
||||||
// .orderBy(
|
|
||||||
// asc(launcherVersionManifest.game),
|
|
||||||
// desc(launcherVersionManifest.place)
|
|
||||||
// )
|
|
||||||
// .execute()
|
|
||||||
|
|
||||||
// const versions = versionsRaw
|
|
||||||
// .map(v => ({
|
|
||||||
// ...v,
|
|
||||||
// downloadUrls: JSON.parse(
|
|
||||||
// v.downloadUrls.replaceAll('%version%', v.downloadUrlVersion)
|
|
||||||
// ),
|
|
||||||
// platforms: JSON.parse(v.platforms),
|
|
||||||
// executables: JSON.parse(v.executables),
|
|
||||||
// sha512sums: JSON.parse(v.sha512sums),
|
|
||||||
// sizes: JSON.parse(v.sizes),
|
|
||||||
// downloadUrlVersion: undefined,
|
|
||||||
// downloadUrl: undefined as string | undefined,
|
|
||||||
// executable: undefined as string | undefined,
|
|
||||||
// sha512sum: undefined as string | undefined,
|
|
||||||
// size: undefined as number | undefined,
|
|
||||||
// wine: undefined as boolean | undefined
|
|
||||||
// }))
|
|
||||||
// .filter(v => {
|
|
||||||
// delete v.downloadUrlVersion
|
|
||||||
// if (showAll || !platString) {
|
|
||||||
// delete v.downloadUrl
|
|
||||||
// delete v.executable
|
|
||||||
// delete v.sha512sum
|
|
||||||
// delete v.size
|
|
||||||
// delete v.wine
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// let i = v.platforms.indexOf(platString)
|
|
||||||
// if (i !== -1) {
|
|
||||||
// v.downloadUrl = v.downloadUrls[i]
|
|
||||||
// v.executable = v.executables[i]
|
|
||||||
// v.sha512sum = v.sha512sums[i]
|
|
||||||
// v.size = v.sizes[i]
|
|
||||||
// delete v.downloadUrls
|
|
||||||
// delete v.platforms
|
|
||||||
// delete v.executables
|
|
||||||
// delete v.sha512sums
|
|
||||||
// delete v.sizes
|
|
||||||
// delete v.wine
|
|
||||||
// return true
|
|
||||||
// } else if (platString == 'linux') {
|
|
||||||
// i = v.platforms.indexOf('windows')
|
|
||||||
// if (i !== -1) {
|
|
||||||
// v.downloadUrl = v.downloadUrls[i]
|
|
||||||
// v.executable = v.executables[i]
|
|
||||||
// v.sha512sum = v.sha512sums[i]
|
|
||||||
// v.size = v.sizes[i]
|
|
||||||
// v.wine = true
|
|
||||||
// delete v.downloadUrls
|
|
||||||
// delete v.platforms
|
|
||||||
// delete v.executables
|
|
||||||
// delete v.sha512sums
|
|
||||||
// delete v.sizes
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return false
|
|
||||||
// })
|
|
||||||
|
|
||||||
// const gamesListRaw = await db.select().from(games).execute()
|
|
||||||
|
|
||||||
// const gamesList = gamesListRaw.map(v => ({
|
|
||||||
// ...v,
|
|
||||||
// categoryNames: JSON.parse(v.categoryNames)
|
|
||||||
// }))
|
|
||||||
|
|
||||||
connection.end()
|
|
||||||
|
|
||||||
// const seenGames = new Set<number>()
|
|
||||||
// const finalVersions = versions.filter(v => {
|
|
||||||
// if (platString !== 'android' && platString !== 'ios') return true
|
|
||||||
// if (seenGames.has(v.game)) return false
|
|
||||||
// seenGames.add(v.game)
|
|
||||||
// return true
|
|
||||||
// })
|
|
||||||
|
|
||||||
return jsonResponse({ versions: [], games: [] })
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
import { games, launcherVersionManifest } from '../../../lib/tables'
|
||||||
|
import { and, asc, 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
|
||||||
|
const arch = context.query.arch
|
||||||
|
const game = context.query.game
|
||||||
|
|
||||||
|
let showAll = false
|
||||||
|
if (!platform || !arch) showAll = true
|
||||||
|
|
||||||
|
let platformsToShow: string[] | null = null
|
||||||
|
if (!showAll) {
|
||||||
|
if (platform == 'windows') {
|
||||||
|
if (arch == 'x86') platformsToShow = ['windows-x86']
|
||||||
|
else if (arch == 'x86_64' || arch == 'x64')
|
||||||
|
platformsToShow = ['windows-x86', 'windows-x64']
|
||||||
|
else if (arch == 'aarch64' || arch == 'arm64')
|
||||||
|
platformsToShow = ['windows-arm64']
|
||||||
|
else {
|
||||||
|
connection.end()
|
||||||
|
return jsonResponse(
|
||||||
|
{
|
||||||
|
message: 'Unsupported architecture for Windows',
|
||||||
|
versions: null,
|
||||||
|
games: null
|
||||||
|
},
|
||||||
|
400
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (platform == 'linux') {
|
||||||
|
if (arch == 'x86') platformsToShow = ['linux-x64']
|
||||||
|
else if (arch == 'x86_64' || arch == 'x64')
|
||||||
|
platformsToShow = ['linux-x86', 'linux-x64']
|
||||||
|
else if (arch == 'aarch64' || arch == 'arm64')
|
||||||
|
platformsToShow = ['linux-arm64']
|
||||||
|
else {
|
||||||
|
connection.end()
|
||||||
|
return jsonResponse(
|
||||||
|
{
|
||||||
|
message: 'Unsupported architecture for Linux',
|
||||||
|
versions: null,
|
||||||
|
games: null
|
||||||
|
},
|
||||||
|
400
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (platform == 'macos') {
|
||||||
|
if (arch == 'x86_64' || arch == 'x64')
|
||||||
|
platformsToShow = ['macos-x64', 'macos-universal']
|
||||||
|
else if (arch == 'aarch64' || arch == 'arm64')
|
||||||
|
platformsToShow = ['macos-arm64', 'macos-universal']
|
||||||
|
else {
|
||||||
|
connection.end()
|
||||||
|
return jsonResponse(
|
||||||
|
{
|
||||||
|
message: 'Unsupported architecture for macOS',
|
||||||
|
versions: null,
|
||||||
|
games: null
|
||||||
|
},
|
||||||
|
400
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (platform == 'android') platformsToShow = ['android']
|
||||||
|
else if (platform == 'ios') platformsToShow = ['ios']
|
||||||
|
else {
|
||||||
|
connection.end()
|
||||||
|
return jsonResponse(
|
||||||
|
{ message: 'Unsupported platform', versions: null, games: null },
|
||||||
|
400
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionsRaw = await db
|
||||||
|
.select({
|
||||||
|
id: launcherVersionManifest.id,
|
||||||
|
displayName: launcherVersionManifest.displayName,
|
||||||
|
releaseDate: launcherVersionManifest.releaseDate,
|
||||||
|
game: launcherVersionManifest.game,
|
||||||
|
versionName: launcherVersionManifest.versionName,
|
||||||
|
downloads: launcherVersionManifest.downloads,
|
||||||
|
place: launcherVersionManifest.place,
|
||||||
|
changelog: launcherVersionManifest.changelog,
|
||||||
|
category: launcherVersionManifest.category,
|
||||||
|
lastRevision: launcherVersionManifest.lastRevision
|
||||||
|
})
|
||||||
|
.from(launcherVersionManifest)
|
||||||
|
.where(
|
||||||
|
game != null
|
||||||
|
? and(
|
||||||
|
eq(launcherVersionManifest.game, Number(game)),
|
||||||
|
eq(launcherVersionManifest.hidden, false)
|
||||||
|
)
|
||||||
|
: eq(launcherVersionManifest.hidden, false)
|
||||||
|
)
|
||||||
|
.orderBy(
|
||||||
|
asc(launcherVersionManifest.game),
|
||||||
|
desc(launcherVersionManifest.place)
|
||||||
|
)
|
||||||
|
.execute()
|
||||||
|
|
||||||
|
const versions = versionsRaw
|
||||||
|
.map(v => {
|
||||||
|
const downloads: Record<string, number> = JSON.parse(v.downloads)
|
||||||
|
|
||||||
|
let download: string | undefined = undefined
|
||||||
|
if (platformsToShow) {
|
||||||
|
for (const key of platformsToShow) {
|
||||||
|
if (key in downloads) download = key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { versionName, ...rest } = v
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
downloads: platformsToShow ? undefined : downloads,
|
||||||
|
download: platformsToShow
|
||||||
|
? download
|
||||||
|
? downloads[download]
|
||||||
|
: undefined
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(v => {
|
||||||
|
if (!platformsToShow) return true
|
||||||
|
return v.download !== undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!game) {
|
||||||
|
const gamesListRaw = await db.select().from(games).execute()
|
||||||
|
const gamesList = gamesListRaw.map(v => ({
|
||||||
|
...v,
|
||||||
|
categoryNames: JSON.parse(v.categoryNames)
|
||||||
|
}))
|
||||||
|
|
||||||
|
connection.end()
|
||||||
|
|
||||||
|
return jsonResponse({ versions: versions, games: gamesList })
|
||||||
|
} else return jsonResponse(versions)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user