mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 15:40:02 -04:00
feat: start supporting cachestorage api (partially)
This commit is contained in:
parent
c37caff949
commit
96412050a5
1 changed files with 61 additions and 0 deletions
61
src/client/shared/caches.ts
Normal file
61
src/client/shared/caches.ts
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
import { rewriteUrl } from "../../shared";
|
||||||
|
import { ScramjetClient } from "../client";
|
||||||
|
|
||||||
|
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
|
//TODO: this doesnt support request objects, do that later (i dont feel like it)
|
||||||
|
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) {
|
||||||
|
ctx.args[0] = `${client.url.origin}@${ctx.args[0]}`;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Proxy("CacheStorage.prototype.delete", {
|
||||||
|
apply(ctx) {
|
||||||
|
ctx.args[0] = `${client.url.origin}@${ctx.args[0]}`;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Proxy("Cache.prototype.add", {
|
||||||
|
apply(ctx) {
|
||||||
|
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++) {
|
||||||
|
ctx.args[0][i] = rewriteUrl(ctx.args[0][i], client.meta);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Proxy("Cache.prototype.delete", {
|
||||||
|
apply(ctx) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Proxy("Cache.prototype.match", {
|
||||||
|
apply(ctx) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Proxy("Cache.prototype.matchAll", {
|
||||||
|
apply(ctx) {
|
||||||
|
if (ctx.args[0]) ctx.args[0] = `${client.url.origin}@${ctx.args[0]}`;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue