25 const fetchIdeas = async () => {
26 try {
27 const response = await fetch("/api/ideas");
28 if (response.ok) {
29 const data = await response.json();
53 }
54
55 const response = await fetch("/api/ideas", {
56 method: "POST",
57 body: formDataToSend,
74 const handleLike = async (ideaId: number) => {
75 try {
76 const response = await fetch(`/api/ideas/${ideaId}/like`, {
77 method: "POST",
78 });
46 await blob.set(fileKey, fileContent);
47
48 fileUrl = `/api/files/${fileKey}`;
49 fileName = file.name;
50 } catch (fileError) {
36 const fetchMessages = async () => {
37 try {
38 const response = await fetch("/api/chat/messages");
39 if (response.ok) {
40 const data = await response.json();
50 const fetchInvitations = async () => {
51 try {
52 const response = await fetch(`/api/chat/wlp/invitations/${user.id}`);
53 if (response.ok) {
54 const data = await response.json();
84 }
85
86 const response = await fetch("/api/chat/messages", {
87 method: "POST",
88 body: formData,
127 try {
128 // First check if user exists
129 const userResponse = await fetch(`/api/users/check/${encodeURIComponent(inviteeName.trim())}`);
130 if (!userResponse.ok) return;
131
137
138 // Send invitation
139 const response = await fetch("/api/chat/wlp/invite", {
140 method: "POST",
141 headers: {
160 const handleInvitationResponse = async (invitationId: number, status: "accepted" | "declined") => {
161 try {
162 const response = await fetch("/api/chat/wlp/respond", {
163 method: "POST",
164 headers: {
14app.get("/shared/*", c => serveFile(c.req.path, import.meta.url));
15
16// API Routes
17app.get("/api/courses", (c) => {
18 return c.json(COURSES);
19});
20
21app.get("/api/courses/:courseId", (c) => {
22 const courseId = c.req.param("courseId");
23 const course = COURSES.find(course => course.id === courseId);
30});
31
32app.get("/api/contact", (c) => {
33 return c.json(CONTACT_INFO);
34});
35
36app.get("/api/pricing", (c) => {
37 return c.json(PRICING);
38});
1# TLDR This - Article Summarizer
2
3A simple web application that summarizes articles and URLs into 1-3 sentence summaries using OpenAI's API.
4
5## Features
6
7- **Simple Interface**: Clean textarea for pasting URLs or article text
8- **Smart Summarization**: Uses OpenAI API to generate concise 1-3 sentence summaries
9- **URL Support**: Automatically fetches and summarizes content from URLs
10- **Error Handling**: Graceful handling of invalid URLs, API failures, and other errors
11- **Responsive Design**: Works well on desktop and mobile devices
12
15```
16โโโ backend/
17โ โโโ index.ts # Main Hono server with API routes
18โ โโโ README.md # Backend documentation
19โโโ frontend/
31## Setup Instructions
32
331. **Environment Variables**: Set up your OpenAI API key in Val Town environment variables:
34 - Go to your Val Town settings
35 - Add environment variable: `OPENAI_API_KEY` with your OpenAI API key
36
372. **Deploy**: The app will automatically deploy when you save the files in Val Town
393. **Access**: Your app will be available at your Val Town HTTP endpoint
40
41## API Endpoints
42
43- `GET /` - Serves the main application
44- `POST /api/summarize` - Summarizes text or URL content
45- `GET /frontend/*` - Serves frontend assets
46- `GET /shared/*` - Serves shared utilities
59The app handles various error scenarios:
60- Invalid or unreachable URLs
61- OpenAI API failures or rate limits
62- Network connectivity issues
63- Malformed input data
137}
138
139// API endpoint for summarization
140app.post("/api/summarize", async c => {
141 try {
142 const body: SummarizeRequest = await c.req.json();
203
204// Health check endpoint
205app.get("/api/health", c => {
206 return c.json({ status: "ok", timestamp: new Date().toISOString() });
207});
37 };
38
39 const response = await fetch("/api/summarize", {
40 method: "POST",
41 headers: {
29 setLoading(false);
30 } else {
31 // Fallback to API calls if no initial data
32 loadData();
33 }
38 setLoading(true);
39 const [cyclesRes, symptomsRes, predictionRes] = await Promise.all([
40 fetch('/api/cycles'),
41 fetch('/api/symptoms'),
42 fetch('/api/cycles/predictions/next').catch(() => ({ ok: false }))
43 ]);
44
68 try {
69 const [cyclesRes, predictionRes] = await Promise.all([
70 fetch('/api/cycles'),
71 fetch('/api/cycles/predictions/next').catch(() => ({ ok: false }))
72 ]);
73
91 // Reload symptoms after update
92 try {
93 const symptomsRes = await fetch('/api/symptoms');
94 if (symptomsRes.ok) {
95 const symptomsData = await symptomsRes.json();
1# Backend - Pastry Shop API
2
3This directory contains the server-side logic for the pastry ordering system.
6
7- `index.ts` - Main Hono application with routes and static file serving
8- `routes/orders.ts` - Order management API endpoints
9- `database/` - Database setup and query functions
10
11## API Endpoints
12
13### Orders
14- `POST /api/orders` - Create a new order
15- `GET /api/orders` - Get all orders (for admin)
16- `PATCH /api/orders/:id/status` - Update order status
17
18### Pages
49## Error Handling
50
51- Input validation for all API endpoints
52- Proper HTTP status codes
53- Detailed error messages for debugging
24
25- ES6 modules for clean code organization
26- Async/await for API calls
27- Form validation and error handling
28- Local cart state management