Add an endpoint for getting the latest berry dash version number
This commit is contained in:
@@ -11,6 +11,8 @@ import { handler as launcherLatestHandler } from './routes/launcher/latest'
|
|||||||
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'
|
||||||
|
|
||||||
|
import { handler as berryDashLatestVersionGetHandler } from './routes/berrydash/latest-version/get'
|
||||||
|
|
||||||
import { handler as berrydashLeaderboardGetHandler } from './routes/berrydash/leaderboard/get'
|
import { handler as berrydashLeaderboardGetHandler } from './routes/berrydash/leaderboard/get'
|
||||||
|
|
||||||
import { handler as berrydashProfileGetHandler } from './routes/berrydash/profile/get'
|
import { handler as berrydashProfileGetHandler } from './routes/berrydash/profile/get'
|
||||||
@@ -103,6 +105,12 @@ app.get(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
app.get('/berrydash/latest-version', berryDashLatestVersionGetHandler, {
|
||||||
|
detail: {
|
||||||
|
description: 'The endpoint for getting the latest berry dash version.',
|
||||||
|
tags: ['Berry Dash']
|
||||||
|
}
|
||||||
|
})
|
||||||
app.get(
|
app.get(
|
||||||
'/berrydash/leaderboards/score',
|
'/berrydash/leaderboards/score',
|
||||||
context => berrydashLeaderboardGetHandler(context, 0),
|
context => berrydashLeaderboardGetHandler(context, 0),
|
||||||
|
|||||||
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