Public
Back

Version 4

6/23/2024
import { encodeBase64 } from "jsr:@std/encoding@0.224.3/base64";
import { contentType } from "jsr:@std/media-types@0.224.1";
import { extname } from "jsr:@std/path@0.225.2";

export default async function(req: Request) {
const url = new URL(req.url);
const target = "https://" + url.pathname.replace(/^\/_json/, "");

const srcURL = new URL(target);
const resp = await fetch(srcURL);
if (!resp.ok) {
return new Response("not found", { status: 404 });
}

return Response.json({
b64: encodeBase64(await resp.arrayBuffer()),
contentType: contentType(extname(srcURL.pathname)) || "text/plain",
});
}
pomdtr-ejm.web.val.run
Updated: June 23, 2024