diff --git a/database/lncvrtgames.sql b/database/lncvrtgames.sql index 6be8f7c..5ccf193 100644 --- a/database/lncvrtgames.sql +++ b/database/lncvrtgames.sql @@ -3,7 +3,7 @@ -- https://www.phpmyadmin.net/ -- -- Host: localhost --- Generation Time: Jan 31, 2026 at 08:57 PM +-- Generation Time: Feb 04, 2026 at 12:40 AM -- Server version: 12.1.2-MariaDB -- PHP Version: 8.5.2 @@ -72,7 +72,8 @@ CREATE TABLE `launcherversionmanifest` ( `sizes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '[]', `changelog` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, `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 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED; -- -------------------------------------------------------- diff --git a/src/index.ts b/src/index.ts index 2c47164..10ecaa5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,7 @@ import { handler as canLoadClientHandler } from './routes/can-load-client' import { handler as launcherVersionsHandler } from './routes/launcher/versions' import { handler as launcherLatestHandler } from './routes/launcher/latest' +import { handler as launcherDownloadHandler } from './routes/launcher/download' import { handler as launcherLoaderLatestHandler } from './routes/launcher/loader/latest' import { handler as launcherLoaderUpdateDataHandler } from './routes/launcher/loader/update-data' @@ -551,6 +552,21 @@ app.get('/launcher/latest', launcherLatestHandler, { ) }) }) +app.get('/launcher/download', context => launcherDownloadHandler(context), { + detail: { + hide: true + }, + query: t.Object({ + id: t.String() + }), + headers: t.Object({ + 'x-forwarded-for': t.Optional( + t.String({ + hide: true + }) + ) + }) +}) app.get('/launcher/loader/latest', launcherLoaderLatestHandler, { detail: { description: diff --git a/src/lib/tables.ts b/src/lib/tables.ts index e924f8b..a8c5883 100644 --- a/src/lib/tables.ts +++ b/src/lib/tables.ts @@ -66,7 +66,8 @@ export const launcherVersionManifest = mysqlTable('launcherversionmanifest', { sizes: text('sizes').default('[]').notNull(), changelog: text('changelog'), 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) }) export const verifyCodes = mysqlTable('verifycodes', { diff --git a/src/routes/launcher/download.ts b/src/routes/launcher/download.ts new file mode 100644 index 0000000..7aed1b1 --- /dev/null +++ b/src/routes/launcher/download.ts @@ -0,0 +1,21 @@ +import { Context } from 'elysia' +import { launcherVersionManifest } from '../../lib/tables' +import { getDatabaseConnection } from '../../lib/util' +import { eq, sql } from 'drizzle-orm' + +export async function handler (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 +}