Skip to content

Commit

Permalink
Fix unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
longern committed Jul 10, 2024
1 parent de3979b commit 9a2a848
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
16 changes: 10 additions & 6 deletions functions/webdav/copy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pLimit from "p-limit";

import { notFound } from "@/utils/bucket";
import { listAll, RequestHandlerParams, WEBDAV_ENDPOINT } from "./utils";

Expand All @@ -14,10 +16,11 @@ export async function handleRequestCopy({
const src = await bucket.get(path);
if (src === null) return notFound();

const destPathname = new URL(destinationHeader).pathname.replace(/\/$/, "");
if (!destPathname.startsWith(WEBDAV_ENDPOINT))
const destPathname = new URL(destinationHeader).pathname;
const decodedPathname = decodeURIComponent(destPathname).replace(/\/$/, "");
if (!decodedPathname.startsWith(WEBDAV_ENDPOINT))
return new Response("Bad Request", { status: 400 });
const destination = destPathname.slice(WEBDAV_ENDPOINT.length);
const destination = decodedPathname.slice(WEBDAV_ENDPOINT.length);

if (
destination === path ||
Expand Down Expand Up @@ -53,11 +56,12 @@ export async function handleRequestCopy({
customMetadata: object.customMetadata,
});
};
const promise_array = [];
const limit = pLimit(5);
const promises = [];
for await (const object of listAll(bucket, prefix, true)) {
promise_array.push(copy(object));
promises.push(limit(() => copy(object)));
}
await Promise.all(promise_array);
await Promise.all(promises);
break;
}
default:
Expand Down
50 changes: 45 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/node": "^20.14.9",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"p-limit": "^6.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
Expand Down

0 comments on commit 9a2a848

Please sign in to comment.