Skip to content

Commit

Permalink
add helpful admin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Dec 30, 2024
1 parent 324b570 commit 5419c40
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
59 changes: 59 additions & 0 deletions routes/admin/events/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { withRouteSpec } from "lib/middleware/with-winter-spec"
import { z } from "zod"

export default withRouteSpec({
methods: ["GET"],
jsonResponse: z.any(),
})((req, ctx) => {
const events = ctx.db.events

return new Response(
`<html>
<head>
<title>Events List</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="p-4">
<h1 class="text-3xl font-bold mb-8">Events</h1>
<table class="w-full border-collapse border border-gray-300">
<thead>
<tr class="bg-gray-100">
<th class="border border-gray-300 p-2">Event Type</th>
<th class="border border-gray-300 p-2">Created At</th>
<th class="border border-gray-300 p-2">Details</th>
</tr>
</thead>
<tbody>
${events
.sort(
(a, b) =>
new Date(b.created_at).valueOf() -
new Date(a.created_at).valueOf(),
)
.map(
({ event_type, event_id, created_at, ...rest }) => `
<tr>
<td class="border border-gray-300 p-2">${event_type}</td>
<td class="border border-gray-300 p-2">${new Date(
created_at,
).toLocaleString()}</td>
<td class="border border-gray-300 p-2">${JSON.stringify(rest)
.slice(1, -1)
.replace(/"([^"]+)":/g, "$1:")}</td>
</tr>
`,
)
.join("")}
</tbody>
</table>
</div>
</body>
</html>`,
{
headers: {
"Content-Type": "text/html; charset=utf-8",
},
},
)
})
4 changes: 2 additions & 2 deletions routes/admin/files/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default withRouteSpec({
</head>
<body>
<div class="container">
<p><a href="/admin/files/list">← Back to file list</a></p>
<p><a href="./list">← Back to file list</a></p>
<h1>Create New File</h1>
<form method="POST">
<div class="form-group">
Expand All @@ -77,7 +77,7 @@ export default withRouteSpec({
</html>`,
{
headers: {
"Content-Type": "text/html",
"Content-Type": "text/html; charset=utf-8",
},
},
)
Expand Down
4 changes: 2 additions & 2 deletions routes/admin/files/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default withRouteSpec({
</head>
<body>
<div class="container">
<p><a href="/admin/files/list">← Back to file list</a></p>
<p><a href="./list">← Back to file list</a></p>
<h1>File Details</h1>
<div class="details">
<p><span class="label">File ID:</span> ${file.file_id}</p>
Expand All @@ -44,7 +44,7 @@ export default withRouteSpec({
</html>`,
{
headers: {
"Content-Type": "text/html",
"Content-Type": "text/html; charset=utf-8",
},
},
)
Expand Down
4 changes: 2 additions & 2 deletions routes/admin/files/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default withRouteSpec({
</head>
<body>
<h1>Files</h1>
<p><a href="/admin/files/create" style="background-color: #4CAF50; color: white; padding: 10px 15px; border-radius: 4px; text-decoration: none; display: inline-block; margin-bottom: 20px;">Create New File</a></p>
<p><a href="./create" style="background-color: #4CAF50; color: white; padding: 10px 15px; border-radius: 4px; text-decoration: none; display: inline-block; margin-bottom: 20px;">Create New File</a></p>
<table>
<tr>
<th>File Path</th>
Expand All @@ -45,7 +45,7 @@ export default withRouteSpec({
</html>`,
{
headers: {
"Content-Type": "text/html",
"Content-Type": "text/html; charset=utf-8",
},
},
)
Expand Down
36 changes: 36 additions & 0 deletions routes/admin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { withRouteSpec } from "lib/middleware/with-winter-spec"
import { z } from "zod"

export default withRouteSpec({
methods: ["GET"],
jsonResponse: z.any(),
})((req, ctx) => {
return new Response(
`<html>
<head>
<title>file-server Admin Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="max-w-4xl mx-auto px-4 py-8">
<h1 class="text-3xl font-bold mb-8">file-server Admin Dashboard</h1>
<nav>
<ul class="space-y-4">
<li>
<a href="./admin/files/list" class="block px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors">File Management</a>
</li>
<li>
<a href="./admin/events/list" class="block px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors">Event Management</a>
</li>
</ul>
</nav>
</div>
</body>
</html>`,
{
headers: {
"Content-Type": "text/html",
},
},
)
})

0 comments on commit 5419c40

Please sign in to comment.