diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-07 21:18:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-07 21:18:11 +0200 |
commit | a95ecf42876d80093ed0beb0bf98ef5d28b922dc (patch) | |
tree | 5ee3e937312af799008c264a469e817ade4443b6 | |
parent | :pencil: features list (diff) | |
parent | npm i @fosscord/server-util@1.3.40 (diff) | |
download | server-a95ecf42876d80093ed0beb0bf98ef5d28b922dc.tar.xz |
Merge pull request #190 from BanTheNons/profile-banners
Implemented profile banners!
-rw-r--r-- | package-lock.json | 14 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/routes/auth/register.ts | 1 | ||||
-rw-r--r-- | src/routes/guilds/#guild_id/index.ts | 4 | ||||
-rw-r--r-- | src/routes/users/#id/profile.ts | 1 | ||||
-rw-r--r-- | src/routes/users/@me/index.ts | 5 | ||||
-rw-r--r-- | src/routes/users/@me/profile.ts | 1 | ||||
-rw-r--r-- | src/schema/User.ts | 4 |
8 files changed, 19 insertions, 13 deletions
diff --git a/package-lock.json b/package-lock.json index e18715bc..db6d1111 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@fosscord/server-util": "^1.3.39", + "@fosscord/server-util": "^1.3.40", "@types/jest": "^26.0.22", "@types/json-schema": "^7.0.7", "ajv": "^8.4.0", @@ -678,9 +678,9 @@ } }, "node_modules/@fosscord/server-util": { - "version": "1.3.39", - "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.39.tgz", - "integrity": "sha512-skDV2SMBsKMy0Ngz73aXHi9Nkhx6V6FH9pi9TuiJam976g2Dv/QWaBgfPgPNYu6euta986PTFrOqi8R8D2WYWw==", + "version": "1.3.40", + "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.40.tgz", + "integrity": "sha512-LXB5Dby4dVNgIXy6Fehx+EsTboTy+Dbs5cqWj4av776qHfcn/EndyZLWX5XKcS++xJocHU8ci+A8T7ZaN04oiQ==", "dependencies": { "@types/jsonwebtoken": "^8.5.0", "@types/mongoose-autopopulate": "^0.10.1", @@ -11457,9 +11457,9 @@ } }, "@fosscord/server-util": { - "version": "1.3.39", - "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.39.tgz", - "integrity": "sha512-skDV2SMBsKMy0Ngz73aXHi9Nkhx6V6FH9pi9TuiJam976g2Dv/QWaBgfPgPNYu6euta986PTFrOqi8R8D2WYWw==", + "version": "1.3.40", + "resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.40.tgz", + "integrity": "sha512-LXB5Dby4dVNgIXy6Fehx+EsTboTy+Dbs5cqWj4av776qHfcn/EndyZLWX5XKcS++xJocHU8ci+A8T7ZaN04oiQ==", "requires": { "@types/jsonwebtoken": "^8.5.0", "@types/mongoose-autopopulate": "^0.10.1", diff --git a/package.json b/package.json index 9a99640f..87fdda61 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "homepage": "https://github.com/fosscord/fosscord-api#readme", "dependencies": { - "@fosscord/server-util": "^1.3.39", + "@fosscord/server-util": "^1.3.40", "@types/jest": "^26.0.22", "@types/json-schema": "^7.0.7", "ajv": "^8.4.0", diff --git a/src/routes/auth/register.ts b/src/routes/auth/register.ts index 279103bc..f9005655 100644 --- a/src/routes/auth/register.ts +++ b/src/routes/auth/register.ts @@ -197,6 +197,7 @@ router.post( discriminator, avatar: null, accent_color: null, + banner: null, bot: false, system: false, desktop: false, diff --git a/src/routes/guilds/#guild_id/index.ts b/src/routes/guilds/#guild_id/index.ts index 8e052f6d..404a289a 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/${guild_id}`, body.icon); - body.banner = await handleFile(`/banners/${guild_id}`, body.banner); + if (body.icon) body.icon = await handleFile(`/icons/${guild_id}`, body.icon); + if(body.banner) 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/#id/profile.ts b/src/routes/users/#id/profile.ts index b86b0b90..4b4b9439 100644 --- a/src/routes/users/#id/profile.ts +++ b/src/routes/users/#id/profile.ts @@ -17,6 +17,7 @@ router.get("/", async (req: Request, res: Response) => { public_flags: user.public_flags, avatar: user.avatar, accent_color: user.accent_color, + banner: user.banner, bio: req.user_bot ? null : user.bio, bot: user.bot, } diff --git a/src/routes/users/@me/index.ts b/src/routes/users/@me/index.ts index 185e44d4..f6b29958 100644 --- a/src/routes/users/@me/index.ts +++ b/src/routes/users/@me/index.ts @@ -1,6 +1,5 @@ import { Router, Request, Response } from "express"; import { UserModel, toObject, PublicUserProjection } from "@fosscord/server-util"; -import { HTTPError } from "lambert-server"; import { getPublicUser } from "../../../util/User"; import { UserModifySchema } from "../../../schema/User"; import { check } from "../../../util/instanceOf"; @@ -14,7 +13,9 @@ 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(`/avatars/${req.user_id}`, body.avatar as string); + + if(body.avatar) body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string); + if (body.banner) body.banner = await handleFile(`/banners/${req.user_id}`, body.banner as string); const user = await UserModel.findOneAndUpdate({ id: req.user_id }, body, { projection: PublicUserProjection }).exec(); // TODO: dispatch user update event diff --git a/src/routes/users/@me/profile.ts b/src/routes/users/@me/profile.ts index 0d295d05..b67d1964 100644 --- a/src/routes/users/@me/profile.ts +++ b/src/routes/users/@me/profile.ts @@ -17,6 +17,7 @@ router.get("/", async (req: Request, res: Response) => { public_flags: user.public_flags, avatar: user.avatar, accent_color: user.accent_color, + banner: user.banner, bio: user.bio, bot: user.bot, } diff --git a/src/schema/User.ts b/src/schema/User.ts index ae213ee3..77ee08b4 100644 --- a/src/schema/User.ts +++ b/src/schema/User.ts @@ -4,7 +4,8 @@ export const UserModifySchema = { $username: new Length(String, 2, 32), $avatar: String, $bio: new Length(String, 0, 190), - $accent_color: Number + $accent_color: Number, + $banner: String }; export interface UserModifySchema { @@ -12,4 +13,5 @@ export interface UserModifySchema { avatar?: string | null; bio?: string; accent_color?: number | null; + banner?: string | null; } |