Avatar

@nilslice

2 likes5 public vals
Joined April 10, 2023
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import createPlugin from "https://esm.sh/@extism/extism";
export default async function(req: Request): Promise<Response> {
const plugin = await createPlugin(
"https://cdn.modsurfer.dylibso.com/api/v1/module/ec17c9afde08aa9e7fa857fe2c9cbb9206e3a3dbec98429ceebd3421de7070da.wasm",
{ useWasi: false },
);
const data = {
event_file_name: "input.md",
event_file_data: btoa(await req.text()),
};
let out = await plugin.call("on_file_write", JSON.stringify(data));
return Response.json(out.json());
}
Fork
1
2
3
4
5
6
7
8
import { text2png } from "https://esm.town/v/nilslice/libtext2png";
export default async function(req: Request): Promise<Response> {
const img = await text2png("Just give me the PNG", "magenta", 50); // returns a `Blob`
return new Response(img, {
headers: { "Content-type": "image/png" },
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import createPlugin from "https://esm.sh/@extism/extism";
export const text2png = async (text: string, color: string, fontSize: number): Promise<Blob> => {
const plugin = await createPlugin(
"https://cdn.modsurfer.dylibso.com/api/v1/module/2c9eb901052b1e6397d2414bdb796975407cc87085e6b5fe9564932538d8af51.wasm",
{ useWasi: false },
);
const input = JSON.stringify({
value: text,
color: color,
font_size: fontSize,
});
const out = await plugin.call("handle", input);
return await b64toBlob(out.json().value, "image/png");
};
const b64toBlob = (base64, type = "application/octet-stream") =>
fetch(`data:${type};base64,${base64}`).then(res => res.blob());
Fork
1
2
3
4
5
6
7
8
9
10
import handler from "https://esm.town/v/nilslice/text2png";
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
url.searchParams.set("text", "hello from the other val");
url.searchParams.set("color", "green");
url.searchParams.set("font_size", "100");
let r = new Request(url);
return handler(r);
}
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import createPlugin from "https://esm.sh/@extism/extism";
export default async function(req: Request): Promise<Response> {
const plugin = await createPlugin(
"https://cdn.modsurfer.dylibso.com/api/v1/module/2c9eb901052b1e6397d2414bdb796975407cc87085e6b5fe9564932538d8af51.wasm",
{ useWasi: false },
);
const q = new URL(req.url).searchParams;
const input = JSON.stringify({
value: q.get("text"),
color: q.get("color"),
font_size: parseInt(q.get("font_size")),
});
const out = await plugin.call("handle", input);
const img = await b64toBlob(out.json().value, "image/png");
return new Response(img, {
headers: { "Content-type": "image/png" },
});
}
const b64toBlob = (base64, type = "application/octet-stream") =>
fetch(`data:${type};base64,${base64}`).then(res => res.blob());
Next