Add an endpoint for getting the latest berry dash version number
This commit is contained in:
30
src/routes/berrydash/latest-version/get.ts
Normal file
30
src/routes/berrydash/latest-version/get.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { games, launcherVersionManifest } from '../../../lib/tables'
|
||||
import { and, asc, desc, eq } from 'drizzle-orm'
|
||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||
import { Context } from 'elysia'
|
||||
|
||||
export async function handler (context: Context) {
|
||||
const dbResult = getDatabaseConnection(0)
|
||||
if (!dbResult)
|
||||
return jsonResponse({ error: 'Failed to connect to database' }, 500)
|
||||
const { connection, db } = dbResult
|
||||
|
||||
const version = await db
|
||||
.select({
|
||||
versionName: launcherVersionManifest.versionName
|
||||
})
|
||||
.from(launcherVersionManifest)
|
||||
.where(
|
||||
and(
|
||||
eq(launcherVersionManifest.hidden, false),
|
||||
eq(launcherVersionManifest.game, 1)
|
||||
)
|
||||
)
|
||||
.orderBy(desc(launcherVersionManifest.place))
|
||||
.limit(1)
|
||||
.execute()
|
||||
|
||||
connection.end()
|
||||
|
||||
return version[0] ? version[0].versionName : '-1'
|
||||
}
|
||||
Reference in New Issue
Block a user