diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-07 19:21:00 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-07 19:21:00 +0200 |
commit | 30e05fdb86df8393cefa299ac7ffa53d2af2b5a2 (patch) | |
tree | adc1d81e11882924a0f401834e282b55a6c29cbd | |
parent | :art: add handleFile() (diff) | |
download | server-30e05fdb86df8393cefa299ac7ffa53d2af2b5a2.tar.xz |
:bug: fix handleFile()
-rw-r--r-- | src/routes/guilds/#guild_id/index.ts | 4 | ||||
-rw-r--r-- | src/routes/users/@me/index.ts | 2 | ||||
-rw-r--r-- | src/util/cdn.ts | 5 |
3 files changed, 6 insertions, 5 deletions
diff --git a/src/routes/guilds/#guild_id/index.ts b/src/routes/guilds/#guild_id/index.ts index a2dfeeda..8e052f6d 100644 --- a/src/routes/guilds/#guild_id/index.ts +++ b/src/routes/guilds/#guild_id/index.ts @@ -43,8 +43,8 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response) const perms = await getPermission(req.user_id, guild_id); perms.hasThrow("MANAGE_GUILD"); - body.icon = await handleFile("icons", body.icon); - body.banner = await handleFile("banners", body.banner); + body.icon = await handleFile(`/icons/${guild_id}`, body.icon); + body.banner = await handleFile(`/banners/${guild_id}`, body.banner); const guild = await GuildModel.findOneAndUpdate({ id: guild_id }, body) .populate({ path: "joined_at", match: { id: req.user_id } }) diff --git a/src/routes/users/@me/index.ts b/src/routes/users/@me/index.ts index 25a05da3..185e44d4 100644 --- a/src/routes/users/@me/index.ts +++ b/src/routes/users/@me/index.ts @@ -14,7 +14,7 @@ router.get("/", async (req: Request, res: Response) => { router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => { const body = req.body as UserModifySchema; - body.avatar = await handleFile(body.avatar as string); + body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string); const user = await UserModel.findOneAndUpdate({ id: req.user_id }, body, { projection: PublicUserProjection }).exec(); // TODO: dispatch user update event diff --git a/src/util/cdn.ts b/src/util/cdn.ts index fb0cfb53..b0d0f62a 100644 --- a/src/util/cdn.ts +++ b/src/util/cdn.ts @@ -31,9 +31,10 @@ export async function handleFile(path: string, body?: string): Promise<string | const buffer = Buffer.from(body.split(",")[1], "base64"); // @ts-ignore - const { id } = await uploadFile(`/${path}/${guild_id}`, { buffer, mimetype, originalname: "banner" }); + const { id } = await uploadFile(path, { buffer, mimetype, originalname: "banner" }); return id; } catch (error) { - throw new HTTPError("Invalid " + path); + console.error(error); + throw new HTTPError("Invalid icon"); } } |