1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// This approach uses HTML for the form and Blob storage for persistence.
// We'll use the built-in Request and Response objects for handling HTTP.
// The form fields are customized for video information collection.
// We'll add JSON API endpoints for Framer Fetch integration.
import { blob } from "https://esm.town/v/std/blob";
const KEY = new URL(import.meta.url).pathname;
export default async function main(req: Request): Promise<Response> {
const url = new URL(req.url);
// API endpoints for Framer Fetch
if (url.pathname === "/api/entries") {
if (req.method === "GET") {
const entries = await blob.getJSON(KEY).catch(() => []) || [];
return Response.json(entries);
} else if (req.method === "POST") {
const entry = await req.json();
const entries = await blob.getJSON(KEY).catch(() => []) || [];
entries.push(entry);
await blob.setJSON(KEY, entries);
return Response.json({ success: true });
}
}
// HTML form handling
if (req.method === "POST") {
const formData = await req.formData();
const entry = Object.fromEntries(formData);
const entries = await blob.getJSON(KEY).catch(() => []) || [];
entries.push(entry);
await blob.setJSON(KEY, entries);
return Response.redirect(req.url);
}
// Retrieve existing entries
const entries = await blob.getJSON(KEY).catch(() => []) || [];
const html = `
<!DOCTYPE html>
<html>
<body>
<form method="POST">
<input name="title" placeholder="Video Title" required><br>
<input name="url" type="url" placeholder="Video URL" required><br>
<input name="date" type="date" required><br>
<input name="speaker" placeholder="Speaker" required><br>
<textarea name="description" placeholder="Description" required></textarea><br>
<button type="submit">Submit</button>
</form>
<h2>Entries:</h2>
<ul>
${entries.map(entry => `
<li>${Object.entries(entry).map(([k, v]) => `${k}: ${v}`).join(', ')}</li>
`).join('')}
</ul>
</body>
</html>
`;
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
}