8 let text;
9 try {
10 text = await fetchTranspiledJavaScript(esmURL);
11 } catch (err) {
12 throw new Error("Failed to fetch file " + esmURL);
13 }
14 return text;
35}
36
37export async function fetchTranspiledJavaScript(url: string) {
38 if (!url.startsWith("https://esm.town")) throw Error("Can only fetch from https://esm.town");
39 const res = await fetch(url, {
40 headers: {
41 // Always transpile TS to JS
46 });
47 if (!res.ok) {
48 throw new Error("Failed to fetch " + url);
49 }
50 return await res.text();
32 // use a trick to turn a data uri into a blob
33 if (!text.startsWith("data:")) return Response.json({}, { status: 500 });
34 responseBlob = await (await fetch(text)).blob();
35 }
36
62
63 // Use a trick to turn a data uri into a blob
64 let imageBlob = await (await fetch(image)).blob();
65 await blob.set("pondiverse_image" + id.lastInsertRowid, imageBlob);
66
3import { blob } from "https://esm.town/v/std/blob";
4import { email } from "https://esm.town/v/std/email";
5import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
6import { load } from "npm:cheerio";
7import { XMLParser } from "npm:fast-xml-parser";
46 }
47
48 // Fetch content from the regulatory source
49 async fetchContent() {
50 try {
51 const pageHtml = await fetchText(this.url);
52 return await this.extractContent(pageHtml);
53 } catch (error) {
54 console.error(`Error fetching content from ${this.name}: ${error.message}`);
55 return null;
56 }
76 console.log(`Checking ${this.name} for updates...`);
77
78 const currentContent = await this.fetchContent();
79 if (!currentContent) return null;
80
2
3import addCreation from "./addCreation";
4import fetchCreations from "./fetchCreations";
5import getCreation from "./getCreation";
6
12
13 if (req.method == "GET" && url.pathname == "/")
14 return fetchCreations(req);
15
16 if (req.method == "GET" && url.pathname == "/images" && url.searchParams.has("c"))
22 return getCreation(req);
23 if (req.method == "GET" && url.pathname == "/creations")
24 return fetchCreations(req);
25
26 if (req.method == "POST" && url.pathname == "/updateDatabase")
1import { blob } from "https://esm.town/v/std/blob";
2import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
3
4import { TABLE_NAME } from "./database";
5
105});
106
107export default app.fetch;
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
53 throw new Error("Invalid transaction mode provided to sqlite.batch. Must be 'write', 'read', or 'deferred.");
54 }
55 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
56 method: "POST",
57 headers: {
9 const variable: string = await blob.getJSON(blobKey) ?? "";
10
11 const response = await fetch(scrapeURL);
12 const body = await response.text();
13 const $ = cheerio.load(body);
9 const handleSubmit = async (e) => {
10 e.preventDefault();
11 const response = await fetch("/classify", {
12 method: "POST",
13 headers: { "Content-Type": "application/json" },