1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { generateImage } from "https://esm.town/v/isidentical/falImageGen?v=11";
import { blob } from "https://esm.town/v/std/blob?v=12";
const genKey = (key: string): string => {
return "genImageCache-v1-" + key;
};
export default async function(req: Request): Promise<Response> {
let key = new URL(req.url).pathname;
let url = await blob.getJSON(genKey(key));
if (!url) {
let resp = await generateImage(`generate the image you would expect if the url path was: "${key}"`);
url = resp.url;
await blob.setJSON(genKey(key), url);
}
return new Response((await fetch(url)).body, { headers: { "content-type": "image/jpg" } });
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
maxm-imggenurl.web.val.run
v15
May 23, 2024