URL encode
This commit is contained in:
parent
c988884ab1
commit
de4aa3a6ca
2 changed files with 9 additions and 12 deletions
|
@ -45,19 +45,15 @@ export const registerStreamProtocol = () => {
|
|||
// stream://write/path/to/file#/path/to/another/file
|
||||
// host[pathname----] [pathname-2---------]
|
||||
//
|
||||
const { host, pathname, hash } = new URL(url);
|
||||
// Convert e.g. "%20" to spaces.
|
||||
const path = decodeURIComponent(pathname);
|
||||
// `hash` begins with a "#", slice that off.
|
||||
const hashPath = decodeURIComponent(hash.slice(1));
|
||||
log.debug(
|
||||
() => `[stream] ${host} ${path}${hashPath ? "::" + hashPath : ""}`,
|
||||
);
|
||||
const { host, searchParams } = new URL(url);
|
||||
const path = ensure(searchParams.get("path"));
|
||||
const path2 = searchParams.get("path2") ?? undefined;
|
||||
log.debug(() => `[stream] ${host} ${path}${path2 ? "::" + path2 : ""}`);
|
||||
switch (host) {
|
||||
case "read":
|
||||
return handleRead(path);
|
||||
case "read-zip":
|
||||
return handleReadZip(path, hashPath);
|
||||
return handleReadZip(path, ensure(path2));
|
||||
case "write":
|
||||
return handleWrite(path, request);
|
||||
default:
|
||||
|
|
|
@ -39,11 +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${encodeURIComponent(pathOrZipItem)}`);
|
||||
const params = new URLSearchParams({ path: pathOrZipItem });
|
||||
url = new URL(`stream://read?${params.toString()}`);
|
||||
} else {
|
||||
const [zipPath, entryName] = pathOrZipItem;
|
||||
url = new URL(`stream://read-zip${encodeURIComponent(zipPath)}`);
|
||||
url.hash = entryName;
|
||||
const params = new URLSearchParams({ path: zipPath, path2: entryName });
|
||||
url = new URL(`stream://read-zip?${params.toString()}`);
|
||||
}
|
||||
|
||||
const req = new Request(url, { method: "GET" });
|
||||
|
|
Loading…
Add table
Reference in a new issue