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

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

View File

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

View File

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

View File

@@ -51,6 +51,7 @@ export async function handler (context: Context) {
const ip = getClientIp(context)
if (!ip) {
connection0.end()
connection1.end()
return jsonResponse(
{
success: false,
@@ -86,45 +87,70 @@ export async function handler (context: Context) {
)
}
if (price < 10)
if (price < 10) {
connection0.end()
connection1.end()
return exitBecauseInvalid(
connection0,
connection1,
'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')
}
const decoded = Buffer.from(body.fileContent, 'base64')
if (!decoded)
if (!decoded) {
connection0.end()
connection1.end()
return exitBecauseInvalid(
connection0,
connection1,
'Invalid image uploaded'
)
if (decoded.length > 1024 * 1024)
}
if (decoded.length > 1024 * 1024) {
connection0.end()
connection1.end()
return exitBecauseInvalid(
connection0,
connection1,
'File size exceeds 1 MB limit'
)
}
const info = sizeOf(decoded)
if (!info)
if (!info) {
connection0.end()
connection1.end()
return exitBecauseInvalid(
connection0,
connection1,
'Invalid image uploaded'
)
if (info.type !== 'png')
}
if (info.type !== 'png') {
connection0.end()
connection1.end()
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(
connection0,
connection1,
'Image has to be 128x128'
)
}
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(
{
success: false,
@@ -135,6 +161,7 @@ export async function handler (context: Context) {
},
400
)
}
const hashResult = hash(atob(body.fileContent), 'sha512')
const id = crypto.randomUUID()
@@ -149,6 +176,9 @@ export async function handler (context: Context) {
timestamp: time
})
connection0.end()
connection1.end()
return jsonResponse({
success: true,
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
? JSON.parse(userData[0].saveData)
: null
if (!savedata)
if (!savedata) {
connection0.end()
connection1.end()
return jsonResponse(
{ success: false, message: 'User save does not exist', data: null },
404
)
}
connection0.end()
connection1.end()

View File

@@ -90,6 +90,8 @@ export async function handler (context: Context) {
if (votes[userId.toString()]) {
let likes = 0
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)
}
votes[userId.toString()] = likedQuery.toLowerCase() == 'true'

View File

@@ -88,6 +88,8 @@ export async function handler (context: Context) {
.execute()
if (exists[0]) {
connection0.end()
connection1.end()
return jsonResponse(
{
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(
{
success: false,
@@ -108,6 +114,7 @@ export async function handler (context: Context) {
},
400
)
}
const time = Math.floor(Date.now() / 1000)
await db1