Move endpoints

This commit is contained in:
2026-01-29 19:43:28 -07:00
parent 024b651c52
commit 8edd408297
5 changed files with 99 additions and 120 deletions

View File

@@ -17,6 +17,10 @@ import { handler as launcherLatestHandler } from './routes/launcher/latest'
import { handler as launcherLoaderLatestHandler } from './routes/launcher/loader/latest'
import { handler as launcherLoaderUpdateDataHandler } from './routes/launcher/loader/update-data'
import { handler as berryDashAccountLoginPostHandler } from './routes/account/login/post'
import { handler as berryDashAccountRegisterPostHandler } from './routes/account/register/post'
import { handler as berryDashAccountChangeUsernamePostHandler } from './routes/account/change-username/post'
import { handler as berryDashAccountChangePasswordPostHandler } from './routes/account/change-password/post'
import { handler as accountForgotUsernamePostHandler } from './routes/account/forgot-username/post'
import { handler as accountForgotPasswordPostHandler } from './routes/account/forgot-password/post'
import { handler as accountResetPasswordPostHandler } from './routes/account/reset-password/post'
@@ -36,10 +40,6 @@ import { handler as berryDashIconMarketplacePostHandler } from './routes/berryda
import { handler as berryDashIconMarketplaceUploadPostHandler } from './routes/berrydash/icon-marketplace/upload/post'
import { handler as berryDashIconMarketplaceIconGetHandler } from './routes/berrydash/icon-marketplace/icon/get'
import { handler as berryDashAccountLoginPostHandler } from './routes/berrydash/account/login/post'
import { handler as berryDashAccountRegisterPostHandler } from './routes/berrydash/account/register/post'
import { handler as berryDashAccountChangeUsernamePostHandler } from './routes/berrydash/account/change-username/post'
import { handler as berryDashAccountChangePasswordPostHandler } from './routes/berrydash/account/change-password/post'
import { handler as berryDashAccountSaveGetHandler } from './routes/berrydash/account/save/get'
import { handler as berryDashAccountSavePostHandler } from './routes/berrydash/account/save/post'
@@ -512,6 +512,73 @@ app.get(
})
}
)
app.post(
'/account/login',
context => berryDashAccountLoginPostHandler(context),
{
detail: {
description:
'The endpoint for logging into an account. This is also the endpoint for refreshing login.',
tags: ['Accounts']
},
body: t.Object({
username: t.String(),
password: t.String()
})
}
)
app.post(
'/account/register',
context => berryDashAccountRegisterPostHandler(context),
{
detail: {
description: 'The endpoint for registering an account.',
tags: ['Accounts']
},
body: t.Object({
username: t.String(),
password: t.String(),
email: t.String(),
verifyCode: t.String()
})
}
)
app.post(
'/account/change-username',
context => berryDashAccountChangeUsernamePostHandler(context),
{
detail: {
description: "The endpoint for changing the account's user name.",
tags: ['Accounts']
},
body: t.Object({
newUsername: t.String()
}),
headers: t.Object({
authorization: t.String({
description: 'This is your session token'
})
})
}
)
app.post(
'/account/change-password',
context => berryDashAccountChangePasswordPostHandler(context),
{
detail: {
description: "The endpoint for changing the account's password.",
tags: ['Accounts']
},
body: t.Object({
newPassword: t.String()
}),
headers: t.Object({
authorization: t.String({
description: 'This is your session token'
})
})
}
)
app.post('/account/forgot-username', accountForgotUsernamePostHandler, {
detail: {
description: 'The endpoint for retreiving the username for an account.',
@@ -689,7 +756,7 @@ app.delete(
}),
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
})
}
@@ -721,7 +788,7 @@ app.post(
}),
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
})
}
@@ -743,7 +810,7 @@ app.put(
}),
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
})
}
@@ -781,7 +848,7 @@ app.post(
headers: t.Object({
authorization: t.Optional(
t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
)
})
@@ -804,7 +871,7 @@ app.post(
}),
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
})
}
@@ -852,74 +919,7 @@ app.post(
}),
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
})
})
}
)
app.post(
'/berrydash/account/login',
context => berryDashAccountLoginPostHandler(context),
{
detail: {
description:
'The endpoint for logging into an account. This is also the endpoint for refreshing login.',
tags: ['Berry Dash', 'Accounts']
},
body: t.Object({
username: t.String(),
password: t.String()
})
}
)
app.post(
'/berrydash/account/register',
context => berryDashAccountRegisterPostHandler(context),
{
detail: {
description: 'The endpoint for registering an account.',
tags: ['Berry Dash', 'Accounts']
},
body: t.Object({
username: t.String(),
password: t.String(),
email: t.String(),
verifyCode: t.String()
})
}
)
app.post(
'/berrydash/account/change-username',
context => berryDashAccountChangeUsernamePostHandler(context),
{
detail: {
description: "The endpoint for changing the account's user name.",
tags: ['Berry Dash', 'Accounts']
},
body: t.Object({
newUsername: t.String()
}),
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
})
})
}
)
app.post(
'/berrydash/account/change-password',
context => berryDashAccountChangePasswordPostHandler(context),
{
detail: {
description: "The endpoint for changing the account's password.",
tags: ['Berry Dash', 'Accounts']
},
body: t.Object({
newPassword: t.String()
}),
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
})
}
@@ -935,7 +935,7 @@ app.get(
},
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
})
}
@@ -951,7 +951,7 @@ app.post(
},
headers: t.Object({
authorization: t.String({
description: 'This is your Berry Dash session token'
description: 'This is your session token'
})
})
}

