URL encode better

e.g. fixes the reading of a file with a hash in the name
This commit is contained in:
Manav Rathi 2024-05-01 17:39:28 +05:30
parent 0a93ba67a1
commit b967d4bbea
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View file

@ -50,6 +50,9 @@ export const registerStreamProtocol = () => {
const path = decodeURIComponent(pathname);
// `hash` begins with a "#", slice that off.
const hashPath = decodeURIComponent(hash.slice(1));
log.debug(
() => `[stream] ${host} ${path}${hashPath ? "::" + hashPath : ""}`,
);
switch (host) {
case "read":
return handleRead(path);

View file

@ -39,10 +39,12 @@ export const readStream = async (
): Promise<{ response: Response; size: number; lastModifiedMs: number }> => {
let url: URL;
if (typeof pathOrZipItem == "string") {
url = new URL(`stream://read${pathOrZipItem}`);
url = new URL("stream://read");
url.pathname = pathOrZipItem
} else {
const [zipPath, entryName] = pathOrZipItem;
url = new URL(`stream://read-zip${zipPath}`);
url = new URL("stream://read-zip");
url.pathname = zipPath;
url.hash = entryName;
}