raise avatar limits to 2 MB, 1024x1024

This commit is contained in:
Julian 2023-04-28 12:08:36 -04:00
parent da5373ef25
commit 15360eb6b9
Signed by: NotNite
GPG key ID: BD91A5402CCEB08A
5 changed files with 6 additions and 6 deletions

View file

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

View file

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

View file

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

View file

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

View file

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