Count downloads for mods & fix game download count
This commit is contained in:
2 files changed
+14
-4
No files matched your search
@@ -1014,6 +1014,7 @@ app.get('/launcher/latest', launcherLatestHandler, {
|
|||||||
app.get('/launcher/download', context => launcherDownloadHandler(context), {
|
app.get('/launcher/download', context => launcherDownloadHandler(context), {
|
||||||
query: t.Object({
|
query: t.Object({
|
||||||
versionId: t.Optional(t.String({ hide: true })),
|
versionId: t.Optional(t.String({ hide: true })),
|
||||||
|
modId: t.Optional(t.String({ hide: true })),
|
||||||
downloadId: t.String()
|
downloadId: t.String()
|
||||||
}),
|
}),
|
||||||
headers: t.Object({
|
headers: t.Object({
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Context } from 'elysia'
|
import { Context } from 'elysia'
|
||||||
import { cdnFiles, launcherVersionManifest } from '../../../lib/tables'
|
import { cdnFiles, launcherVersionManifest, mods } from '../../../lib/tables'
|
||||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||||
import { eq, sql } from 'drizzle-orm'
|
import { eq, sql } from 'drizzle-orm'
|
||||||
|
|
||||||
@@ -8,7 +8,8 @@ export const handler = async (context: Context) => {
|
|||||||
if (!dbResult) return jsonResponse({ success: false, data: null }, 400)
|
if (!dbResult) return jsonResponse({ success: false, data: null }, 400)
|
||||||
const { connection, db } = dbResult
|
const { connection, db } = dbResult
|
||||||
|
|
||||||
const gameId = context.query.gameId
|
const versionId = context.query.versionId
|
||||||
|
const modId = context.query.modId
|
||||||
const downloadId = Number(context.query.downloadId)
|
const downloadId = Number(context.query.downloadId)
|
||||||
|
|
||||||
const result = await db
|
const result = await db
|
||||||
@@ -20,13 +21,21 @@ export const handler = async (context: Context) => {
|
|||||||
if (result.length != 1)
|
if (result.length != 1)
|
||||||
return jsonResponse({ success: false, data: null }, 400)
|
return jsonResponse({ success: false, data: null }, 400)
|
||||||
|
|
||||||
if (gameId)
|
if (versionId)
|
||||||
await db
|
await db
|
||||||
.update(launcherVersionManifest)
|
.update(launcherVersionManifest)
|
||||||
.set({
|
.set({
|
||||||
downloads: sql`${launcherVersionManifest.downloads} + 1`
|
downloads: sql`${launcherVersionManifest.downloads} + 1`
|
||||||
})
|
})
|
||||||
.where(eq(launcherVersionManifest.id, gameId))
|
.where(eq(launcherVersionManifest.id, versionId))
|
||||||
|
|
||||||
|
if (modId)
|
||||||
|
await db
|
||||||
|
.update(mods)
|
||||||
|
.set({
|
||||||
|
downloadCount: sql`${mods.downloadCount} + 1`
|
||||||
|
})
|
||||||
|
.where(eq(mods.id, Number(modId)))
|
||||||
|
|
||||||
connection.end()
|
connection.end()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user