WIP: CLI running of plugs

This commit is contained in:
Zef Hemel
2023-08-04 18:56:55 +02:00
parent de3e385017
commit 3464af0252
35 changed files with 738 additions and 136 deletions
+25
View File
@@ -0,0 +1,25 @@
import type { SysCallMapping } from "../../plugos/system.ts";
import {
ProxyFetchRequest,
ProxyFetchResponse,
} from "../../common/proxy_fetch.ts";
import { base64Encode } from "../asset_bundle/base64.ts";
export function sandboxFetchSyscalls(): SysCallMapping {
return {
"sandboxFetch.fetch": async (
_ctx,
url: string,
options: ProxyFetchRequest,
): Promise<ProxyFetchResponse> => {
// console.log("Got sandbox fetch ", url);
const resp = await fetch(url, options);
return {
status: resp.status,
ok: resp.ok,
headers: Object.fromEntries(resp.headers.entries()),
base64Body: base64Encode(new Uint8Array(await resp.arrayBuffer())),
};
},
};
}