summary refs log tree commit diff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/assets/schemas.json162
-rw-r--r--api/src/routes/channels/#channel_id/index.ts2
-rw-r--r--api/src/routes/channels/#channel_id/invites.ts2
-rw-r--r--api/src/routes/channels/#channel_id/webhooks.ts3
-rw-r--r--api/src/util/handlers/route.ts5
5 files changed, 120 insertions, 54 deletions
diff --git a/api/assets/schemas.json b/api/assets/schemas.json

index 00819e7c..d8576514 100644 --- a/api/assets/schemas.json +++ b/api/assets/schemas.json
@@ -552,6 +552,12 @@ }, "default_auto_archive_duration": { "type": "integer" + }, + "flags": { + "type": "integer" + }, + "default_thread_rate_limit_per_user": { + "type": "integer" } }, "additionalProperties": false, @@ -695,7 +701,6 @@ }, "additionalProperties": false, "required": [ - "avatar", "name" ], "$schema": "http://json-schema.org/draft-07/schema#" @@ -1028,6 +1033,12 @@ }, "default_auto_archive_duration": { "type": "integer" + }, + "flags": { + "type": "integer" + }, + "default_thread_rate_limit_per_user": { + "type": "integer" } }, "additionalProperties": false @@ -1094,6 +1105,9 @@ "preferred_locale": { "type": "string" }, + "premium_progress_bar_enabled": { + "type": "boolean" + }, "region": { "type": "string" }, @@ -1651,6 +1665,9 @@ "UserSettingsSchema": { "type": "object", "properties": { + "id": { + "type": "string" + }, "afk_timeout": { "type": "integer" }, @@ -1672,22 +1689,7 @@ "custom_status": { "anyOf": [ { - "type": "object", - "properties": { - "emoji_id": { - "type": "string" - }, - "emoji_name": { - "type": "string" - }, - "expires_at": { - "type": "integer" - }, - "text": { - "type": "string" - } - }, - "additionalProperties": false + "$ref": "#/definitions/CustomStatus" }, { "type": "null" @@ -1713,16 +1715,7 @@ "type": "integer" }, "friend_source_flags": { - "type": "object", - "properties": { - "all": { - "type": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "all" - ] + "$ref": "#/definitions/FriendSourceFlags" }, "gateway_connected": { "type": "boolean" @@ -1733,31 +1726,7 @@ "guild_folders": { "type": "array", "items": { - "type": "object", - "properties": { - "color": { - "type": "integer" - }, - "guild_ids": { - "type": "array", - "items": { - "type": "string" - } - }, - "id": { - "type": "integer" - }, - "name": { - "type": "string" - } - }, - "additionalProperties": false, - "required": [ - "color", - "guild_ids", - "id", - "name" - ] + "$ref": "#/definitions/GuildFolder" } }, "guild_positions": { @@ -1818,9 +1787,98 @@ }, "timezone_offset": { "type": "integer" + }, + "hasId": { + "description": "Checks if entity has an id.\nIf entity composite compose ids, it will check them all.", + "type": "object", + "additionalProperties": false + }, + "save": { + "description": "Saves current entity in the database.\nIf entity does not exist in the database then inserts, otherwise updates.", + "type": "object", + "additionalProperties": false + }, + "remove": { + "description": "Removes current entity from the database.", + "type": "object", + "additionalProperties": false + }, + "softRemove": { + "description": "Records the delete date of current entity.", + "type": "object", + "additionalProperties": false + }, + "recover": { + "description": "Recovers a given entity in the database.", + "type": "object", + "additionalProperties": false + }, + "reload": { + "description": "Reloads entity data from the database.", + "type": "object", + "additionalProperties": false } }, "additionalProperties": false, + "definitions": { + "CustomStatus": { + "type": "object", + "properties": { + "emoji_id": { + "type": "string" + }, + "emoji_name": { + "type": "string" + }, + "expires_at": { + "type": "integer" + }, + "text": { + "type": "string" + } + }, + "additionalProperties": false + }, + "FriendSourceFlags": { + "type": "object", + "properties": { + "all": { + "type": "boolean" + } + }, + "additionalProperties": false, + "required": [ + "all" + ] + }, + "GuildFolder": { + "type": "object", + "properties": { + "color": { + "type": "integer" + }, + "guild_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "color", + "guild_ids", + "id", + "name" + ] + } + }, "$schema": "http://json-schema.org/draft-07/schema#" } } \ No newline at end of file diff --git a/api/src/routes/channels/#channel_id/index.ts b/api/src/routes/channels/#channel_id/index.ts
index 68b52be6..70c34f05 100644 --- a/api/src/routes/channels/#channel_id/index.ts +++ b/api/src/routes/channels/#channel_id/index.ts
@@ -71,6 +71,8 @@ export interface ChannelModifySchema { 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) => { diff --git a/api/src/routes/channels/#channel_id/invites.ts b/api/src/routes/channels/#channel_id/invites.ts
index a53b1de4..c0279f49 100644 --- a/api/src/routes/channels/#channel_id/invites.ts +++ b/api/src/routes/channels/#channel_id/invites.ts
@@ -36,7 +36,7 @@ router.post("/", route({ body: "InviteCreateSchema", permission: "CREATE_INSTANT const invite = await OrmUtils.mergeDeep(new Invite(),{ code: random(), - temporary: req.body.temporary, + temporary: req.body.temporary || true, uses: 0, max_uses: req.body.max_uses, max_age: req.body.max_age, diff --git a/api/src/routes/channels/#channel_id/webhooks.ts b/api/src/routes/channels/#channel_id/webhooks.ts
index 8f0e0a7f..00bf4619 100644 --- a/api/src/routes/channels/#channel_id/webhooks.ts +++ b/api/src/routes/channels/#channel_id/webhooks.ts
@@ -12,7 +12,7 @@ export interface WebhookCreateSchema { * @maxLength 80 */ name: string; - avatar: string; + avatar?: string; } //TODO: implement webhooks router.get("/", route({}), async (req: Request, res: Response) => { @@ -36,6 +36,7 @@ router.post("/", route({ body: "WebhookCreateSchema", permission: "MANAGE_WEBHOO if (name === "clyde") throw new HTTPError("Invalid name", 400); // TODO: save webhook in database and send response + res.json(new Webhook()); }); export default router; diff --git a/api/src/util/handlers/route.ts b/api/src/util/handlers/route.ts
index eaf7dc91..f8130f3c 100644 --- a/api/src/util/handlers/route.ts +++ b/api/src/util/handlers/route.ts
@@ -117,6 +117,11 @@ export function route(opts: RouteOptions) { const valid = validate(normalizeBody(req.body)); if (!valid) { const fields: Record<string, { code?: string; message: string }> = {}; + if(process.env.LOG_INVALID_BODY) { + console.log(`Got invalid request: ${req.method} ${req.originalUrl}`) + console.log(req.body) + validate.errors?.forEach(x => console.log(x.params)) + } validate.errors?.forEach((x) => (fields[x.instancePath.slice(1)] = { code: x.keyword, message: x.message || "" })); throw FieldErrors(fields); }