🐛 fix handleFile()
This commit is contained in:
		
							parent
							
								
									c396fac204
								
							
						
					
					
						commit
						30e05fdb86
					
				| @ -43,8 +43,8 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response) | |||||||
| 	const perms = await getPermission(req.user_id, guild_id); | 	const perms = await getPermission(req.user_id, guild_id); | ||||||
| 	perms.hasThrow("MANAGE_GUILD"); | 	perms.hasThrow("MANAGE_GUILD"); | ||||||
| 
 | 
 | ||||||
| 	body.icon = await handleFile("icons", body.icon); | 	body.icon = await handleFile(`/icons/${guild_id}`, body.icon); | ||||||
| 	body.banner = await handleFile("banners", body.banner); | 	body.banner = await handleFile(`/banners/${guild_id}`, body.banner); | ||||||
| 
 | 
 | ||||||
| 	const guild = await GuildModel.findOneAndUpdate({ id: guild_id }, body) | 	const guild = await GuildModel.findOneAndUpdate({ id: guild_id }, body) | ||||||
| 		.populate({ path: "joined_at", match: { id: req.user_id } }) | 		.populate({ path: "joined_at", match: { id: req.user_id } }) | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ router.get("/", async (req: Request, res: Response) => { | |||||||
| 
 | 
 | ||||||
| router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => { | router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => { | ||||||
| 	const body = req.body as UserModifySchema; | 	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(); | 	const user = await UserModel.findOneAndUpdate({ id: req.user_id }, body, { projection: PublicUserProjection }).exec(); | ||||||
| 	// TODO: dispatch user update event
 | 	// TODO: dispatch user update event
 | ||||||
|  | |||||||
| @ -31,9 +31,10 @@ export async function handleFile(path: string, body?: string): Promise<string | | |||||||
| 		const buffer = Buffer.from(body.split(",")[1], "base64"); | 		const buffer = Buffer.from(body.split(",")[1], "base64"); | ||||||
| 
 | 
 | ||||||
| 		// @ts-ignore
 | 		// @ts-ignore
 | ||||||
| 		const { id } = await uploadFile(`/${path}/${guild_id}`, { buffer, mimetype, originalname: "banner" }); | 		const { id } = await uploadFile(path, { buffer, mimetype, originalname: "banner" }); | ||||||
| 		return id; | 		return id; | ||||||
| 	} catch (error) { | 	} catch (error) { | ||||||
| 		throw new HTTPError("Invalid " + path); | 		console.error(error); | ||||||
|  | 		throw new HTTPError("Invalid icon"); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Flam3rboy
						Flam3rboy