Add downloads count

This commit is contained in:
2026-02-03 17:41:03 -07:00
parent 4cc0ff910d
commit 294339a39e
4 changed files with 42 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/ -- https://www.phpmyadmin.net/
-- --
-- Host: localhost -- 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 -- Server version: 12.1.2-MariaDB
-- PHP Version: 8.5.2 -- PHP Version: 8.5.2
@@ -72,7 +72,8 @@ CREATE TABLE `launcherversionmanifest` (
`sizes` 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
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- -------------------------------------------------------- -- --------------------------------------------------------

View File

@@ -14,6 +14,7 @@ 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'
import { handler as launcherLatestHandler } from './routes/launcher/latest' 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 launcherLoaderLatestHandler } from './routes/launcher/loader/latest'
import { handler as launcherLoaderUpdateDataHandler } from './routes/launcher/loader/update-data' 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, { app.get('/launcher/loader/latest', launcherLoaderLatestHandler, {
detail: { detail: {
description: description:

View File

@@ -66,7 +66,8 @@ export const launcherVersionManifest = mysqlTable('launcherversionmanifest', {
sizes: text('sizes').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)
}) })
export const verifyCodes = mysqlTable('verifycodes', { export const verifyCodes = mysqlTable('verifycodes', {

View File

@@ -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
}