File size: 2,439 Bytes
bee6636 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import { rewriteUrl } from "../../shared/rewriters/url";
import { ScramjetClient } from "../client";
export default function (client: ScramjetClient, _self: Self) {
client.Proxy("CacheStorage.prototype.open", {
apply(ctx) {
ctx.args[0] = `${client.url.origin}@${ctx.args[0]}`;
},
});
client.Proxy("CacheStorage.prototype.has", {
apply(ctx) {
ctx.args[0] = `${client.url.origin}@${ctx.args[0]}`;
},
});
client.Proxy("CacheStorage.prototype.match", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
client.Proxy("CacheStorage.prototype.delete", {
apply(ctx) {
ctx.args[0] = `${client.url.origin}@${ctx.args[0]}`;
},
});
client.Proxy("Cache.prototype.add", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
client.Proxy("Cache.prototype.addAll", {
apply(ctx) {
for (let i = 0; i < ctx.args[0].length; i++) {
if (
typeof ctx.args[0][i] === "string" ||
ctx.args[0][i] instanceof URL
) {
ctx.args[0][i] = rewriteUrl(ctx.args[0][i], client.meta);
}
}
},
});
client.Proxy("Cache.prototype.put", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
client.Proxy("Cache.prototype.match", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
client.Proxy("Cache.prototype.matchAll", {
apply(ctx) {
if (
(ctx.args[0] && typeof ctx.args[0] === "string") ||
(ctx.args[0] && ctx.args[0] instanceof URL)
) {
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
client.Proxy("Cache.prototype.keys", {
apply(ctx) {
if (
(ctx.args[0] && typeof ctx.args[0] === "string") ||
(ctx.args[0] && ctx.args[0] instanceof URL)
) {
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
client.Proxy("Cache.prototype.delete", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
}
|