Perms for GET webhook, url property

This commit is contained in:
TomatoCake
2024-07-18 15:16:50 +02:00
parent 15a2e57b05
commit 873107f90d
6 changed files with 618 additions and 306 deletions
@@ -20,7 +20,7 @@ const router = Router();
router.get(
"/",
route({
description: "Returns a webhook object for the given id.",
description: "Returns a webhook object for the given id and token.",
responses: {
200: {
body: "APIWebhook",
@@ -45,7 +45,12 @@ router.get(
throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
}
return res.json(webhook);
const instanceUrl =
Config.get().api.endpointPublic || "http://localhost:3001";
return res.json({
...webhook,
url: instanceUrl + "/webhooks/" + webhook.id + "/" + webhook.token,
});
},
);
+25 -9
View File
@@ -1,5 +1,10 @@
import { route } from "@spacebar/api";
import { Webhook } from "@spacebar/util";
import {
Config,
DiscordApiErrors,
getPermission,
Webhook,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
const router = Router();
@@ -15,18 +20,29 @@ router.get(
},
}),
async (req: Request, res: Response) => {
// TODO: Permission check
const { webhook_id } = req.params;
const webhook = await Webhook.findOneOrFail({
where: { id: webhook_id },
relations: [
"user",
"guild",
"source_guild",
"application" /*"source_channel"*/,
],
relations: ["channel", "guild", "application", "user"],
});
if (webhook.guild_id) {
const permission = await getPermission(
req.user_id,
webhook.guild_id,
);
if (!permission.has("MANAGE_WEBHOOKS"))
throw DiscordApiErrors.UNKNOWN_WEBHOOK;
} else if (webhook.user_id != req.user_id)
throw DiscordApiErrors.UNKNOWN_WEBHOOK;
const instanceUrl =
Config.get().api.endpointPublic || "http://localhost:3001";
return res.json({
...webhook,
url: instanceUrl + "/webhooks/" + webhook.id + "/" + webhook.token,
});
return res.json(webhook);
},
);
-1
View File
@@ -149,7 +149,6 @@ export async function handleMessage(opts: MessageOptions): Promise<Message> {
`/avatars/${opts.webhook_id}`,
dataUri as string,
);
console.log(message.avatar);
message.author.avatar = message.avatar;
}
} else {