1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 05:02:37 +01:00

added profile banners

This commit is contained in:
BuildTools 2021-08-07 21:58:16 +03:00
parent 0e4674ee50
commit 98a780ad7c
6 changed files with 11 additions and 5 deletions

View File

@ -197,6 +197,7 @@ router.post(
discriminator,
avatar: null,
accent_color: null,
banner: null,
bot: false,
system: false,
desktop: false,

View File

@ -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 } })

View File

@ -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,
}

View File

@ -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

View File

@ -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,
}

View File

@ -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;
}