SilverBullet pivot to become an offline-first PWA (#403)
This commit is contained in:
+34
-9
@@ -1,12 +1,37 @@
|
||||
import type { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { proxySyscalls } from "../../plugos/syscalls/transport.ts";
|
||||
import type { Space } from "../../common/spaces/space.ts";
|
||||
import type { HttpSpacePrimitives } from "../../common/spaces/http_space_primitives.ts";
|
||||
import {
|
||||
performLocalFetch,
|
||||
ProxyFetchRequest,
|
||||
ProxyFetchResponse,
|
||||
} from "../../common/proxy_fetch.ts";
|
||||
|
||||
export function sandboxFetchSyscalls(space: Space): SysCallMapping {
|
||||
return proxySyscalls(
|
||||
[
|
||||
"sandboxFetch.fetch",
|
||||
],
|
||||
(ctx, name, ...args) => space.proxySyscall(ctx.plug, name, args),
|
||||
);
|
||||
export function sandboxFetchSyscalls(
|
||||
httpSpacePrimitives?: HttpSpacePrimitives,
|
||||
): SysCallMapping {
|
||||
return {
|
||||
"sandboxFetch.fetch": async (
|
||||
_ctx,
|
||||
url: string,
|
||||
options: ProxyFetchRequest,
|
||||
): Promise<ProxyFetchResponse> => {
|
||||
// console.log("Got sandbox fetch ", url);
|
||||
if (!httpSpacePrimitives) {
|
||||
// No SB server to proxy the fetch available so let's execute the request directly
|
||||
return performLocalFetch(url, options);
|
||||
}
|
||||
const resp = httpSpacePrimitives.authenticatedFetch(
|
||||
httpSpacePrimitives.url,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
operation: "fetch",
|
||||
url,
|
||||
options,
|
||||
}),
|
||||
},
|
||||
);
|
||||
return (await resp).json();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user