summary refs log tree commit diff
diff options
context:
space:
mode:
authorCyber <cyber.hf18@gmail.com>2026-01-14 16:19:15 +0100
committerGitHub <noreply@github.com>2026-01-14 16:19:15 +0100
commitd9f5be41be6d359d7ecc4de9a704906a53b1b2a3 (patch)
tree807289c1079c886af9514448882b9c6a2a26d391
parentGateway close logging for 4002 (diff)
parentfest: throw an error if bot name is empty (diff)
downloadserver-ts-d9f5be41be6d359d7ecc4de9a704906a53b1b2a3.tar.xz
Merge pull request #1465 from CyberL1/fix/name-must-not-be-empty
-rw-r--r--assets/openapi.json3
-rw-r--r--assets/schemas.json3
-rw-r--r--src/api/routes/applications/#application_id/bot/index.ts11
-rw-r--r--src/api/routes/applications/#application_id/index.ts11
-rw-r--r--src/schemas/uncategorised/BotModifySchema.ts1
-rw-r--r--src/util/util/FieldError.ts15
6 files changed, 35 insertions, 9 deletions
diff --git a/assets/openapi.json b/assets/openapi.json

index 78204ccb..19447b16 100644 --- a/assets/openapi.json +++ b/assets/openapi.json
@@ -3997,6 +3997,9 @@ }, "username": { "type": "string" + }, + "banner": { + "type": "string" } } }, diff --git a/assets/schemas.json b/assets/schemas.json
index 6d334cfd..d3b24041 100644 --- a/assets/schemas.json +++ b/assets/schemas.json
@@ -4234,6 +4234,9 @@ }, "username": { "type": "string" + }, + "banner": { + "type": "string" } }, "additionalProperties": false, diff --git a/src/api/routes/applications/#application_id/bot/index.ts b/src/api/routes/applications/#application_id/bot/index.ts
index 901f386f..7f5369ae 100644 --- a/src/api/routes/applications/#application_id/bot/index.ts +++ b/src/api/routes/applications/#application_id/bot/index.ts
@@ -17,7 +17,7 @@ */ import { route } from "@spacebar/api"; -import { Application, DiscordApiErrors, User, createAppBotUser, generateToken, handleFile } from "@spacebar/util"; +import { Application, DiscordApiErrors, FieldErrors, User, createAppBotUser, generateToken, handleFile } from "@spacebar/util"; import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; import { verifyToken } from "node-2fa"; @@ -100,6 +100,15 @@ router.patch( const body = req.body as BotModifySchema; if (!body.avatar?.trim()) delete body.avatar; + if (body.username?.trim() == "") { + throw FieldErrors({ + username: { + code: "BASE_TYPE_REQUIRED", + message: req.t("common:field.BASE_TYPE_REQUIRED"), + }, + }); + } + const app = await Application.findOneOrFail({ where: { id: req.params.application_id }, relations: { bot: true, owner: true }, diff --git a/src/api/routes/applications/#application_id/index.ts b/src/api/routes/applications/#application_id/index.ts
index 1576df88..58c01568 100644 --- a/src/api/routes/applications/#application_id/index.ts +++ b/src/api/routes/applications/#application_id/index.ts
@@ -17,7 +17,7 @@ */ import { route } from "@spacebar/api"; -import { Application, DiscordApiErrors, Guild, handleFile, User } from "@spacebar/util"; +import { Application, DiscordApiErrors, FieldErrors, Guild, handleFile, User } from "@spacebar/util"; import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; import { verifyToken } from "node-2fa"; @@ -73,6 +73,15 @@ router.patch( if (app.owner.totp_secret && (!req.body.code || verifyToken(app.owner.totp_secret, req.body.code))) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008); + if (body.name?.trim() == "") { + throw FieldErrors({ + name: { + code: "BASE_TYPE_REQUIRED", + message: req.t("common:field.BASE_TYPE_REQUIRED"), + }, + }); + } + if (body.icon) { body.icon = await handleFile(`/app-icons/${app.id}`, body.icon as string); } diff --git a/src/schemas/uncategorised/BotModifySchema.ts b/src/schemas/uncategorised/BotModifySchema.ts
index 21276023..d1bbab8e 100644 --- a/src/schemas/uncategorised/BotModifySchema.ts +++ b/src/schemas/uncategorised/BotModifySchema.ts
@@ -19,4 +19,5 @@ export interface BotModifySchema { avatar?: string; username?: string; + banner?: string; } diff --git a/src/util/util/FieldError.ts b/src/util/util/FieldError.ts
index 8f93b2b6..76b34b82 100644 --- a/src/util/util/FieldError.ts +++ b/src/util/util/FieldError.ts
@@ -29,19 +29,20 @@ export type ErrorContent = { code: string; message: string }; export type ObjectErrorContent = { _errors: ErrorContent[] }; export function FieldErrors(fields: Record<string, { code?: string; message: string }>, errors?: ErrorObject[]) { - return new FieldError( - 50035, - "Invalid Form Body", - Object.values(fields).map(({ message, code }) => ({ + const errorsObject = {} as Record<string, ObjectErrorContent>; + + Object.entries(fields).map(([key, { message, code }]) => { + errorsObject[key] = { _errors: [ { message, code: code || "BASE_TYPE_INVALID", }, ], - })), - errors, - ); + }; + }); + + return new FieldError(50035, "Invalid Form Body", errorsObject, errors); } // TODO: implement Image data type: Data URI scheme that supports JPG, GIF, and PNG formats. An example Data URI format is: data:image/jpeg;base64,BASE64_ENCODED_JPEG_IMAGE_DATA