View File

@@ -3,9 +3,9 @@ import {
getClientIp,
getDatabaseConnection,
jsonResponse
} from '../../../../lib/util'
import { checkAuthorization } from '../../../../lib/auth'
import { users } from '../../../../lib/tables'
} from '../../../lib/util'
import { checkAuthorization } from '../../../lib/auth'
import { users } from '../../../lib/tables'
import { eq } from 'drizzle-orm'
import bcrypt from 'bcryptjs'
@@ -23,7 +23,6 @@ export async function handler (context: Context) {
500
)
const { connection: connection0, db: db0 } = dbInfo0
const { connection: connection1, db: db1 } = dbInfo1
const ip = getClientIp(context)
const authorizationToken = context.headers.authorization
@@ -34,7 +33,6 @@ export async function handler (context: Context) {
)
if (!authResult.valid) {
connection0.end()
connection1.end()
return jsonResponse({ success: false, message: 'Unauthorized' }, 401)
}
const userId = authResult.id
@@ -42,7 +40,6 @@ export async function handler (context: Context) {
const body = context.body as Body
if (!body.newPassword) {
connection0.end()
connection1.end()
return jsonResponse(
{ success: false, message: 'No new password provided' },
400
@@ -55,7 +52,6 @@ export async function handler (context: Context) {
)
) {
connection0.end()
connection1.end()
return jsonResponse(
{
success: false,

View File

@@ -3,9 +3,9 @@ import {
getClientIp,
getDatabaseConnection,
jsonResponse
} from '../../../../lib/util'
import { checkAuthorization } from '../../../../lib/auth'
import { users } from '../../../../lib/tables'
} from '../../../lib/util'
import { checkAuthorization } from '../../../lib/auth'
import { users } from '../../../lib/tables'
import { eq } from 'drizzle-orm'
type Body = {
@@ -22,7 +22,6 @@ export async function handler (context: Context) {
500
)
const { connection: connection0, db: db0 } = dbInfo0
const { connection: connection1, db: db1 } = dbInfo1
const ip = getClientIp(context)
const authorizationToken = context.headers.authorization
@@ -33,7 +32,6 @@ export async function handler (context: Context) {
)
if (!authResult.valid) {
connection0.end()
connection1.end()
return jsonResponse({ success: false, message: 'Unauthorized' }, 401)
}
const userId = authResult.id
@@ -41,7 +39,6 @@ export async function handler (context: Context) {
const body = context.body as Body
if (!body.newUsername) {
connection0.end()
connection1.end()
return jsonResponse(
{ success: false, message: 'No new username provided' },
400
@@ -50,7 +47,6 @@ export async function handler (context: Context) {
if (!/^[a-zA-Z0-9]{3,16}$/.test(body.newUsername)) {
connection0.end()
connection1.end()
return jsonResponse(
{
success: false,

View File

@@ -1,6 +1,6 @@
import { Context } from 'elysia'
import { getDatabaseConnection, jsonResponse } from '../../../../lib/util'
import { berryDashUserData, users } from '../../../../lib/tables'
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
import { users } from '../../../lib/tables'
import { eq } from 'drizzle-orm'
import bcrypt from 'bcryptjs'
@@ -19,12 +19,10 @@ export async function handler (context: Context) {
500
)
const { connection: connection0, db: db0 } = dbInfo0
const { connection: connection1, db: db1 } = dbInfo1
const body = context.body as Body
if (!body.username || !body.password) {
connection0.end()
connection1.end()
return jsonResponse(
{
success: false,
@@ -48,7 +46,6 @@ export async function handler (context: Context) {
.execute()
if (!user[0]) {
connection0.end()
connection1.end()
return jsonResponse(
{
success: false,
@@ -60,7 +57,6 @@ export async function handler (context: Context) {
}
if (!(await bcrypt.compare(body.password, user[0].password))) {
connection0.end()
connection1.end()
return jsonResponse(
{
success: false,

View File

@@ -3,10 +3,10 @@ import {
getClientIp,
getDatabaseConnection,
jsonResponse
} from '../../../../lib/util'
} from '../../../lib/util'
import isEmail from 'validator/lib/isEmail'
import { berryDashUserData, users, verifyCodes } from '../../../../lib/tables'
import { and, desc, eq, or, sql } from 'drizzle-orm'
import { berryDashUserData, users, verifyCodes } from '../../../lib/tables'
import { and, desc, eq, sql } from 'drizzle-orm'
import bcrypt from 'bcryptjs'
import { randomBytes } from 'crypto'
@@ -23,7 +23,7 @@ export async function handler (context: Context) {
if (!dbInfo0 || !dbInfo1)
return jsonResponse(
{ success: false, message: 'Failed to connect to database', data: null },
{ success: false, message: 'Failed to connect to database' },
500
)
const { connection: connection0, db: db0 } = dbInfo0
@@ -36,9 +36,7 @@ export async function handler (context: Context) {
return jsonResponse(
{
success: false,
message:
'Username, password, email and verifyCode must be in POST data',
data: null
message: 'Username, password, email and verifyCode must be in POST data'
},
400
)
@@ -49,8 +47,7 @@ export async function handler (context: Context) {
return jsonResponse(
{
success: false,
message: 'Invalid verify code (codes can only be used once)',
data: null
message: 'Invalid verify code (codes can only be used once)'
},
400
)
@@ -62,8 +59,7 @@ export async function handler (context: Context) {
return jsonResponse(
{
success: false,
message: 'Failed to get required info',
data: null
message: 'Failed to get required info'
},
400
)
@@ -99,8 +95,7 @@ export async function handler (context: Context) {
return jsonResponse(
{
success: false,
message: 'Invalid verify code (codes can only be used once)',
data: null
message: 'Invalid verify code (codes can only be used once)'
},
400
)
@@ -111,8 +106,7 @@ export async function handler (context: Context) {
return jsonResponse(
{
success: false,
message: 'Username must be 3-16 characters, letters and numbers only',
data: null
message: 'Username must be 3-16 characters, letters and numbers only'
},
400
)
@@ -124,8 +118,7 @@ export async function handler (context: Context) {
return jsonResponse(
{
success: false,
message: 'Email is invalid',
data: null
message: 'Email is invalid'
},
400
)
@@ -140,8 +133,7 @@ export async function handler (context: Context) {
{
success: false,
message:
'Password must be at least 8 characters with at least one letter and one number',
data: null
'Password must be at least 8 characters with at least one letter and one number'
},
400
)
@@ -172,8 +164,7 @@ export async function handler (context: Context) {
return jsonResponse(
{
success: true,
message: null,
data: null
message: null
},
200
)