2 // Helper functions for Blob storage
3 async function getBlob(key: string): Promise<any> {
4 const response = await fetch(`https://api.val.town/v/std/blob-${key}`);
5 if (!response.ok) throw new Error("Error fetching blob data");
6 return response.json();
7 }
8
9 async function setBlob(key: string, data: any): Promise<void> {
10 const response = await fetch(`https://api.val.town/v/std/blob-${key}`, {
11 method: "POST",
12 headers: { "Content-Type": "application/json" },
42 <li>
43 <a href="${story.url}">${story.title}</a>
44 <button onclick="fetch('/vote?id=${story.id}', { method: 'POST' }).then(() => location.reload())">Upvote (${story.votes})</button>
45 </li>`).join('')}
46 </ul>
79});
80
81export default app.fetch;
82
24}
25
26// Fetch all stored stories
27async function getStories() {
28 return (await blob.getJSON(storiesKey)) || [];
66export default async function main(req: Request): Promise<Response> {
67 await initializeStories();
68 return app.fetch(req);
69}
70
64});
65
66// Export the Hono app as the default fetch handler
67export default app.fetch;
68
52});
53
54export default app.fetch;
55
64});
65
66export default app.fetch;
67
2import { blob } from "https://esm.town/v/std/blob";
3
4// Fetch all stories or initialize an empty array if no data exists yet
5export default async function main(req: Request): Promise<Response> {
6 let stories = await blob.getJSON("hackerNewsStories") || [];
39
40export default async function main(req: Request): Promise<Response> {
41 // Fetch existing comments
42 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
43
33
34export default async function main(req: Request): Promise<Response> {
35 // Fetch existing comments
36 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
37
33
34export default async function main(req: Request): Promise<Response> {
35 // Fetch existing comments
36 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
37