I don't know why I didn't just do this from the start

This commit is contained in:
2026-02-02 20:04:46 -07:00
parent 14b6522af8
commit fbf5a46e74
16 changed files with 122 additions and 26 deletions

View File

@@ -126,7 +126,11 @@ app.ws('/ws', {
db0, db0,
ip ip
) )
if (!authResult.valid) return if (!authResult.valid) {
connection0.end()
connection1.end()
return
}
const userId = authResult.id const userId = authResult.id
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
@@ -183,7 +187,11 @@ app.ws('/ws', {
db0, db0,
ip ip
) )
if (!authResult.valid) return if (!authResult.valid) {
connection0.end()
connection1.end()
return
}
const userId = authResult.id const userId = authResult.id
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
@@ -319,7 +327,11 @@ app.ws('/ws', {
db0, db0,
ip ip
) )
if (!authResult.valid) return if (!authResult.valid) {
connection0.end()
connection1.end()
return
}
const userId = authResult.id const userId = authResult.id
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
@@ -341,7 +353,11 @@ app.ws('/ws', {
.where(eq(berryDashUserData.id, userId)) .where(eq(berryDashUserData.id, userId))
.limit(1) .limit(1)
.execute() .execute()
if (!userData[0]) return if (!userData[0]) {
connection0.end()
connection1.end()
return
}
const userInfo = await db0 const userInfo = await db0
.select({ username: users.username }) .select({ username: users.username })
@@ -349,7 +365,11 @@ app.ws('/ws', {
.where(eq(users.id, userId)) .where(eq(users.id, userId))
.limit(1) .limit(1)
.execute() .execute()
if (!userInfo[0]) return if (!userInfo[0]) {
connection0.end()
connection1.end()
return
}
let savedata = JSON.parse(userData[0].saveData) let savedata = JSON.parse(userData[0].saveData)

View File

@@ -69,5 +69,7 @@ export async function handler (context: Context) {
.where(eq(users.id, userId)) .where(eq(users.id, userId))
.execute() .execute()
connection0.end()
return jsonResponse({ success: true, message: null, data: token }) return jsonResponse({ success: true, message: null, data: token })
} }

View File

@@ -63,5 +63,7 @@ export async function handler (context: Context) {
.where(eq(users.id, userId)) .where(eq(users.id, userId))
.execute() .execute()
connection0.end()
return jsonResponse({ success: true, message: null, data: token }) return jsonResponse({ success: true, message: null, data: token })
} }

View File

@@ -40,7 +40,10 @@ export async function handler (context: Context) {
) )
} }
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
if (!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))) if (
!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))
) {
connection0.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -51,6 +54,7 @@ export async function handler (context: Context) {
}, },
400 400
) )
}
const notFound = `You requested information about your account. Unfortunately, we were unable to find your account associated with this email. This is caused by either an incorrect email provided during signup, or this email not owning a Lncvrt Games account.` const notFound = `You requested information about your account. Unfortunately, we were unable to find your account associated with this email. This is caused by either an incorrect email provided during signup, or this email not owning a Lncvrt Games account.`

View File

@@ -38,7 +38,10 @@ export async function handler (context: Context) {
400 400
) )
} }
if (!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))) if (
!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))
) {
connection0.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -49,6 +52,7 @@ export async function handler (context: Context) {
}, },
400 400
) )
}
const notFound = `You requested information about your account, your username\n\nUnfortunately, we were unable to find your username associated with this email. This is caused by either an incorrect email provided during signup, or this email not owning a Lncvrt Games account.` const notFound = `You requested information about your account, your username\n\nUnfortunately, we were unable to find your username associated with this email. This is caused by either an incorrect email provided during signup, or this email not owning a Lncvrt Games account.`

View File

