1import { load } from "https://esm.sh/cheerio";
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
3
4const defaultAsEmptyString = (value) => value ?? "";
22
23 useEffect(() => {
24 fetchLeaderboard();
25 }, []);
26
38 }, [isHolding]);
39
40 const fetchLeaderboard = async () => {
41 const response = await fetch('/leaderboard');
42 const data = await response.json();
43 setLeaderboard(data);
49 setGameState('end');
50 await submitScore();
51 await fetchLeaderboard();
52 };
53
54 const submitScore = async () => {
55 await fetch('/submit-score', {
56 method: 'POST',
57 headers: { 'Content-Type': 'application/json' },
918 code: newCode,
919 });
920 fetch('/save', { method: "POST", body }).then(() => {
921 document.getElementById('code-input-hidden').value = newCode;
922 document.getElementById('preview-iframe').src += '';
1284 app.post("/", mainHandler);
1285
1286 return passwordAuth(app.fetch, { verifyPassword: verifyToken });
1287}
1// import { fetch } from "https://esm.town/v/std/fetch";
2import { convertHtmlToMarkdown } from 'npm:@yawnxyz/dom-to-semantic-markdown';
3import { JSDOM } from 'npm:jsdom';
10export async function getHtmlFromUrl(url) {
11 try {
12 const response = await fetch(url);
13 const html = await response.text();
14
17 return $.html();
18 } catch (error) {
19 console.error("Error fetching the URL:", error);
20 return null;
21 }
22}
23
24// todo, pass in html optional, and skip fetch?
25export async function getMetadataFromUrl(url) {
26 const response = await fetch(url, {
27 method: "GET",
28 headers: new Headers({
31 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
32 "Accept-Language": "en-US,en;q=0.5",
33 "Sec-Fetch-Site": "cross-site",
34 "Sec-Fetch-Mode": "navigate",
35 "Sec-Fetch-User": "?1",
36 "Sec-Fetch-Dest": "document",
37 "Referer": "https://www.google.com/",
38 "sec-ch-ua": `"Not A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"`,
32 console.log(
33 length
34 ? `Successfully fetched ${length} row${length === 1 ? "" : "s"}`
35 : "No rows found",
36 );
19
20 try {
21 const response = await fetch(`/generate?prompt=${encodeURIComponent(prompt)}`);
22 if (!response.ok) {
23 throw new Error(`Failed to generate image: ${response.statusText}`);
80 }
81
82 const response = await fetch("https://fal.run/fal-ai/flux/schnell", {
83 method: "POST",
84 headers: {
74 }
75
76 console.log(`Fetching contributions for ${username}`);
77 try {
78 let vals;
88 }
89
90 console.log(`Fetched ${vals.length} contributions`);
91 const contributionData = processVals(vals, useVersions);
92 console.log(`Processed ${contributionData.length} contributions`);
269}
270
271export default (typeof Deno !== "undefined" && Deno.env.get("valtown")) ? app.fetch : app;
272
55 if (urlQuery) {
56 setQuery(urlQuery);
57 fetchResults(urlQuery);
58 }
59 }, []);
60
61 const fetchResults = async (searchQuery) => {
62 setLoading(true);
63 setError(null);
64 try {
65 const response = await fetch(`/api/search?query=${encodeURIComponent(searchQuery)}`);
66 if (!response.ok) {
67 throw new Error(`HTTP error! status: ${response.status}`);
70 setResults(data.results);
71 } catch (e) {
72 console.error("Error fetching results:", e);
73 setError("An error occurred while fetching results. Please try again.");
74 } finally {
75 setLoading(false);
81 if (query) {
82 window.history.pushState({}, "", `?query=${encodeURIComponent(query)}`);
83 fetchResults(query);
84 }
85 };
221if (typeof document !== "undefined") { client(); }
222
223async function fetchDBpediaResults(query: string) {
224 const lookupResponse = await fetch(
225 `https://lookup.dbpedia.org/api/search?query=${encodeURIComponent(query)}&format=json&maxResults=10`
226 );
251
252 try {
253 const results = await fetchDBpediaResults(query);
254
255 if (path === "/api/raw") {
25
26 if (user && user.id) {
27 // Automatically fetches more pages as needed.
28 for await (const basicVal of client.users.vals.list(user.id, {
29 limit: 100,
48 const valId = typeof valOrId === 'string' ? valOrId : valOrId.id; // Determine if input is a val or valId
49
50 // Automatically fetches more pages as needed.
51 for await (const versionListResponse of client.vals.versions.list(valId, {
52 limit: 20, // Default limit
67 const valsArray = []; // Initialize an array to store values with versions
68 if (user && user.id) {
69 // Automatically fetches more pages as needed.
70 const semaphore = new Sema(concurrency); // Assuming 5 concurrent operations are allowed
71 const processVal = async (basicVal) => {
24 if (urlQuery) {
25 setQuery(urlQuery);
26 fetchResults(urlQuery);
27 }
28 }, []);
29
30 const fetchResults = async (searchQuery) => {
31 const response = await fetch(`/api/search?query=${encodeURIComponent(searchQuery)}`);
32 const data = await response.json();
33 setResults(data);
38 if (query) {
39 window.history.pushState({}, "", `?query=${encodeURIComponent(query)}`);
40 fetchResults(query);
41 }
42 };
125if (typeof document !== "undefined") { client(); }
126
127async function fetchDBpediaResults(query: string) {
128 const lookupResponse = await fetch(
129 `https://lookup.dbpedia.org/api/search?query=${encodeURIComponent(query)}&format=json&maxResults=5`,
130 );
143 `;
144
145 const sparqlResponse = await fetch(
146 `https://dbpedia.org/sparql?query=${encodeURIComponent(sparqlQuery)}&format=json`,
147 );
171 }
172
173 const results = await fetchDBpediaResults(query);
174
175 return new Response(JSON.stringify(results), {