remove admin routes until TinyAuth is set up
This commit is contained in:
parent
8a9c56c3d5
commit
c0d1feaacd
3 changed files with 1 additions and 72 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ dist
|
||||||
data
|
data
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
**/.env
|
**/.env
|
||||||
|
CLAUDE.md
|
||||||
|
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
---
|
|
||||||
export const prerender = false;
|
|
||||||
|
|
||||||
import { getPendingEntries, type GuestbookEntry } from '../lib/db';
|
|
||||||
import Layout from '../layouts/Layout.astro';
|
|
||||||
import { formatDate } from '../lib/format';
|
|
||||||
|
|
||||||
let entries: GuestbookEntry[] = [];
|
|
||||||
try {
|
|
||||||
entries = await getPendingEntries();
|
|
||||||
} catch {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
---
|
|
||||||
<Layout title="admin - guestbook" showHeader={false}>
|
|
||||||
|
|
||||||
<h1>guestbook admin</h1>
|
|
||||||
|
|
||||||
{entries.length === 0 ? (
|
|
||||||
<p class="muted">no pending entries</p>
|
|
||||||
) : (
|
|
||||||
<ul id="entries">
|
|
||||||
{entries.map(e => (
|
|
||||||
<li data-id={e.id}>
|
|
||||||
<span class="muted">{formatDate(e.createdAt)}</span>
|
|
||||||
<strong>{e.name}</strong>
|
|
||||||
{e.url && <a href={e.url}>{e.url}</a>}
|
|
||||||
<p>{e.message}</p>
|
|
||||||
<button class="approve">approve</button>
|
|
||||||
<button class="reject">reject</button>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<script>
|
|
||||||
document.querySelectorAll('#entries li').forEach(li => {
|
|
||||||
const id = li.getAttribute('data-id');
|
|
||||||
|
|
||||||
li.querySelector('.approve')?.addEventListener('click', async () => {
|
|
||||||
const res = await fetch(`/api/guestbook/${id}`, { method: 'PATCH' });
|
|
||||||
if (res.ok) li.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
li.querySelector('.reject')?.addEventListener('click', async () => {
|
|
||||||
const res = await fetch(`/api/guestbook/${id}`, { method: 'DELETE' });
|
|
||||||
if (res.ok) li.remove();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</Layout>
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
import type { APIRoute } from 'astro';
|
|
||||||
import { approveEntry, deleteEntry } from '../../../lib/db';
|
|
||||||
import { jsonResponse, errorResponse } from '../../../lib/api';
|
|
||||||
|
|
||||||
export const prerender = false;
|
|
||||||
|
|
||||||
export const PATCH: APIRoute = async ({ params }) => {
|
|
||||||
const id = parseInt(params.id!, 10);
|
|
||||||
if (isNaN(id)) return errorResponse('Invalid ID', 400);
|
|
||||||
|
|
||||||
await approveEntry(id);
|
|
||||||
return jsonResponse({ success: true });
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DELETE: APIRoute = async ({ params }) => {
|
|
||||||
const id = parseInt(params.id!, 10);
|
|
||||||
if (isNaN(id)) return errorResponse('Invalid ID', 400);
|
|
||||||
|
|
||||||
await deleteEntry(id);
|
|
||||||
return jsonResponse({ success: true });
|
|
||||||
};
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue