summary refs log tree commit diff
path: root/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/guilds/#guild_id/index.ts6
-rw-r--r--src/routes/users/@me/index.ts16
2 files changed, 7 insertions, 15 deletions
diff --git a/src/routes/guilds/#guild_id/index.ts b/src/routes/guilds/#guild_id/index.ts

index 3af49106..8e052f6d 100644 --- a/src/routes/guilds/#guild_id/index.ts +++ b/src/routes/guilds/#guild_id/index.ts
@@ -17,6 +17,7 @@ import { HTTPError } from "lambert-server"; import { GuildUpdateSchema } from "../../../schema/Guild"; import { emitEvent } from "../../../util/Event"; import { check } from "../../../util/instanceOf"; +import { handleFile } from "../../../util/cdn"; import "missing-native-js-functions"; const router = Router(); @@ -42,6 +43,9 @@ 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/${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 } }) .exec(); @@ -50,7 +54,7 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response) emitEvent({ event: "GUILD_UPDATE", data: data, guild_id } as GuildUpdateEvent); - return res.send(data); + return res.json(data); }); export default router; diff --git a/src/routes/users/@me/index.ts b/src/routes/users/@me/index.ts
index 68196afe..185e44d4 100644 --- a/src/routes/users/@me/index.ts +++ b/src/routes/users/@me/index.ts
@@ -4,7 +4,7 @@ import { HTTPError } from "lambert-server"; import { getPublicUser } from "../../../util/User"; import { UserModifySchema } from "../../../schema/User"; import { check } from "../../../util/instanceOf"; -import { uploadFile } from "../../../util/cdn"; +import { handleFile } from "../../../util/cdn"; const router: Router = Router(); @@ -14,19 +14,7 @@ router.get("/", async (req: Request, res: Response) => { router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => { const body = req.body as UserModifySchema; - - if (body.avatar) { - try { - const mimetype = body.avatar.split(":")[1].split(";")[0]; - const buffer = Buffer.from(body.avatar.split(",")[1], "base64"); - - // @ts-ignore - const { id } = await uploadFile(`/avatars/${req.user_id}`, { buffer, mimetype, originalname: "avatar" }); - body.avatar = id; - } catch (error) { - throw new HTTPError("Invalid avatar"); - } - } + 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