Change database a bit
This commit is contained in:
@@ -32,7 +32,14 @@ export const launcherUpdates = mysqlTable('launcherupdates', {
|
||||
sha512sums: text('sha512sums').default('[]').notNull()
|
||||
})
|
||||
|
||||
export const launcherGames = mysqlTable('launchergames', {
|
||||
export const loaderUpdates = mysqlTable('loaderupdates', {
|
||||
id: varchar('id', { length: 24 }).primaryKey().notNull(),
|
||||
releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(),
|
||||
hidden: boolean('hidden').default(false).notNull(),
|
||||
place: int('place').default(0).notNull()
|
||||
})
|
||||
|
||||
export const games = mysqlTable('games', {
|
||||
id: int('id').primaryKey().autoincrement().notNull(),
|
||||
name: text('name').notNull(),
|
||||
official: boolean('official').default(false).notNull(),
|
||||
@@ -40,7 +47,7 @@ export const launcherGames = mysqlTable('launchergames', {
|
||||
developer: varchar('developer', { length: 32 })
|
||||
})
|
||||
|
||||
export const launcherVersions = mysqlTable('launcherversions', {
|
||||
export const launcherVersionManifest = mysqlTable('launcherversionmanifest', {
|
||||
id: varchar('id', { length: 24 }).primaryKey().notNull(),
|
||||
versionName: text('versionName').notNull(),
|
||||
releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(),
|
||||
@@ -50,7 +57,7 @@ export const launcherVersions = mysqlTable('launcherversions', {
|
||||
hidden: boolean('hidden').default(false).notNull(),
|
||||
game: int('game')
|
||||
.default(0)
|
||||
.references(() => launcherGames.id)
|
||||
.references(() => games.id)
|
||||
.notNull(),
|
||||
place: int('place').default(0).notNull(),
|
||||
sha512sums: text('sha512sums').default('[]').notNull(),
|
||||
|
||||
@@ -1,3 +1,23 @@
|
||||
import { loaderUpdates } from '../../../lib/tables'
|
||||
import { desc, eq } from 'drizzle-orm'
|
||||
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||
|
||||
export async function handler () {
|
||||
return '1.0.2'
|
||||
const dbResult = getDatabaseConnection(0)
|
||||
if (!dbResult)
|
||||
return jsonResponse({ error: 'Failed to connect to database' }, 500)
|
||||
const { connection, db } = dbResult
|
||||
|
||||
const version = await db
|
||||
.select({
|
||||
id: loaderUpdates.id
|
||||
})
|
||||
.from(loaderUpdates)
|
||||
.where(eq(loaderUpdates.hidden, false))
|
||||
.orderBy(desc(loaderUpdates.place))
|
||||
.limit(1)
|
||||
|
||||
connection.end()
|
||||
|
||||
return version[0].id
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { launcherGames, launcherVersions } from '../../lib/tables'
|
||||
import { games, launcherVersionManifest } from '../../lib/tables'
|
||||
import { asc, desc, eq } from 'drizzle-orm'
|
||||
import { getDatabaseConnection, jsonResponse } from '../../lib/util'
|
||||
import { Context } from 'elysia'
|
||||
@@ -72,20 +72,23 @@ export async function handler (context: Context) {
|
||||
|
||||
const versionsRaw = await db
|
||||
.select({
|
||||
id: launcherVersions.id,
|
||||
versionName: launcherVersions.versionName,
|
||||
releaseDate: launcherVersions.releaseDate,
|
||||
game: launcherVersions.game,
|
||||
downloadUrls: launcherVersions.downloadUrls,
|
||||
platforms: launcherVersions.platforms,
|
||||
executables: launcherVersions.executables,
|
||||
sha512sums: launcherVersions.sha512sums,
|
||||
sizes: launcherVersions.sizes,
|
||||
place: launcherVersions.place
|
||||
id: launcherVersionManifest.id,
|
||||
versionName: launcherVersionManifest.versionName,
|
||||
releaseDate: launcherVersionManifest.releaseDate,
|
||||
game: launcherVersionManifest.game,
|
||||
downloadUrls: launcherVersionManifest.downloadUrls,
|
||||
platforms: launcherVersionManifest.platforms,
|
||||
executables: launcherVersionManifest.executables,
|
||||
sha512sums: launcherVersionManifest.sha512sums,
|
||||
sizes: launcherVersionManifest.sizes,
|
||||
place: launcherVersionManifest.place
|
||||
})
|
||||
.from(launcherVersions)
|
||||
.where(eq(launcherVersions.hidden, false))
|
||||
.orderBy(asc(launcherVersions.game), desc(launcherVersions.place))
|
||||
.from(launcherVersionManifest)
|
||||
.where(eq(launcherVersionManifest.hidden, false))
|
||||
.orderBy(
|
||||
asc(launcherVersionManifest.game),
|
||||
desc(launcherVersionManifest.place)
|
||||
)
|
||||
.execute()
|
||||
|
||||
const versions = versionsRaw
|
||||
@@ -125,9 +128,9 @@ export async function handler (context: Context) {
|
||||
return false
|
||||
})
|
||||
|
||||
const games = await db.select().from(launcherGames).execute()
|
||||
const gameList = await db.select().from(games).execute()
|
||||
|
||||
connection.end()
|
||||
|
||||
return jsonResponse({ versions, games })
|
||||
return jsonResponse({ versions, gameList })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user