Add downloads count
This commit is contained in:
@@ -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;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
16
src/index.ts
16
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:
|
||||
|
||||
@@ -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', {
|
||||
|
||||
21
src/routes/launcher/download.ts
Normal file
21
src/routes/launcher/download.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user