@@ -33,8 +33,10 @@ export async function handler (context: Context) {
.where(eq(users.username, body.username)) .where(eq(users.username, body.username))
.limit(1) .limit(1)
.execute() .execute()
if (!user[0]) {
connection0.end() connection0.end()
if (!user[0])
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -43,9 +45,7 @@ export async function handler (context: Context) {
}, },
401 401
) )
} if (!(await bcrypt.compare(body.password, user[0].password)))
if (!(await bcrypt.compare(body.password, user[0].password))) {
connection0.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -54,7 +54,6 @@ export async function handler (context: Context) {
}, },
401 401
) )
}
return jsonResponse({ return jsonResponse({
success: true, success: true,

View File

@@ -44,7 +44,11 @@ export async function handler (context: Context) {
) )
} }
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
if (!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))) if (
!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))
) {
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -55,6 +59,7 @@ export async function handler (context: Context) {
}, },
400 400
) )
}
if (!/^[a-zA-Z0-9]{3,16}$/.test(body.username)) { if (!/^[a-zA-Z0-9]{3,16}$/.test(body.username)) {
connection0.end() connection0.end()
@@ -117,6 +122,9 @@ export async function handler (context: Context) {
}) })
.execute() .execute()
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ {
success: true, success: true,

View File

@@ -52,7 +52,10 @@ export async function handler (context: Context) {
) )
} }
if (!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))) if (
!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))
) {
connection0.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -64,6 +67,7 @@ export async function handler (context: Context) {
}, },
400 400
) )
}
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
const codeExists = await db0 const codeExists = await db0

View File

@@ -48,6 +48,8 @@ export async function handler (context: Context) {
userSaveData.account.name = null userSaveData.account.name = null
userSaveData.account.session = null userSaveData.account.session = null
} catch { } catch {
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ success: false, message: "Couldn't parse save data" }, { success: false, message: "Couldn't parse save data" },
400 400
@@ -60,5 +62,8 @@ export async function handler (context: Context) {
.where(eq(berryDashUserData.id, userId)) .where(eq(berryDashUserData.id, userId))
.execute() .execute()
connection0.end()
connection1.end()
return jsonResponse({ success: true, message: null }) return jsonResponse({ success: true, message: null })
} }

View File

