summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorMathMan05 <mathmanrm@gmail.com>2026-02-05 11:32:50 -0600
committerMathMan05 <mathmanrm@gmail.com>2026-02-05 11:32:50 -0600
commit1699d9ae2afe8b56bccd7c0723380065aef8bc81 (patch)
treea94d9f72d0671bda127f12ce0ba1fba23b984769 /src/api
parentfix responce types (diff)
downloadserver-ts-1699d9ae2afe8b56bccd7c0723380065aef8bc81.tar.xz
post with tags
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/threads.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/api/routes/channels/#channel_id/threads.ts b/src/api/routes/channels/#channel_id/threads.ts

index 3845b96d..8ef2c0fe 100644 --- a/src/api/routes/channels/#channel_id/threads.ts +++ b/src/api/routes/channels/#channel_id/threads.ts
@@ -17,7 +17,22 @@ */ import { handleMessage, postHandleMessage, route, sendMessage } from "@spacebar/api"; -import { Channel, emitEvent, User, uploadFile, Attachment, Member, ReadState, MessageCreateEvent, FieldErrors, getPermission, ThreadMember, Message } from "@spacebar/util"; +import { + Channel, + emitEvent, + User, + uploadFile, + Attachment, + Member, + ReadState, + MessageCreateEvent, + FieldErrors, + getPermission, + ThreadMember, + Message, + ChannelFlags, + DiscordApiErrors, +} from "@spacebar/util"; import { ChannelType, MessageType, ThreadCreationSchema, MessageCreateAttachment, MessageCreateCloudAttachment } from "@spacebar/schemas"; import { Request, Response, Router } from "express"; @@ -56,7 +71,22 @@ router.post( const channel = await Channel.findOneOrFail({ where: { id: channel_id }, + relations: ["available_tags"], }); + if (!body.applied_tags?.length) { + const required = channel.flags & Number(ChannelFlags.FLAGS.REQUIRE_TAG); + //TODO better error + if (required) throw new Error("Tag is required for this API"); + } else if (channel.available_tags) { + const realTags = new Map(channel.available_tags.map((tag) => [tag.id, tag])); + const bad = body.applied_tags.find((tag) => !realTags.has(tag)); + //TODO better error + if (bad) throw new Error("Invalid tag " + bad); + const permsNeeded = body.applied_tags.find((_) => realTags.get(_)?.moderated); + if (permsNeeded) { + req.permission?.hasThrow("MANAGE_THREADS"); + } + } const user = await User.findOneOrFail({ where: { id: req.user_id } }); const thread = await Channel.createChannel( @@ -72,6 +102,7 @@ router.post( rate_limit_per_user: body.rate_limit_per_user, type: body.type || (channel.threadOnly() ? ChannelType.GUILD_PUBLIC_THREAD : ChannelType.GUILD_PRIVATE_THREAD), recipients: [], + applied_tags: body.applied_tags || [], thread_metadata: { archived: false, auto_archive_duration: body.auto_archive_duration || channel.default_auto_archive_duration || 4320,