Fix db not closing
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import mysql from 'mysql2'
|
||||
import { drizzle } from 'drizzle-orm/mysql2'
|
||||
import { Connection } from 'mysql2/typings/mysql/lib/Connection'
|
||||
|
||||
export function jsonResponse (data: any, status = 200) {
|
||||
return new Response(JSON.stringify(data, null, 2), {
|
||||
@@ -17,6 +16,7 @@ export function getDatabaseConnection () {
|
||||
password: process.env.DB_PASS ?? '',
|
||||
database: process.env.DB_NAME ?? ''
|
||||
})
|
||||
const db = drizzle(connection)
|
||||
|
||||
return drizzle(connection)
|
||||
return { connection, db }
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { desc, eq } from 'drizzle-orm'
|
||||
import { getDatabaseConnection } from '../../lib/util'
|
||||
|
||||
export async function handler () {
|
||||
const db = getDatabaseConnection()
|
||||
const { connection, db } = getDatabaseConnection()
|
||||
|
||||
const version = await db
|
||||
.select({
|
||||
@@ -14,5 +14,7 @@ export async function handler () {
|
||||
.orderBy(desc(launcherUpdates.place))
|
||||
.limit(1)
|
||||
|
||||
connection.end()
|
||||
|
||||
return version[0].id
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
|
||||
import { Context } from 'elysia'
|
||||
|
||||
export async function handler (context: Context) {
|
||||
const db = getDatabaseConnection()
|
||||
const { connection, db } = getDatabaseConnection()
|
||||
|
||||
const platform = context.query.platform as string | undefined
|
||||
const arch = context.query.arch as string | undefined
|
||||
@@ -20,6 +20,7 @@ export async function handler (context: Context) {
|
||||
if (arch == 'x86_64') platString = 'windows'
|
||||
else if (arch == 'aarch64') platString = 'windows-arm64'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{ error: 'Unsupported architecture for Windows' },
|
||||
400
|
||||
@@ -28,6 +29,7 @@ export async function handler (context: Context) {
|
||||
} else if (platform == 'linux') {
|
||||
if (arch == 'x86_64') platString = 'linux'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{ error: 'Unsupported architecture for Linux' },
|
||||
400
|
||||
@@ -37,12 +39,14 @@ export async function handler (context: Context) {
|
||||
if (arch == 'x86_64') platString = 'macos-intel'
|
||||
else if (arch == 'aarch64') platString = 'macos-silicon'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{ error: 'Unsupported architecture for macOS' },
|
||||
400
|
||||
)
|
||||
}
|
||||
} else {
|
||||
connection.end()
|
||||
return jsonResponse({ error: 'Unsupported platform' }, 400)
|
||||
}
|
||||
}
|
||||
@@ -88,5 +92,7 @@ export async function handler (context: Context) {
|
||||
return false
|
||||
})
|
||||
|
||||
connection.end()
|
||||
|
||||
return jsonResponse(versions[0])
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { getDatabaseConnection, jsonResponse } from '../../lib/util'
|
||||
import { Context } from 'elysia'
|
||||
|
||||
export async function handler (context: Context) {
|
||||
const db = getDatabaseConnection()
|
||||
const { connection, db } = getDatabaseConnection()
|
||||
|
||||
const platform = context.query.platform as string | undefined
|
||||
const arch = context.query.arch as string | undefined
|
||||
@@ -20,6 +20,7 @@ export async function handler (context: Context) {
|
||||
if (arch == 'x86_64') platString = 'windows'
|
||||
else if (arch == 'aarch64') platString = 'windows-arm64'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
message: 'Unsupported architecture for Windows',
|
||||
@@ -32,6 +33,7 @@ export async function handler (context: Context) {
|
||||
} else if (platform == 'linux') {
|
||||
if (arch == 'x86_64') platString = 'linux'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
message: 'Unsupported architecture for Linux',
|
||||
@@ -44,6 +46,7 @@ export async function handler (context: Context) {
|
||||
} else if (platform == 'macos') {
|
||||
if (arch == 'x86_64' || arch == 'aarch64') platString = 'macos'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{
|
||||
message: 'Unsupported architecture for macOS',
|
||||
@@ -56,6 +59,7 @@ export async function handler (context: Context) {
|
||||
} else if (platform == 'android') platString = 'android'
|
||||
else if (platform == 'ios') platString = 'ios'
|
||||
else {
|
||||
connection.end()
|
||||
return jsonResponse(
|
||||
{ message: 'Unsupported platform', versions: null, games: null },
|
||||
400
|
||||
@@ -119,5 +123,7 @@ export async function handler (context: Context) {
|
||||
|
||||
const games = await db.select().from(launcherGames).execute()
|
||||
|
||||
connection.end()
|
||||
|
||||
return jsonResponse({ versions, games })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user