89useEffect(() => {
10fetchItems();
11}, []);
1213const fetchItems = async () => {
14const response = await fetch("/items");
15const data = await response.json();
16setItems(data);
19const handleAddItem = async () => {
20if (newItem.trim() === "") return;
21await fetch("/items", {
22method: "POST",
23headers: { "Content-Type": "application/json" },
25});
26setNewItem("");
27fetchItems();
28};
293536const removeItem = async (id) => {
37await fetch(`/items/${id}`, { method: "DELETE" });
38fetchItems();
39};
4041const clearList = async () => {
42await fetch("/items", { method: "DELETE" });
43fetchItems();
44};
45
createFlashcardsValmain.tsx5 matches
1617useEffect(() => {
18fetchCSV();
19}, []);
2025}, [flashcards]);
2627const fetchCSV = async () => {
28const response = await fetch("/csv");
29const csvText = await response.text();
30const result = Papa.parse(csvText, { header: false });
57const formData = new FormData();
58formData.append("csv", file);
59const response = await fetch("/upload", {
60method: "POST",
61body: formData,
63if (response.ok) {
64alert("File uploaded successfully!");
65fetchCSV();
66} else {
67alert("Error uploading file.");
generateDailyTwitterEmailmain.tsx3 matches
1import { email } from "https://esm.town/v/std/email";
23async function fetchTweets(listId: string): Promise<any[]> {
4const url = `https://news.ycombinator.com/`;
5const response = await fetch(url);
6const html = await response.text();
7console.log(html);
27export default async function(interval: Interval) {
28const listId = "1359390628841480192";
29const tweets = await fetchTweets(listId);
3031// Sort tweets by likes and get top 10
anthropicCachingmain.tsx6 matches
30setLoading(prev => ({ ...prev, [operation]: true }));
31try {
32const response = await fetch(`/run?operation=${operation}`, {
33method: "POST",
34headers: {
138}
139140async function fetchContent(): Promise<string> {
141const response = await fetch("https://www.gutenberg.org/cache/epub/1342/pg1342.txt");
142const text = await response.text();
143151const MODEL_NAME = "claude-3-5-sonnet-20240620";
152153const bookContent = await fetchContent();
154const startTime = Date.now();
155187const MODEL_NAME = "claude-3-5-sonnet-20240620";
188189const bookContent = await fetchContent();
190const startTime = Date.now();
191226const MODEL_NAME = "claude-3-5-sonnet-20240620";
227228const bookContent = await fetchContent();
229const questions = [
230"What is the title of this novel?",
45try {
6const response = await fetch(url);
78if (!response.ok) {
13const firstImageUrl = "https://cn.bing.com" + data.images[0].url;
14// 第三æ¥ï¼šè¯·æ±‚该图片的实际内容
15const imageResponse = await fetch(firstImageUrl);
1617if (!imageResponse.ok) {
18throw new Error(`Failed to fetch image! status: ${imageResponse.status}`);
19}
2026});
27} catch (error) {
28console.error("Error fetching data:", error);
29return new Response(JSON.stringify({ error: "Failed to fetch data" }), {
30status: 500,
31headers: {
94tokenUrl.searchParams.set("state", store.state);
9596const tokenResp = await fetch(tokenUrl.toString());
97if (!tokenResp.ok) {
98throw new Error(await tokenResp.text());
103};
104105const resp = await fetch("https://lastlogin.io/userinfo", {
106headers: {
107Authorization: `Bearer ${access_token}`,
314if (iconChoice === 'default') {
315const domain = new URL(url).hostname;
316const response = await fetch(`/favicon?domain=${encodeURIComponent(domain)}`);
317const blob = await response.blob();
318iconBase64 = await convertToBase64(blob);
426}
427
428const response = await fetch(`https://www.google.com/s2/favicons?domain=${domain}&sz=256`);
429const favicon = await response.arrayBuffer();
430
434});
435436export default app.fetch;
markdown_downloadmain.tsx13 matches
145transcript += arr.map(({ text }) => text).join("\n\n");
146} catch (e) {
147transcript = `Failed to fetch transcript ${e}\n`;
148}
149let header = "";
153+ y.description + "\n</div>\n\n";
154} catch (e) {
155header = `Failed to fetch youtube metadata: ${e}\n`;
156}
157return header + "\n" + transcript;
203204let html = action.htmlContent;
205let fetch_response;
206if (!html) {
207fetch_response = await fetch(url.toString(), {
208method: req.method,
209headers: new Headers({
212"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
213"Accept-Language": "en-US,en;q=0.5",
214"Sec-Fetch-Site": "cross-site",
215"Sec-Fetch-Mode": "navigate",
216"Sec-Fetch-User": "?1",
217"Sec-Fetch-Dest": "document",
218"Referer": "https://www.google.com/",
219"sec-ch-ua": `"Not A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"`,
225});
226227console.log(fetch_response);
228229html = await fetch_response.text();
230}
231let title = "";
243let markdown_extended = markdown + "\n\n" + url;
244245if (fetch_response && Math.floor(fetch_response.status / 200) * 200 != 200 || markdown === "") {
246const jina_url = `https://r.jina.ai/${url.toString()}`;
247console.log(`jina fallback:${jina_url}`);
248const fallback_fetch_response = await fetch(jina_url);
249markdown_extended = await fallback_fetch_response.text();
250}
251if (req.headers.get("Accept")?.includes("text/html")) {
selfDestructmain.tsx2 matches
1import ValTown from "https://esm.sh/@valtown/sdk@0.22.0";
2import { fetchValInfo } from "https://esm.town/v/pomdtr/fetchValInfo?v=2";
34export async function selfDestruct(importMetaUrl: string) {
5const { id } = await fetchValInfo(importMetaUrl);
6const { vals } = new ValTown();
7
18const getSpaces = async () => {
19const options = requestOptions({ method: "GET" });
20const response = await fetch(`${apiHost}/user/spaces`, options);
21const data = await response.json();
22const spaceNames = data.map(space => space.name);