@@ -75,6 +75,8 @@ export async function handler (context: Context) {
} }
if (context.query.raw) { if (context.query.raw) {
connection0.end()
connection1.end()
const buffer = Buffer.from(icon[0].data, 'base64') const buffer = Buffer.from(icon[0].data, 'base64')
return new Response(buffer, { return new Response(buffer, {
headers: { 'Content-Type': 'image/png' } headers: { 'Content-Type': 'image/png' }

View File

@@ -61,6 +61,8 @@ export async function handler (context: Context) {
for (const key of requiredKeys) { for (const key of requiredKeys) {
if (!(key in body)) { if (!(key in body)) {
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ success: false, message: 'Invalid POST data', data: null }, { success: false, message: 'Invalid POST data', data: null },
400 400

View File

@@ -51,6 +51,7 @@ export async function handler (context: Context) {
const ip = getClientIp(context) const ip = getClientIp(context)
if (!ip) { if (!ip) {
connection0.end() connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -86,45 +87,70 @@ export async function handler (context: Context) {
) )
} }
if (price < 10) if (price < 10) {
connection0.end()
connection1.end()
return exitBecauseInvalid( return exitBecauseInvalid(
connection0, connection0,
connection1, connection1,
'Price cannot be be under 10 coins' 'Price cannot be be under 10 coins'
) )
if (!/^[a-zA-Z0-9 ]+$/.test(body.name) || body.name.length > 16) }
if (!/^[a-zA-Z0-9 ]+$/.test(body.name) || body.name.length > 16) {
connection0.end()
connection1.end()
return exitBecauseInvalid(connection0, connection1, 'Name is invalid') return exitBecauseInvalid(connection0, connection1, 'Name is invalid')
}
const decoded = Buffer.from(body.fileContent, 'base64') const decoded = Buffer.from(body.fileContent, 'base64')
if (!decoded) if (!decoded) {
connection0.end()
connection1.end()
return exitBecauseInvalid( return exitBecauseInvalid(
connection0, connection0,
connection1, connection1,
'Invalid image uploaded' 'Invalid image uploaded'
) )
if (decoded.length > 1024 * 1024) }
if (decoded.length > 1024 * 1024) {
connection0.end()
connection1.end()
return exitBecauseInvalid( return exitBecauseInvalid(
connection0, connection0,
connection1, connection1,
'File size exceeds 1 MB limit' 'File size exceeds 1 MB limit'
) )
}
const info = sizeOf(decoded) const info = sizeOf(decoded)
if (!info) if (!info) {
connection0.end()
connection1.end()
return exitBecauseInvalid( return exitBecauseInvalid(
connection0, connection0,
connection1, connection1,
'Invalid image uploaded' 'Invalid image uploaded'
) )
if (info.type !== 'png') }
if (info.type !== 'png') {
connection0.end()
connection1.end()
return exitBecauseInvalid(connection0, connection1, 'Image must be a PNG') return exitBecauseInvalid(connection0, connection1, 'Image must be a PNG')
if (info.width !== 128 || info.height !== 128) }
if (info.width !== 128 || info.height !== 128) {
connection0.end()
connection1.end()
return exitBecauseInvalid( return exitBecauseInvalid(
connection0, connection0,
connection1, connection1,
'Image has to be 128x128' 'Image has to be 128x128'
) )
}
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
if (!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))) if (
!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))
) {
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -135,6 +161,7 @@ export async function handler (context: Context) {
}, },
400 400
) )
}
const hashResult = hash(atob(body.fileContent), 'sha512') const hashResult = hash(atob(body.fileContent), 'sha512')
const id = crypto.randomUUID() const id = crypto.randomUUID()
@@ -149,6 +176,9 @@ export async function handler (context: Context) {
timestamp: time timestamp: time
}) })
connection0.end()
connection1.end()
return jsonResponse({ return jsonResponse({
success: true, success: true,
message: 'Icon uploaded successfully! It will be reviewed soon.' message: 'Icon uploaded successfully! It will be reviewed soon.'

View File

@@ -61,11 +61,14 @@ export async function handler (context: Context) {
const savedata = userData[0].saveData const savedata = userData[0].saveData
? JSON.parse(userData[0].saveData) ? JSON.parse(userData[0].saveData)
: null : null
if (!savedata) if (!savedata) {
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ success: false, message: 'User save does not exist', data: null }, { success: false, message: 'User save does not exist', data: null },
404 404
) )
}
connection0.end() connection0.end()
connection1.end() connection1.end()

View File

@@ -90,6 +90,8 @@ export async function handler (context: Context) {
if (votes[userId.toString()]) { if (votes[userId.toString()]) {
let likes = 0 let likes = 0
for (const vote of Object.values(votes) as boolean[]) likes += vote ? 1 : -1 for (const vote of Object.values(votes) as boolean[]) likes += vote ? 1 : -1
connection0.end()
connection1.end()
return jsonResponse({ success: true, message: null, data: { likes } }, 200) return jsonResponse({ success: true, message: null, data: { likes } }, 200)
} }
votes[userId.toString()] = likedQuery.toLowerCase() == 'true' votes[userId.toString()] = likedQuery.toLowerCase() == 'true'

View File

@@ -88,6 +88,8 @@ export async function handler (context: Context) {
.execute() .execute()
if (exists[0]) { if (exists[0]) {
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -97,7 +99,11 @@ export async function handler (context: Context) {
) )
} }
if (!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))) if (
!(await verifyTurstileOrVerifyCode(body.token, body.verifyCode, ip, db0))
) {
connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,
@@ -108,6 +114,7 @@ export async function handler (context: Context) {
}, },
400 400
) )
}
const time = Math.floor(Date.now() / 1000) const time = Math.floor(Date.now() / 1000)
await db1 await db1

View File

@@ -62,7 +62,8 @@ export async function handler (context: Context) {
.orderBy(desc(verifyCodes.id)) .orderBy(desc(verifyCodes.id))
.limit(1) .limit(1)
.execute() .execute()
if (codeExists[0]) if (codeExists[0]) {
connection0.end()
return jsonResponse( return jsonResponse(
{ {
success: true, success: true,
@@ -71,6 +72,7 @@ export async function handler (context: Context) {
}, },
200 200
) )
}
await db0.insert(verifyCodes).values({ code, ip, timestamp: time }) await db0.insert(verifyCodes).values({ code, ip, timestamp: time })