feat: reporting apis; better rate limiting

refactor: change certain apis to be more REST like (e.g. DELETE /api/paste/{pasteId}/delete -> DELETE /api/paste/{pasteId}
This commit is contained in:
2026-01-10 00:06:36 -05:00
parent 864a4ee91a
commit 14bbd9c762
15 changed files with 954 additions and 48 deletions
@@ -8,8 +8,8 @@ const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
const { id } = params;
const paste = await fetch(`${apiUrl}/api/paste/${id}`);
if (paste.status === 404) {
const pasteRes = await fetch(`${apiUrl}/api/paste/${id}`);
if (pasteRes.status === 404) {
return {
status: 404,
error: { message: 'Paste not found' }
@@ -27,7 +27,9 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
}
});
const pasteData = (await paste.json()) as Paste;
const pasteData = await pasteRes.json();
const paste = pasteData.paste as Paste;
if (viewed.status === 200) {
const viewJson = await viewed.json();
if (viewJson.success === true && viewJson.message !== 'View already recorded.') {
@@ -49,5 +51,5 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
const options = await pasteOptions.json();
const content = await pasteContent.text();
return { paste: pasteData, content, options, url: url.href };
return { paste, content, options, url: url.href };
};
@@ -171,7 +171,7 @@
const encrypted = await encryptAES(content, password);
content = encrypted;
}
const res = await fetch(`/api/paste/${data.paste.id}/edit`, {
const res = await fetch(`/api/paste/${data.paste.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
@@ -196,7 +196,7 @@
metadata?.title !== data.paste.title) &&
metadata !== null
) {
const res = await fetch(`/api/paste/${data.paste.id}/modify`, {
const res = await fetch(`/api/paste/${data.paste.id}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
@@ -582,7 +582,7 @@
if (!token) {
return;
}
const res = await fetch(`/api/paste/${data.paste?.id}/delete`, {
const res = await fetch(`/api/paste/${data.paste?.id}`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${token}`