21
22 try {
23 const response = await fetch(`/api/weather/${encodeURIComponent(location)}`);
24
25 if (!response.ok) {
43 const fetchRecentSearches = async () => {
44 try {
45 const response = await fetch("/api/history");
46 if (response.ok) {
47 const data = await response.json();
55 const clearSearchHistory = async () => {
56 try {
57 const response = await fetch("/api/history", {
58 method: "DELETE"
59 });
102
103 <footer className="mt-12 text-center text-white text-opacity-70 text-sm">
104 <p>Data provided by Open-Meteo API</p>
105 <p className="mt-1">
106 <a
2import type { WeatherData, CurrentWeather, ForecastDay, Location } from "../shared/types.ts";
3
4// Geocoding API to get coordinates from location name
5export async function getCoordinates(locationName: string): Promise<Location | null> {
6 try {
7 const response = await fetch(
8 `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(locationName)}&count=1&language=en&format=json`
9 );
10
28}
29
30// Fetch current weather and forecast data from Open-Meteo API
31export async function getWeatherData(latitude: number, longitude: number): Promise<WeatherData | null> {
32 try {
33 const response = await fetch(
34 `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,relative_humidity_2m,weather_code,wind_speed_10m,wind_direction_10m&daily=weather_code,temperature_2m_max,temperature_2m_min,sunrise,sunset,precipitation_sum&timezone=auto&forecast_days=4`
35 );
36
6- Serving HTML content
7- Client-side JavaScript
8- API integration
9- Basic UI with TailwindCSS
10
16## Features
17
181. **Current Time API**: Fetches the current server time from a backend API endpoint
192. **Click Counter**: Simple client-side counter with increment and reset functionality
203. **Responsive Design**: Mobile-friendly layout using TailwindCSS
22## How to Use
23
241. Click the "Get Current Time" button to fetch the current server time from the API
252. Use the increment and reset buttons to manage the counter
263. View the source code by clicking the "View Source" link
56 document.getElementById('timeButton').addEventListener('click', async () => {
57 try {
58 const response = await fetch('/api/time');
59 if (!response.ok) {
60 throw new Error(`Server responded with status: ${response.status}`);
9});
10
11// API endpoint to get current time
12app.get("/api/time", (c) => {
13 return c.json({
14 time: new Date().toISOString(),
1// @your-handle.minutesApi.ts
2import { sqlite } from "https://esm.town/v/std/sqlite";
3
22- CSS3 with custom properties
23- TailwindCSS for utility classes
24- Intersection Observer API for scroll animations
25
26## How to Use
34- The page is implemented as a JavaScript HTTP endpoint in Val Town
35- The logo SVG is embedded in the JavaScript file and served dynamically
36- The page uses Intersection Observer API to create scroll-triggered animations
37
38## Future Enhancements
14 // This is a fallback and won't have the same quality as Google TTS
15
16 // For this example, we'll use the VoiceRSS API (requires API key)
17 // In a real implementation, you would use your preferred fallback service
18 const apiKey = Deno.env.get("VOICERSS_API_KEY");
19
20 if (!apiKey) {
21 console.log("No VoiceRSS API key found for fallback TTS");
22 // Return empty audio if no API key is available
23 return new Uint8Array(0);
24 }
25
26 // Limit text length to avoid API limits
27 const limitedText = text.substring(0, 2000);
28
29 const params = new URLSearchParams({
30 key: apiKey,
31 src: limitedText,
32 hl: "en-us",
37 });
38
39 const response = await fetch(`https://api.voicerss.org/?${params.toString()}`);
40
41 if (!response.ok) {
42 throw new Error(`VoiceRSS API error: ${response.statusText}`);
43 }
44
191
192 try {
193 const response = await fetch('/api/debug');
194 const data = await response.json();
195
198 // Check OpenAI
199 if (data.environment.hasOpenAIKey) {
200 statusHtml += '<li class="text-green-700">✅ OpenAI API key is configured</li>';
201 } else {
202 statusHtml += '<li class="text-red-700">❌ OpenAI API key is missing</li>';
203 }
204
263 const startTime = Date.now();
264
265 // Make API request
266 const response = await fetch('/api/convert', {
267 method: 'POST',
268 headers: {
99
100/**
101 * Converts text to speech using Google's TTS API
102 * @param script - The podcast script
103 * @param voices - Array of voice names to use for different speakers
145 console.log(`Generating audio for ${segments.length} segments...`);
146
147 // Process segments in smaller batches to avoid overwhelming the API
148 const batchSize = 5;
149 const audioSegments: Uint8Array[] = [];
158 const voice = segment.speaker.includes("A") ? voices[0] : voices[1];
159
160 // Limit text length to avoid API limits
161 const text = segment.text.substring(0, 5000);
162