diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-14 22:15:55 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-14 22:15:55 +0200 |
commit | f691aa4c5aa47c8a8085c7b01912a1c403ce8732 (patch) | |
tree | 532673ee0955f5eec2c8a33c7abad8ed64dc9a48 /api/src/util | |
parent | fix #129 (diff) | |
download | server-f691aa4c5aa47c8a8085c7b01912a1c403ce8732.tar.xz |
:construction: webhook
Diffstat (limited to 'api/src/util')
-rw-r--r-- | api/src/util/route.ts | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/api/src/util/route.ts b/api/src/util/route.ts index 6cd8f622..1e2beb5d 100644 --- a/api/src/util/route.ts +++ b/api/src/util/route.ts @@ -1,4 +1,4 @@ -import { DiscordApiErrors, Event, EventData, getPermission, PermissionResolvable, Permissions } from "@fosscord/util"; +import { DiscordApiErrors, Event, EventData, getPermission, PermissionResolvable, Permissions, Webhook } from "@fosscord/util"; import { NextFunction, Request, Response } from "express"; import fs from "fs"; import path from "path"; @@ -54,9 +54,13 @@ export function route(opts: RouteOptions) { return async (req: Request, res: Response, next: NextFunction) => { if (opts.permission) { const required = new Permissions(opts.permission); + if (req.params.webhook_id) { + const webhook = await Webhook.findOneOrFail({ id: req.params.webhook_id }); + req.params.channel_id = webhook.channel_id; + req.params.guild_id = webhook.guild_id; + } const permission = await getPermission(req.user_id, req.params.guild_id, req.params.channel_id); - // bitfield comparison: check if user lacks certain permission if (!permission.has(required)) { throw DiscordApiErrors.MISSING_PERMISSIONS.withParams(opts.permission as string); } |