mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
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:
@@ -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}`
|
||||
|
||||
Reference in New Issue
Block a user