Townieusage-dashboard.ts3 matches
59// If we get here, authentication was successful
6061// Fetch all rows from the usage table
62// Fetch all rows from the usage table
63const allUsageData = await sqlite.execute(`SELECT * FROM ${USAGE_TABLE} ORDER BY timestamp DESC`);
6465// Fetch aggregated data grouped by user_id
66const groupedUsageData = await sqlite.execute(`
67SELECT
4849// Register the commands
50const response = await fetch(`https://discord.com/api/v10/${endpoint}`, {
51method: "PUT",
52headers: {
HHGtoMyDayNotebookView.tsx12 matches
67const [currentPage, setCurrentPage] = useState(1);
6869const fetchMemories = useCallback(async () => {
70setLoading(true);
71setError(null);
72try {
73const response = await fetch(API_BASE);
74if (!response.ok) {
75throw new Error(`HTTP error! status: ${response.status}`);
78setMemories(data);
79} catch (e) {
80console.error("Failed to fetch memories:", e);
81setError(e.message || "Failed to fetch memories.");
82} finally {
83setLoading(false);
8687useEffect(() => {
88fetchMemories();
89}, [fetchMemories]);
9091const handleAddMemory = async (e: React.FormEvent) => {
100101try {
102const response = await fetch(API_BASE, {
103method: "POST",
104headers: { "Content-Type": "application/json" },
112setNewMemoryTags("");
113setShowAddForm(false);
114await fetchMemories();
115} catch (e) {
116console.error("Failed to add memory:", e);
123124try {
125const response = await fetch(`${API_BASE}/${id}`, {
126method: "DELETE",
127});
129throw new Error(`HTTP error! status: ${response.status}`);
130}
131await fetchMemories();
132} catch (e) {
133console.error("Failed to delete memory:", e);
155156try {
157const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158method: "PUT",
159headers: { "Content-Type": "application/json" },
164}
165setEditingMemory(null);
166await fetchMemories();
167} catch (e) {
168console.error("Failed to update memory:", e);
HHGtoMyDayindex.ts2 matches
135));
136137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;
HHGtoMyDay.cursorrules5 matches
163```
1641655. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
166```ts
167const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
168```
169242243// Inject data to avoid extra round-trips
244const initialData = await fetchInitialData();
245const dataScript = `<script>
246window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
3003015. **API Design:**
302- `fetch` handler is the entry point for HTTP vals
303- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
304- Properly handle CORS if needed for external access
HHGtoMyDayApp.tsx17 matches
82const [cookieAndTeaMode, setCookieAndTeaMode] = useState(false);
8384// Fetch images from backend instead of blob storage directly
85useEffect(() => {
86// Set default background color in case image doesn't load
89}
9091// Fetch avatar image
92fetch("/api/images/stevens.jpg")
93.then((response) => {
94if (response.ok) return response.blob();
103});
104105// Fetch wood background
106fetch("/api/images/wood.jpg")
107.then((response) => {
108if (response.ok) return response.blob();
129}, []);
130131const fetchMemories = useCallback(async () => {
132setLoading(true);
133setError(null);
134try {
135const response = await fetch(API_BASE);
136if (!response.ok) {
137throw new Error(`HTTP error! status: ${response.status}`);
154}
155} catch (e) {
156console.error("Failed to fetch memories:", e);
157setError(e.message || "Failed to fetch memories.");
158} finally {
159setLoading(false);
162163useEffect(() => {
164fetchMemories();
165}, [fetchMemories]);
166167const handleAddMemory = async (e: React.FormEvent) => {
176177try {
178const response = await fetch(API_BASE, {
179method: "POST",
180headers: { "Content-Type": "application/json" },
188setNewMemoryTags("");
189setShowAddForm(false);
190await fetchMemories();
191} catch (e) {
192console.error("Failed to add memory:", e);
199200try {
201const response = await fetch(`${API_BASE}/${id}`, {
202method: "DELETE",
203});
205throw new Error(`HTTP error! status: ${response.status}`);
206}
207await fetchMemories();
208} catch (e) {
209console.error("Failed to delete memory:", e);
231232try {
233const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
234method: "PUT",
235headers: { "Content-Type": "application/json" },
240}
241setEditingMemory(null);
242await fetchMemories();
243} catch (e) {
244console.error("Failed to update memory:", e);
TodoistTesttoday_and_overdue.tsx8 matches
910useEffect(() => {
11fetchTasks();
12}, []);
1314const fetchTasks = async () => {
15setLoading(true);
16setError(null);
17try {
18const res = await fetch("/todoist-tasks");
19if (!res.ok) {
20throw new Error("Failed to fetch tasks");
21}
22const data = await res.json();
54<div>
55<button
56onClick={fetchTasks}
57style={{
58backgroundColor: "#4CAF50",
141142try {
143// Fetch active tasks from Todoist
144const todoistResponse = await fetch(`${TODOIST_API_BASE}/tasks`, {
145headers: {
146"Authorization": `Bearer ${apiToken}`,
150151if (!todoistResponse.ok) {
152throw new Error("Failed to fetch Todoist tasks");
153}
154
untitled-2512new-file-9861.tsx8 matches
510511Â Â Â Â Â Â Â Â Â try {
512Â Â Â Â Â Â Â Â Â Â Â const response = await fetch(sourceApiUrl, {
513Â Â Â Â Â Â Â Â Â Â Â Â Â method: 'POST',
514Â Â Â Â Â Â Â Â Â Â Â Â Â body: formData // FormData handles multipart/form-data encoding
528// Optionally, clear the form and refresh parts of the page
529// uploadForm.reset();
530// Consider fetching and re-rendering tagsData if new tags were added.
531// For simplicity, a page reload might be easiest here, or more complex AJAX update.
532// Example: setTimeout(() => window.location.reload(), 3000); // Reload after 3s
626// --- Dynamic Imports (Inside Handler for Val Town) ---
627const { OpenAI } = await import("https://esm.town/v/std/openai");
628const val_fetch = (await import("https://esm.town/v/std/fetch")).fetch;
629const { PDFExtract } = await import("npm:pdf.js-extract");
630type PDFExtractOptions = import("npm:pdf.js-extract").PDFExtractOptions;
735try {
736if (!input.documentUrl.match(/^https?:\/\//i)) throw new Error("Invalid URL scheme. Must be http or https.");
737const res = await val_fetch(input.documentUrl, {
738headers: {
739"Accept": "text/plain, text/html, application/pdf",
742redirect: "follow",
743});
744if (!res.ok) throw new Error(`HTTP error ${res.status} while fetching URL.`);
745const ct = res.headers.get("content-type") || "";
746if (ct.includes("application/pdf")) {
760) {
761docText = await res.text();
762if (!docText?.trim()) throw new Error("Fetched empty text from URL.");
763if (ct.includes("text/html")) {
764log.push({ agent: ingestAgent, type: "step", message: `HTML content detected. Attempting basic strip.` });
773}
774} catch (e) {
775log.push({ agent: ingestAgent, type: "error", message: `URL fetch/process failed: ${e.message}` });
776}
777}
987tagsData = (result.rows as StoredTag[]) || [];
988} catch (e) {
989console.error("Error fetching tags for UI:", e);
990dbError = e.message;
991tagsData = []; // Ensure tagsData is an empty array on error
v2-vals-create-a-val-examplemain.tsx3 matches
1import { API_URL } from "https://esm.town/v/std/API_URL";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import ValTown from "npm:@valtown/sdk";
430// Example of using the API to create a new val with a single file
31// First create the val
32const valResponse = await fetch(
33`${API_URL}/v2/vals`,
34{
52// Then create the file
53const val = await valResponse.json();
54const fileResponse = await fetch(
55`${API_URL}/v2/vals/${val.id}/files?path=main.tsx`,
56{
4import { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } from "npm:node-html-markdown";
56const html = await fetch("https://github.com/trending").then(r => r.text());
78const { window: { document } } = new JSDOM(html);