From 10bd81274722823f875ba31eaf5fc670bfb22ceb Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Fri, 12 Aug 2022 11:36:39 +0200 Subject: Split schemas into files in util --- api/src/routes/channels/#channel_id/index.ts | 30 ++---------------- api/src/routes/channels/#channel_id/invites.ts | 12 -------- .../#channel_id/messages/#message_id/ack.ts | 9 ------ .../#channel_id/messages/#message_id/index.ts | 4 +-- .../channels/#channel_id/messages/bulk-delete.ts | 4 --- .../routes/channels/#channel_id/messages/index.ts | 36 ++-------------------- api/src/routes/channels/#channel_id/permissions.ts | 7 ++--- api/src/routes/channels/#channel_id/purge.ts | 7 +---- api/src/routes/channels/#channel_id/webhooks.ts | 8 ----- 9 files changed, 9 insertions(+), 108 deletions(-) (limited to 'api/src/routes/channels/#channel_id') diff --git a/api/src/routes/channels/#channel_id/index.ts b/api/src/routes/channels/#channel_id/index.ts index 70c34f05..bb8b868b 100644 --- a/api/src/routes/channels/#channel_id/index.ts +++ b/api/src/routes/channels/#channel_id/index.ts @@ -6,7 +6,8 @@ import { ChannelUpdateEvent, emitEvent, Recipient, - handleFile + handleFile, + ChannelModifySchema } from "@fosscord/util"; import { Request, Response, Router } from "express"; import { route } from "@fosscord/api"; @@ -48,33 +49,6 @@ router.delete("/", route({ permission: "MANAGE_CHANNELS" }), async (req: Request res.send(channel); }); -export interface ChannelModifySchema { - /** - * @maxLength 100 - */ - name?: string; - type?: ChannelType; - topic?: string; - icon?: string | null; - bitrate?: number; - user_limit?: number; - rate_limit_per_user?: number; - position?: number; - permission_overwrites?: { - id: string; - type: ChannelPermissionOverwriteType; - allow: string; - deny: string; - }[]; - parent_id?: string; - id?: string; // is not used (only for guild create) - nsfw?: boolean; - rtc_region?: string; - default_auto_archive_duration?: number; - flags?: number; - default_thread_rate_limit_per_user?: number; -} - router.patch("/", route({ body: "ChannelModifySchema", permission: "MANAGE_CHANNELS" }), async (req: Request, res: Response) => { let payload = req.body as ChannelModifySchema; const { channel_id } = req.params; diff --git a/api/src/routes/channels/#channel_id/invites.ts b/api/src/routes/channels/#channel_id/invites.ts index f111cf54..b5c65c0d 100644 --- a/api/src/routes/channels/#channel_id/invites.ts +++ b/api/src/routes/channels/#channel_id/invites.ts @@ -8,18 +8,6 @@ import { OrmUtils } from "@fosscord/util"; const router: Router = Router(); -export interface InviteCreateSchema { - target_user_id?: string; - target_type?: string; - validate?: string; // ? what is this - max_age?: number; - max_uses?: number; - temporary?: boolean; - unique?: boolean; - target_user?: string; - target_user_type?: number; -} - router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT_INVITE", right: "CREATE_INVITES" }), async (req: Request, res: Response) => { const { user_id } = req; diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts b/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts index c1b8d20f..041f4d5e 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/ack.ts @@ -5,15 +5,6 @@ import { OrmUtils } from "@fosscord/util"; const router = Router(); -// TODO: public read receipts & privacy scoping -// TODO: send read state event to all channel members -// TODO: advance-only notification cursor - -export interface MessageAcknowledgeSchema { - manual?: boolean; - mention_count?: number; -} - router.post("/", route({ body: "MessageAcknowledgeSchema" }), async (req: Request, res: Response) => { const { channel_id, message_id } = req.params; diff --git a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts index b3b310d3..d7e27062 100644 --- a/api/src/routes/channels/#channel_id/messages/#message_id/index.ts +++ b/api/src/routes/channels/#channel_id/messages/#message_id/index.ts @@ -12,13 +12,13 @@ import { MessageDeleteEvent, MessageUpdateEvent, Snowflake, - uploadFile + uploadFile, + MessageCreateSchema } from "@fosscord/util"; import { Router, Response, Request } from "express"; import multer from "multer"; import { route } from "@fosscord/api"; import { handleMessage, postHandleMessage } from "@fosscord/api"; -import { MessageCreateSchema } from "../index"; import { HTTPError } from "@fosscord/util"; const router = Router(); diff --git a/api/src/routes/channels/#channel_id/messages/bulk-delete.ts b/api/src/routes/channels/#channel_id/messages/bulk-delete.ts index 2e40f110..24a33d2d 100644 --- a/api/src/routes/channels/#channel_id/messages/bulk-delete.ts +++ b/api/src/routes/channels/#channel_id/messages/bulk-delete.ts @@ -8,10 +8,6 @@ const router: Router = Router(); export default router; -export interface BulkDeleteSchema { - messages: string[]; -} - // should users be able to bulk delete messages or only bots? ANSWER: all users // should this request fail, if you provide messages older than 14 days/invalid ids? ANSWER: NO // https://discord.com/developers/docs/resources/channel#bulk-delete-messages diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts index c2057422..9ab0d97d 100644 --- a/api/src/routes/channels/#channel_id/messages/index.ts +++ b/api/src/routes/channels/#channel_id/messages/index.ts @@ -5,7 +5,6 @@ import { ChannelType, Config, DmChannelDTO, - Embed, emitEvent, getPermission, getRights, @@ -13,7 +12,8 @@ import { MessageCreateEvent, Snowflake, uploadFile, - Member + Member, + MessageCreateSchema } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { handleMessage, postHandleMessage, route } from "@fosscord/api"; @@ -49,38 +49,6 @@ export function isTextChannel(type: ChannelType): boolean { } } -export interface MessageCreateSchema { - type?: number; - content?: string; - nonce?: string; - channel_id?: string; - tts?: boolean; - flags?: string; - embeds?: Embed[]; - embed?: Embed; - // TODO: ^ embed is deprecated in favor of embeds (https://discord.com/developers/docs/resources/channel#message-object) - allowed_mentions?: { - parse?: string[]; - roles?: string[]; - users?: string[]; - replied_user?: boolean; - }; - message_reference?: { - message_id: string; - channel_id: string; - guild_id?: string; - fail_if_not_exists?: boolean; - }; - payload_json?: string; - file?: any; - /** - TODO: we should create an interface for attachments - TODO: OpenWAAO<-->attachment-style metadata conversion - **/ - attachments?: any[]; - sticker_ids?: string[]; -} - // https://discord.com/developers/docs/resources/channel#create-message // get messages router.get("/", async (req: Request, res: Response) => { diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/api/src/routes/channels/#channel_id/permissions.ts index 06a124bb..34052fe5 100644 --- a/api/src/routes/channels/#channel_id/permissions.ts +++ b/api/src/routes/channels/#channel_id/permissions.ts @@ -1,6 +1,7 @@ import { Channel, ChannelPermissionOverwrite, + ChannelPermissionOverwriteSchema, ChannelPermissionOverwriteType, ChannelUpdateEvent, emitEvent, @@ -10,13 +11,9 @@ import { } from "@fosscord/util"; import { Router, Response, Request } from "express"; import { HTTPError } from "@fosscord/util"; - import { route } from "@fosscord/api"; -const router: Router = Router(); -// TODO: Only permissions your bot has in the guild or channel can be allowed/denied (unless your bot has a MANAGE_ROLES overwrite in the channel) - -export interface ChannelPermissionOverwriteSchema extends ChannelPermissionOverwrite {} +const router: Router = Router(); router.put( "/:overwrite_id", diff --git a/api/src/routes/channels/#channel_id/purge.ts b/api/src/routes/channels/#channel_id/purge.ts index 7ab4ad9a..1ef6e1d7 100644 --- a/api/src/routes/channels/#channel_id/purge.ts +++ b/api/src/routes/channels/#channel_id/purge.ts @@ -1,4 +1,4 @@ -import { HTTPError } from "@fosscord/util"; +import { HTTPError, PurgeSchema } from "@fosscord/util"; import { route } from "@fosscord/api"; import { isTextChannel } from "./messages"; import { FindManyOptions, Between, Not } from "typeorm"; @@ -10,11 +10,6 @@ const router: Router = Router(); export default router; -export interface PurgeSchema { - before: string; - after: string; -} - /** TODO: apply the delete bit by bit to prevent client and database stress **/ diff --git a/api/src/routes/channels/#channel_id/webhooks.ts b/api/src/routes/channels/#channel_id/webhooks.ts index 00bf4619..b11c8eb9 100644 --- a/api/src/routes/channels/#channel_id/webhooks.ts +++ b/api/src/routes/channels/#channel_id/webhooks.ts @@ -6,14 +6,6 @@ import { isTextChannel } from "./messages/index"; import { DiscordApiErrors } from "@fosscord/util"; const router: Router = Router(); -// TODO: webhooks -export interface WebhookCreateSchema { - /** - * @maxLength 80 - */ - name: string; - avatar?: string; -} //TODO: implement webhooks router.get("/", route({}), async (req: Request, res: Response) => { res.json([]); -- cgit 1.4.1