87
88 try {
89 const response = await fetch("/summarize", {
90 method: "POST",
91 body: JSON.stringify({ url }),
224 const { url } = await request.json();
225
226 // Fetch webpage content
227 const webpageResponse = await fetch(url);
228 const webpageText = await webpageResponse.text();
229
145
146 try {
147 const response = await fetch("/ask", {
148 method: "POST",
149 headers: {
8 }
9
10 const response = await fetch(`https://ntfy.sh/${ntfyChannel}`, {
11 method: "POST",
12 body: `What did you throw out today?`,
35}, { concurrency: 3 })).filter(Boolean);
36
37// fetch text from endpoint
38const vals3 = await pMap(vals2, async (v) => {
39 if (!v.links.endpoint) return v;
40 const text = await (await fetch(v.links.endpoint)).text();
41 return { ...v, endpointText: text };
42}, { concurrency: 3 });
69}
70
71// fetch ai summary of val
72const vals4 = await pMap(vals3, async (v) => {
73 const descriptions = await getDescriptions(v);
76
77async function getScreenshot(url: string) {
78 const resp = await fetch(
79 "https://api.apiflash.com/v1/urltoimage?" + new URLSearchParams({
80 access_key: Deno.env.get("API_FLASH"),
88export type WideApi = typeof routes;
89
90export default app.fetch.bind(app);
1/** @jsxImportSource https://esm.sh/preact **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import { api } from "https://esm.town/v/pomdtr/api";
5import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
145
146 try {
147 const response = await fetch("/ask", {
148 method: "POST",
149 headers: {
12
13 useEffect(() => {
14 fetchData();
15 }, []);
16
17 const fetchData = async () => {
18 try {
19 const response = await fetch("/data");
20 if (!response.ok) {
21 throw new Error("Failed to fetch data");
22 }
23 const { categories, allPredictions } = await response.json();
27 setIsLoading(false);
28 } catch (err) {
29 console.error("Error fetching data:", err);
30 setError(err.message);
31 setIsLoading(false);
183 // Data endpoint
184 if (request.method === "GET" && new URL(request.url).pathname === "/data") {
185 const gistResponse = await fetch(
186 "https://gist.githubusercontent.com/bmitchinson/5c3ed5df80977e402113fc33c149ae7e/raw/ea393f1407d31da96623387299fc6e3702f5fb0a/gameawards_24_backend.json",
187 );
213 const username = segments.pop();
214
215 // Fetch categories
216 const gistResponse = await fetch(
217 "https://gist.githubusercontent.com/bmitchinson/5c3ed5df80977e402113fc33c149ae7e/raw/ea393f1407d31da96623387299fc6e3702f5fb0a/gameawards_24_backend.json",
218 );
219 const categories = await gistResponse.json();
220
221 // Fetch this user's predictions
222 const userResult = await sqlite.execute(
223 `SELECT predictions FROM ${KEY}_predictions_${SCHEMA_VERSION} WHERE username = ?`,
36
37 useEffect(() => {
38 async function fetchStats() {
39 const response = await fetch("/dashboard-stats");
40 const data = await response.json();
41 setStats(data);
42 }
43 fetchStats();
44 }, []);
45
146
147 try {
148 const response = await fetch("/", {
149 method: "POST",
150 body: JSON.stringify({
14
15 useEffect(() => {
16 fetchStocks();
17 }, []);
18
19 async function fetchStocks() {
20 const response = await fetch('/stocks');
21 const data = await response.json();
22 setStocks(data);
33 async function addStock(e) {
34 e.preventDefault();
35 const response = await fetch('/stocks', {
36 method: 'POST',
37 headers: {
42
43 if (response.ok) {
44 fetchStocks();
45 setNewStock({
46 symbol: '',