blob_adminapp.tsx22 matches
231const [isDragging, setIsDragging] = useState(false);
232233const fetchBlobs = useCallback(async () => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
239} catch (error) {
240console.error("Error fetching blobs:", error);
241} finally {
242setLoading(false);
245246useEffect(() => {
247fetchBlobs();
248}, [fetchBlobs]);
249250const handleSearch = (e) => {
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
266setEditContent(content);
267} catch (error) {
268console.error("Error fetching blob content:", error);
269} finally {
270setBlobContentLoading(false);
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
312}
313}
314fetchBlobs();
315};
316326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
blob_adminmain.tsx1 match
199});
200201export default lastlogin((request: Request) => app.fetch(request));
9import { OpenAI } from "https://esm.town/v/std/openai";
10// Import Request and Response types if needed (usually available globally in Val Town)
11// Example: import { Request, Response } from "https://esm.town/v/std/fetch";
1213// --- Define Expected Data Structures ---
5657// --- OpenAI Generation Function ---
58// Asynchronously fetches race data from OpenAI's Chat Completion API.
59async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
60// Initialize the OpenAI client (using API key from Val Town secrets)
152} catch (error) {
153// Log the specific error encountered during the OpenAI call or processing
154console.error("Error fetching or processing data from OpenAI:", error);
155// Check if the error is specifically an AuthenticationError
156if (error.constructor.name === "AuthenticationError") {
176// This function handles incoming HTTP requests and returns the HTML for the game.
177export default async function server(request: Request): Promise<Response> {
178// 1. Fetch Race Data: Attempt to get dynamic data from OpenAI, use fallback on error.
179const activeRaceData = await generateRaceDataWithOpenAI();
180
cerebras_coderindex.ts1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
5960// --- OpenAI Generation Function ---
61// Asynchronously fetches race data from OpenAI's Chat Completion API.
62async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
63// Initialize the OpenAI client (using API key from Val Town secrets)
137return generatedData;
138} catch (error) {
139console.error("Error fetching or processing data from OpenAI:", error);
140console.warn("Using fallback race data due to the error.");
141return fallbackRaceData; // Return default data on any failure
146// This function handles incoming HTTP requests and returns an HTML response.
147export default async function server(request: Request): Promise<Response> {
148// 1. Fetch Race Data: Attempt to get dynamic data from OpenAI, use fallback on error.
149const activeRaceData = await generateRaceDataWithOpenAI();
150
beeminderGoalsDueTodaymain.tsx4 matches
89try {
10// Fetch goals with a more detailed request
11const goalsResponse = await fetch(
12`https://www.beeminder.com/api/v1/users/me/goals.json?auth_token=${beeminderAuthToken}&datapoints=recent`,
13);
1415if (!goalsResponse.ok) {
16return new Response("Failed to fetch Beeminder goals", { status: goalsResponse.status });
17}
1844});
45} catch (error) {
46return new Response(`Error fetching Beeminder goals: ${error.message}`, { status: 500 });
47}
48}
reactHonoStarterindex.ts2 matches
21});
2223// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
42and it just got those right first thing.
4344fwiw, I'm not 100% certain it actually referenced the beeminder API docs by fetching them from the url I provided, or if it just got it somehow from having seen enough examples.
4546## Future ideas
786787// Post to the same endpoint, but add format=json and use POST with body
788const response = await fetch(window.location.pathname + "?format=json", {
789method: "POST",
790headers: {
faithfulTanEelmain.tsx1 match
109return generatedData;
110} catch (error) {
111console.error("Error fetching or processing data from OpenAI:", error);
112console.warn("Using fallback race data due to error.");
113return fallbackRaceData;