Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions routes/admin/events/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { withRouteSpec } from "lib/middleware/with-winter-spec"
import { z } from "zod"

const escapeHtml = (value: unknown): string =>
String(value ?? "")
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;")

export default withRouteSpec({
methods: ["GET"],
jsonResponse: z.any(),
Expand Down Expand Up @@ -34,13 +42,15 @@ export default withRouteSpec({
.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">${escapeHtml(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>
<td class="border border-gray-300 p-2">${escapeHtml(
JSON.stringify(rest)
.slice(1, -1)
.replace(/"([^"]+)":/g, "$1:"),
)}</td>
</tr>
`,
)
Expand Down
10 changes: 9 additions & 1 deletion routes/admin/files/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { withRouteSpec } from "lib/middleware/with-winter-spec"
import { z } from "zod"

const escapeHtml = (value: unknown): string =>
String(value ?? "")
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;")

export default withRouteSpec({
methods: ["GET"],
jsonResponse: z.any(),
Expand Down Expand Up @@ -32,7 +40,7 @@ export default withRouteSpec({
.map(
(file) => `
<tr>
<td>${file.file_path}</td>
<td>${escapeHtml(file.file_path)}</td>
<td>
<a href="./get?file_path=${encodeURIComponent(file.file_path)}">View Details</a>
</td>
Expand Down
23 changes: 23 additions & 0 deletions routes/files/download/[[file_path]].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { withRouteSpec } from "lib/middleware/with-winter-spec"
import { z } from "zod"

export default withRouteSpec({
methods: ["GET"],
pathParams: z.object({
file_path: z.string(),
}),
})((req, ctx) => {
const { file_path } = req.routeParams as { file_path: string }
const file = ctx.db.getFile({ file_path: `/${file_path}` })

if (!file) {
return new Response("File not found", { status: 404 })
}

return new Response(file.text_content, {
headers: {
"Content-Type": "text/plain",
"Content-Disposition": `attachment; filename="${file.file_path.split("/").pop()}"`,
},
})
})
Loading