summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-02-14 17:44:55 +0100
committerRory& <root@rory.gay>2026-02-14 17:44:55 +0100
commit642bf1d60b2d7c6d8dbbb1ea34406ef01802294a (patch)
treecaa19483bf136fc6cac1ee846ad2bd2d4572b39a /src/api
parentUnset env for docker containers, add cacertificates? (diff)
downloadserver-ts-642bf1d60b2d7c6d8dbbb1ea34406ef01802294a.tar.xz
Try to enforce channel limts?
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/index.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/api/routes/channels/#channel_id/index.ts b/src/api/routes/channels/#channel_id/index.ts

index a1db91373..37767574d 100644 --- a/src/api/routes/channels/#channel_id/index.ts +++ b/src/api/routes/channels/#channel_id/index.ts
@@ -17,7 +17,19 @@ */ import { route } from "@spacebar/api"; -import { Channel, ChannelDeleteEvent, ChannelUpdateEvent, Recipient, emitEvent, handleFile } from "@spacebar/util"; +import { + Channel, + ChannelDeleteEvent, + ChannelUpdateEvent, + Recipient, + emitEvent, + handleFile, + Config, + FieldError, + ErrorList, + ObjectErrorContent, + makeObjectErrorContent, +} from "@spacebar/util"; import { Request, Response, Router } from "express"; import { ChannelModifySchema, ChannelType } from "@spacebar/schemas"; @@ -174,6 +186,7 @@ router.patch( channel.available_tags = channel.available_tags.filter((_) => filter.has(_.id)); } } + if (payload.applied_tags) { if (channel.isThread()) { const parent = await Channel.findOneOrFail({ @@ -201,6 +214,19 @@ router.patch( if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon); + const channelLimits = Config.get().limits.channel; + + const errors: ErrorList = {}; + if (payload.name && (payload.name.length < 1 || payload.name.length > channelLimits.maxName)) + errors["name"] = makeObjectErrorContent("BASE_TYPE_BAD_LENGTH", `Channel name must be between 1 and ${channelLimits.maxName} characters`); + if (payload.topic !== undefined && payload.topic.length > channelLimits.maxTopic) + errors["topic"] = makeObjectErrorContent("BASE_TYPE_BAD_LENGTH", `Channel topic must be less than ${channelLimits.maxTopic} characters`); + if (payload.user_limit !== undefined && payload.user_limit < 0) errors["user_limit"] = makeObjectErrorContent("BASE_TYPE_BAD_VALUE", "User limit must be 0 or higher"); + + if (Object.keys(errors).length) { + throw new FieldError(400, "Invalid form body", errors); + } + channel.assign(payload); if (channel.thread_metadata) { if (payload.archived !== undefined) {