diff --git a/api/src/util/cdn.ts b/api/src/util/cdn.ts
deleted file mode 100644
index 8c6e9ac9..00000000
--- a/api/src/util/cdn.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import { Config } from "@fosscord/util";
-import FormData from "form-data";
-import { HTTPError } from "lambert-server";
-import fetch from "node-fetch";
-
-export async function uploadFile(path: string, file: Express.Multer.File) {
- const form = new FormData();
- form.append("file", file.buffer, {
- contentType: file.mimetype,
- filename: file.originalname
- });
-
- const response = await fetch(`${Config.get().cdn.endpoint || "http://localhost:3003"}${path}`, {
- headers: {
- signature: Config.get().security.requestSignature,
- ...form.getHeaders()
- },
- method: "POST",
- body: form
- });
- const result = await response.json();
-
- if (response.status !== 200) throw result;
- return result;
-}
-
-export async function handleFile(path: string, body?: string): Promise<string | undefined> {
- if (!body || !body.startsWith("data:")) return body;
- try {
- const mimetype = body.split(":")[1].split(";")[0];
- const buffer = Buffer.from(body.split(",")[1], "base64");
-
- // @ts-ignore
- const { id } = await uploadFile(path, { buffer, mimetype, originalname: "banner" });
- return id;
- } catch (error) {
- console.error(error);
- throw new HTTPError("Invalid " + path);
- }
-}
-
-export async function deleteFile(path: string) {
- const response = await fetch(`${Config.get().cdn.endpoint || "http://localhost:3003"}${path}`, {
- headers: {
- signature: Config.get().security.requestSignature
- },
- method: "DELETE"
- });
- const result = await response.json();
-
- if (response.status !== 200) throw result;
- return result;
-}
diff --git a/api/src/util/route.ts b/api/src/util/route.ts
index e7c7ed1c..45882d8a 100644
--- a/api/src/util/route.ts
+++ b/api/src/util/route.ts
@@ -81,10 +81,10 @@ export function route(opts: RouteOptions) {
return async (req: Request, res: Response, next: NextFunction) => {
if (opts.permission) {
const required = new Permissions(opts.permission);
- const permission = await getPermission(req.user_id, req.params.guild_id, req.params.channel_id);
+ req.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)) {
+ if (!req.permission.has(required)) {
throw DiscordApiErrors.MISSING_PERMISSIONS.withParams(opts.permission as string);
}
}
|