mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 23:30:00 -04:00
fix data url workers
This commit is contained in:
parent
6ea474c3d0
commit
ec0fb8b70a
5 changed files with 75 additions and 43 deletions
|
@ -1,4 +1,5 @@
|
|||
import { encodeUrl, BareMuxConnection } from "../../shared";
|
||||
import type { MessageC2W } from "../../worker";
|
||||
import { ScramjetClient } from "../client";
|
||||
|
||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||
|
@ -6,26 +7,27 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
construct({ args, call }) {
|
||||
if (args[0] instanceof URL) args[0] = args[0].href;
|
||||
if (args[0].startsWith("blob:") || args[0].startsWith("data:")) {
|
||||
if (args[0].startsWith("blob:")) {
|
||||
args[0] =
|
||||
"data:application/javascript;base64," +
|
||||
btoa(syncfetch(client, args[0]));
|
||||
}
|
||||
let data = syncfetch(client, args[0]);
|
||||
let id = Math.random().toString(8).slice(5);
|
||||
|
||||
args[0] = "/scramjet/worker?data=" + args[0];
|
||||
args[0] = "/scramjet/worker?id=" + id;
|
||||
if (args[1] && args[1].type === "module") {
|
||||
args[0] += "&type=module";
|
||||
}
|
||||
|
||||
args[0] += "&origin=" + encodeURIComponent(client.url.origin);
|
||||
|
||||
return;
|
||||
}
|
||||
client.serviceWorker.controller?.postMessage({
|
||||
scramjet$type: "dataworker",
|
||||
data,
|
||||
id,
|
||||
} as MessageC2W);
|
||||
} else {
|
||||
args[0] = encodeUrl(args[0]) + "?dest=worker";
|
||||
|
||||
args[0] = encodeUrl(args[0]) + "?dest=worker";
|
||||
|
||||
if (args[1] && args[1].type === "module") {
|
||||
args[0] += "&type=module";
|
||||
if (args[1] && args[1].type === "module") {
|
||||
args[0] += "&type=module";
|
||||
}
|
||||
}
|
||||
|
||||
const worker = call();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue