mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
fix: update caches api
This commit is contained in:
parent
ba0aa479f0
commit
d2f1e10a6c
1 changed files with 33 additions and 8 deletions
|
@ -17,7 +17,9 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
|
|
||||||
client.Proxy("CacheStorage.prototype.match", {
|
client.Proxy("CacheStorage.prototype.match", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = `${client.url.origin}@${ctx.args[0]}`;
|
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,45 +31,68 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
|
|
||||||
client.Proxy("Cache.prototype.add", {
|
client.Proxy("Cache.prototype.add", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("Cache.prototype.addAll", {
|
client.Proxy("Cache.prototype.addAll", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
for (let i = 0; i < ctx.args[0].length; i++) {
|
for (let i = 0; i < ctx.args[0].length; i++) {
|
||||||
ctx.args[0][i] = rewriteUrl(ctx.args[0][i], client.meta);
|
if (
|
||||||
|
typeof ctx.args[0][i] === "string" ||
|
||||||
|
ctx.args[0][i] instanceof URL
|
||||||
|
) {
|
||||||
|
ctx.args[0][i] = rewriteUrl(ctx.args[0][i].toString(), client.meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("Cache.prototype.put", {
|
client.Proxy("Cache.prototype.put", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("Cache.prototype.match", {
|
client.Proxy("Cache.prototype.match", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("Cache.prototype.matchAll", {
|
client.Proxy("Cache.prototype.matchAll", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
if (ctx.args[0]) ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
if (
|
||||||
|
(ctx.args[0] && typeof ctx.args[0] === "string") ||
|
||||||
|
(ctx.args[0] && ctx.args[0] instanceof URL)
|
||||||
|
) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("Cache.prototype.keys", {
|
client.Proxy("Cache.prototype.keys", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
if (ctx.args[0]) ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
if (
|
||||||
|
(ctx.args[0] && typeof ctx.args[0] === "string") ||
|
||||||
|
(ctx.args[0] && ctx.args[0] instanceof URL)
|
||||||
|
) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
client.Proxy("Cache.prototype.delete", {
|
client.Proxy("Cache.prototype.delete", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
|
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||||
|
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue