forked from NotNet/gluestick
raise avatar limits to 2 MB, 1024x1024
This commit is contained in:
parent
da5373ef25
commit
15360eb6b9
|
@ -53,7 +53,7 @@ export async function POST(request: Request) {
|
||||||
) {
|
) {
|
||||||
avatarBuf = Buffer.from(avatarBase64, "base64");
|
avatarBuf = Buffer.from(avatarBase64, "base64");
|
||||||
|
|
||||||
if (avatarBuf.length > 1_000_000) {
|
if (avatarBuf.length > 2_000_000) {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
ok: false,
|
ok: false,
|
||||||
|
|
|
@ -141,7 +141,7 @@ export default function RegisterForm({
|
||||||
(avatarSource != null
|
(avatarSource != null
|
||||||
? `We found your avatar from ${avatarSource}, but you can change it if you'd like.`
|
? `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"
|
type="file"
|
||||||
name="avatar"
|
name="avatar"
|
||||||
|
|
|
@ -55,7 +55,7 @@ export default async function Page({
|
||||||
const blob = await req.blob();
|
const blob = await req.blob();
|
||||||
const arrayBuffer = await blob.arrayBuffer();
|
const arrayBuffer = await blob.arrayBuffer();
|
||||||
const buffer = Buffer.from(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
|
// I hope you are doing well, you deserve the best of luck while working on this project -Ari
|
||||||
try {
|
try {
|
||||||
const jpg = await ensureJpg(buffer);
|
const jpg = await ensureJpg(buffer);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
|
|
||||||
export async function ensureJpg(avatar: Buffer) {
|
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();
|
const buf = await img.toBuffer();
|
||||||
return buf.toString("base64");
|
return buf.toString("base64");
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,13 @@ const CONFIRM_PASSWORD = (name: string) =>
|
||||||
|
|
||||||
const AVATAR = Yup.string().test(
|
const AVATAR = Yup.string().test(
|
||||||
"file-size",
|
"file-size",
|
||||||
"File is bigger than 1 MB.",
|
"File is bigger than 2 MB.",
|
||||||
(value) => {
|
(value) => {
|
||||||
if (value == null) return true;
|
if (value == null) return true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const buf = Buffer.from(value, "base64");
|
const buf = Buffer.from(value, "base64");
|
||||||
return buf.length <= 1_000_000;
|
return buf.length <= 2_000_000;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue