49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { Context } from 'elysia'
|
|
import { files, launcherVersionManifest, mods } 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 versionId = context.query.versionId
|
|
const modId = context.query.modId
|
|
const downloadId = Number(context.query.downloadId)
|
|
|
|
const result = await db
|
|
.select({ path: files.path, hash: files.hash, host: files.host })
|
|
.from(files)
|
|
.where(eq(files.id, downloadId))
|
|
.execute()
|
|
|
|
if (result.length != 1)
|
|
return jsonResponse({ success: false, data: null }, 400)
|
|
|
|
if (versionId)
|
|
await db
|
|
.update(launcherVersionManifest)
|
|
.set({ downloadCount: sql`${launcherVersionManifest.downloadCount} + 1` })
|
|
.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()
|
|
|
|
return jsonResponse({
|
|
success: true,
|
|
data: {
|
|
url:
|
|
result[0].host == 1
|
|
? 'https://github.com/' + result[0].path
|
|
: 'https://archive.org/download/lncvrt-games-archive/' + result[0].path,
|
|
hash: result[0].hash
|
|
}
|
|
})
|
|
}
|