From 8edd4082972668e85b11831227e395cd9c1f7b54 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Thu, 29 Jan 2026 19:43:28 -0700 Subject: [PATCH] Move endpoints --- src/index.ts | 158 +++++++++--------- .../account/change-password/post.ts | 10 +- .../account/change-username/post.ts | 10 +- .../{berrydash => }/account/login/post.ts | 8 +- .../{berrydash => }/account/register/post.ts | 33 ++-- 5 files changed, 99 insertions(+), 120 deletions(-) rename src/routes/{berrydash => }/account/change-password/post.ts (86%) rename src/routes/{berrydash => }/account/change-username/post.ts (85%) rename src/routes/{berrydash => }/account/login/post.ts (86%) rename src/routes/{berrydash => }/account/register/post.ts (87%) diff --git a/src/index.ts b/src/index.ts index aff9e71..1fb304f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' }) }) } diff --git a/src/routes/berrydash/account/change-password/post.ts b/src/routes/account/change-password/post.ts similarity index 86% rename from src/routes/berrydash/account/change-password/post.ts rename to src/routes/account/change-password/post.ts index fb8895c..3db0ced 100644 --- a/src/routes/berrydash/account/change-password/post.ts +++ b/src/routes/account/change-password/post.ts @@ -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, diff --git a/src/routes/berrydash/account/change-username/post.ts b/src/routes/account/change-username/post.ts similarity index 85% rename from src/routes/berrydash/account/change-username/post.ts rename to src/routes/account/change-username/post.ts index 8428777..6eeb216 100644 --- a/src/routes/berrydash/account/change-username/post.ts +++ b/src/routes/account/change-username/post.ts @@ -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, diff --git a/src/routes/berrydash/account/login/post.ts b/src/routes/account/login/post.ts similarity index 86% rename from src/routes/berrydash/account/login/post.ts rename to src/routes/account/login/post.ts index d325f14..9d369c3 100644 --- a/src/routes/berrydash/account/login/post.ts +++ b/src/routes/account/login/post.ts @@ -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, diff --git a/src/routes/berrydash/account/register/post.ts b/src/routes/account/register/post.ts similarity index 87% rename from src/routes/berrydash/account/register/post.ts rename to src/routes/account/register/post.ts index fd71576..652e981 100644 --- a/src/routes/berrydash/account/register/post.ts +++ b/src/routes/account/register/post.ts @@ -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 )