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 launcherLoaderLatestHandler } from './routes/launcher/loader/latest'
import { handler as launcherLoaderUpdateDataHandler } from './routes/launcher/loader/update-data' 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 accountForgotUsernamePostHandler } from './routes/account/forgot-username/post'
import { handler as accountForgotPasswordPostHandler } from './routes/account/forgot-password/post' import { handler as accountForgotPasswordPostHandler } from './routes/account/forgot-password/post'
import { handler as accountResetPasswordPostHandler } from './routes/account/reset-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 berryDashIconMarketplaceUploadPostHandler } from './routes/berrydash/icon-marketplace/upload/post'
import { handler as berryDashIconMarketplaceIconGetHandler } from './routes/berrydash/icon-marketplace/icon/get' 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 berryDashAccountSaveGetHandler } from './routes/berrydash/account/save/get'
import { handler as berryDashAccountSavePostHandler } from './routes/berrydash/account/save/post' 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, { app.post('/account/forgot-username', accountForgotUsernamePostHandler, {
detail: { detail: {
description: 'The endpoint for retreiving the username for an account.', description: 'The endpoint for retreiving the username for an account.',
@@ -689,7 +756,7 @@ app.delete(
}), }),
headers: t.Object({ headers: t.Object({
authorization: t.String({ 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({ headers: t.Object({
authorization: t.String({ 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({ headers: t.Object({
authorization: t.String({ 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({ headers: t.Object({
authorization: t.Optional( authorization: t.Optional(
t.String({ 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({ headers: t.Object({
authorization: t.String({ 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({ headers: t.Object({
authorization: t.String({ authorization: t.String({
description: 'This is your Berry Dash session token' description: 'This is your 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'
}) })
}) })
} }
@@ -935,7 +935,7 @@ app.get(
}, },
headers: t.Object({ headers: t.Object({
authorization: t.String({ 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({ headers: t.Object({
authorization: t.String({ 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, getClientIp,
getDatabaseConnection, getDatabaseConnection,
jsonResponse jsonResponse
} from '../../../../lib/util' } from '../../../lib/util'
import { checkAuthorization } from '../../../../lib/auth' import { checkAuthorization } from '../../../lib/auth'
import { users } from '../../../../lib/tables' import { users } from '../../../lib/tables'
import { eq } from 'drizzle-orm' import { eq } from 'drizzle-orm'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
@@ -23,7 +23,6 @@ export async function handler (context: Context) {
500 500
) )
const { connection: connection0, db: db0 } = dbInfo0 const { connection: connection0, db: db0 } = dbInfo0
const { connection: connection1, db: db1 } = dbInfo1
const ip = getClientIp(context) const ip = getClientIp(context)
const authorizationToken = context.headers.authorization const authorizationToken = context.headers.authorization
@@ -34,7 +33,6 @@ export async function handler (context: Context) {
) )
if (!authResult.valid) { if (!authResult.valid) {
connection0.end() connection0.end()
connection1.end()
return jsonResponse({ success: false, message: 'Unauthorized' }, 401) return jsonResponse({ success: false, message: 'Unauthorized' }, 401)
} }
const userId = authResult.id const userId = authResult.id
@@ -42,7 +40,6 @@ export async function handler (context: Context) {
const body = context.body as Body const body = context.body as Body
if (!body.newPassword) { if (!body.newPassword) {
connection0.end() connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ success: false, message: 'No new password provided' }, { success: false, message: 'No new password provided' },
400 400
@@ -55,7 +52,6 @@ export async function handler (context: Context) {
) )
) { ) {
connection0.end() connection0.end()
connection1.end()
return jsonResponse( return jsonResponse(
{ {
success: false, success: false,

View File

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

View File

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

View File

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