verify paste length on server

This commit is contained in:
Lee 2024-04-23 21:23:18 +01:00
parent 9bd7a543d8
commit 4bb16d287b

@ -18,15 +18,6 @@ export default function Home(): ReactElement {
return; return;
} }
// Limit the paste size to 400,000 characters
if (value.length > 400_000) {
toast({
title: "Paste",
description: "Pastes can't be longer than 400,000 characters",
});
return;
}
// Upload the paste to the server // Upload the paste to the server
const response = await fetch( const response = await fetch(
`${process.env.NEXT_PUBLIC_API_ENDPOINT}/upload`, `${process.env.NEXT_PUBLIC_API_ENDPOINT}/upload`,
@ -39,8 +30,17 @@ export default function Home(): ReactElement {
}, },
); );
// Redirect to the new paste
const data = await response.json(); const data = await response.json();
if (!response.ok) {
toast({
title: "Paste",
description: data.message,
});
return;
}
// Redirect to the new paste
window.location.href = `/${data.id}`; window.location.href = `/${data.id}`;
} }