15 const start = performance.now();
16 try {
17 res = await fetch(url);
18 end = performance.now();
19 status = res.status;
25 } catch (e) {
26 end = performance.now();
27 reason = `couldn't fetch: ${e}`;
28 ok = false;
29 }
30
31 useEffect(() => {
32 fetchProblem();
33 }, []);
34
35 const fetchProblem = async () => {
36 setLoading(true);
37 try {
38 const response = await fetch("/problem");
39 if (!response.ok) throw new Error("Failed to fetch problem");
40 const data = await response.json();
41 setProblem(data);
45 setShowCorrectAnswer(false);
46 } catch (error) {
47 console.error("Error fetching problem:", error);
48 setFeedback("Failed to load problem. Please try again.");
49 } finally {
56 setLoading(true);
57 try {
58 const response = await fetch("/check", {
59 method: "POST",
60 headers: { "Content-Type": "application/json" },
139 )}
140 {showCorrectAnswer && (
141 <button onClick={fetchProblem} className="next-button">
142 Try a new problem
143 </button>
2 meta: {
3 content_type: ContentType;
4 refetch_settings: boolean;
5 linkify: boolean;
6 suggested_replies: boolean;
143 suggested_replies: boolean;
144 content_type: ContentType;
145 refetch_settings: boolean;
146}
147
304 });
305
306 for await (const event of fetchEventSource(req)) {
307 yield event as PoeBotServerSentEvent;
308 }
309}
310
311async function* fetchEventSource(request: Request): AsyncIterable<{ event: string; data: any }> {
312 const response = await fetch(request);
313
314 if (!response.ok) {
82 ));
83
84export default app.fetch;
150
151async function getUserId() {
152 const resp = await fetch("https://api.val.town/v1/me", {
153 headers: {
154 Authorization: `Bearer ${Deno.env.get("valtown")}`,
201 const tasks = await getPendingTasks();
202 for (const task of tasks) {
203 fetch(`${this.#httpEndpoint}/${task.data.name}`, {
204 method: "POST",
205 body: JSON.stringify({ args: task.data.args }),
216 }
217
218 async fetch(req: Request): Promise<Response> {
219 await this.#ensureMigration();
220
14});
15
16export default queue.fetch.bind(queue);
15 app.get("/projects", (c) => c.html(getProjects()));
16 app.get("/projects/:name", (c) => c.html(getProject(c.req)));
17 return app.fetch(req);
18}
19
74 const handleLogin = async (e: React.FormEvent) => {
75 e.preventDefault();
76 const response = await fetch(`/auth?username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`);
77 const data = await response.json();
78 if (data.token) {
2 let json = await req.json();
3 const id = json.research.split("/").pop();
4 const res = await fetch(`https://api.jakeai.org/researches/${id}`);
5 json = await res.json();
6 return Response.json(json.insights.map(i => ({ type: i.type, group: i.group, quote: i.quote, ups: i.post.ups })));
10 image,
11 );
12 const data = await (await fetch(await getUploadURL(), {
13 "body": fd,
14 "method": "POST",
24}
25async function getUploadURL(): Promise<string> {
26 const data = await (await fetch("https://www.val.town/api/trpc/generateImageUploadUrl", {
27 "headers": {
28 "content-type": "application/json",