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") || [];
7
9];
10
11// Main function to handle HTTP requests
12export default async function(req: Request): Promise<Response> {
13 if (req.method === "GET") {
14 return getStories(req);
22}
23
24// Function to get the list of stories
25async function getStories(req: Request): Promise<Response> {
26 let existingStories = await blob.getJSON("hacker-news-stories");
27 return new Response(JSON.stringify(existingStories), { headers: { "Content-Type": "application/json" } });
28}
29
30// Function to submit a new story
31async function submitStory(req: Request): Promise<Response> {
32 const data = await req.json();
33 const newStory = { id: stories.length + 1, title: data.title, votes: 0 };
37}
38
39// Function to upvote a story
40async function upvoteStory(req: Request): Promise<Response> {
41 const data = await req.json();
42 const storyId = data.id;
8];
9
10// Main function to handle HTTP requests
11export default async function main(req: Request): Promise<Response> {
12 if (req.method === "GET") {
13 // Get the list of stories
38`;
39
40export default async function main(req: Request): Promise<Response> {
41 // Fetch existing comments
42 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
32`;
33
34export default async function main(req: Request): Promise<Response> {
35 // Fetch existing comments
36 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
32`;
33
34export default async function main(req: Request): Promise<Response> {
35 // Fetch existing comments
36 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
36`;
37
38export default async function main(req: Request): Promise<Response> {
39 // Fetch existing comments
40 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
35`;
36
37export default async function main(req: Request): Promise<Response> {
38 // Fetch existing comments
39 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
9const key = "comments";
10
11async function getComments(): Promise<Array<{ id: string; content: string }>> {
12 const comments = await blob.getJSON(key) as Array<{ id: string; content: string }> | undefined;
13 return comments ?? [];
14}
15
16async function addComment(content: string) {
17 const comments = await getComments();
18 comments.push({ id: ulid(), content });
20}
21
22export default async function main(req: Request): Promise<Response> {
23 if (req.method === "POST") {
24 const formData = await req.formData();
6const key = "comments";
7
8export default async function main(req: Request): Promise<Response> {
9 if (req.method === "POST") {
10 // Handle comment submission
Simple functional CSS library for Val Town
A helper function to build a file's email
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.