From 15360eb6b952a7306c4d2bc9173ac9a391ad4f4d Mon Sep 17 00:00:00 2001 From: NotNite Date: Fri, 28 Apr 2023 12:08:36 -0400 Subject: [PATCH] raise avatar limits to 2 MB, 1024x1024 --- src/app/api/update/route.ts | 2 +- src/app/register/RegisterForm.tsx | 2 +- src/app/register/page.tsx | 2 +- src/image.ts | 2 +- src/schemas.ts | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/api/update/route.ts b/src/app/api/update/route.ts index 177b837..3e79cf6 100644 --- a/src/app/api/update/route.ts +++ b/src/app/api/update/route.ts @@ -53,7 +53,7 @@ export async function POST(request: Request) { ) { avatarBuf = Buffer.from(avatarBase64, "base64"); - if (avatarBuf.length > 1_000_000) { + if (avatarBuf.length > 2_000_000) { return new Response( JSON.stringify({ ok: false, diff --git a/src/app/register/RegisterForm.tsx b/src/app/register/RegisterForm.tsx index 0ac01c9..d69b25b 100644 --- a/src/app/register/RegisterForm.tsx +++ b/src/app/register/RegisterForm.tsx @@ -141,7 +141,7 @@ export default function RegisterForm({ (avatarSource != null ? `We found your avatar from ${avatarSource}, but you can change it if you'd like.` : "") + - " This will automatically be used as your avatar with supported services - maximum 1 MB. " + " This will automatically be used as your avatar with supported services - maximum 2 MB. " } type="file" name="avatar" diff --git a/src/app/register/page.tsx b/src/app/register/page.tsx index a2ef87c..437ea29 100644 --- a/src/app/register/page.tsx +++ b/src/app/register/page.tsx @@ -55,7 +55,7 @@ export default async function Page({ const blob = await req.blob(); const arrayBuffer = await blob.arrayBuffer(); const buffer = Buffer.from(arrayBuffer); - if (buffer.length <= 1_000_000) { + if (buffer.length <= 2_000_000) { // I hope you are doing well, you deserve the best of luck while working on this project -Ari try { const jpg = await ensureJpg(buffer); diff --git a/src/image.ts b/src/image.ts index 82026c9..3e867a1 100644 --- a/src/image.ts +++ b/src/image.ts @@ -1,7 +1,7 @@ import sharp from "sharp"; export async function ensureJpg(avatar: Buffer) { - const img = await sharp(avatar).toFormat("jpeg").resize(512, 512); + const img = await sharp(avatar).toFormat("jpeg").resize(1024, 1024); const buf = await img.toBuffer(); return buf.toString("base64"); } diff --git a/src/schemas.ts b/src/schemas.ts index 846400c..b9630ba 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -19,13 +19,13 @@ const CONFIRM_PASSWORD = (name: string) => const AVATAR = Yup.string().test( "file-size", - "File is bigger than 1 MB.", + "File is bigger than 2 MB.", (value) => { if (value == null) return true; try { const buf = Buffer.from(value, "base64"); - return buf.length <= 1_000_000; + return buf.length <= 2_000_000; } catch (e) { return false; }