Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslemammad committed Sep 11, 2024
1 parent 00b5e09 commit a78cb0d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 49 deletions.
4 changes: 1 addition & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
"nitropack": "^2.9.6",
"octokit": "^3.2.1",
"query-registry": "^3.0.1",
"wrangler": "^3.57.1"
},
"dependencies": {
"wrangler": "^3.57.1",
"@paralleldrive/cuid2": "^2.2.2"
}
}
21 changes: 21 additions & 0 deletions packages/backend/server/routes/multipart/complete.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { R2UploadedPart } from "@cloudflare/workers-types";

export default eventHandler(async (event) => {
const {
key: key,
id: id,
"uploaded-parts": uploadedPartsHeader,
} = getHeaders(event);

const binding = useBinding(event);

const upload = binding.resumeMultipartUpload(key!, id!);
const uploadedParts: R2UploadedPart[] = JSON.parse(uploadedPartsHeader!);

const object = await upload.complete(uploadedParts);

return {
ok: true,
key: object.key,
};
});
38 changes: 0 additions & 38 deletions packages/backend/server/routes/multipart/upload.post.ts

This file was deleted.

19 changes: 19 additions & 0 deletions packages/backend/server/routes/multipart/upload.put.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default eventHandler(async (event) => {
const {
key: key,
id: id,
"part-number": partNumberHeader,
} = getHeaders(event);

const partNumber = Number(partNumberHeader);
const binding = useBinding(event);

const upload = binding.resumeMultipartUpload(key!, id!);
const buffer = (await readRawBody(event, false))!;
const part = await upload.uploadPart(partNumber, buffer);

return {
ok: true,
part,
};
});
8 changes: 4 additions & 4 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const apiUrl = process.env.API_URL ?? API_URL;
const publishUrl = new URL("/publish", apiUrl);
const createMultipart = new URL("/multipart/create", apiUrl);
const uploadMultipart = new URL("/multipart/upload", apiUrl);
const completeMultipart = new URL("/multipart/complete", apiUrl);

const main = defineCommand({
meta: {
Expand Down Expand Up @@ -402,7 +403,7 @@ const main = defineCommand({
const chunk = file.slice(start, end);

const uploadMultipartRes = await fetch(uploadMultipart, {
method: "POST",
method: "PUT",
headers: {
key: uploadKey,
id: uploadId,
Expand All @@ -420,8 +421,7 @@ const main = defineCommand({
const { part } = await uploadMultipartRes.json();
uploadedParts.push(part);
}
console.log('uploaded-parts', uploadedParts)
const completeMultipartRes = await fetch(uploadMultipart, {
const completeMultipartRes = await fetch(completeMultipart, {
method: "POST",
headers: {
key: uploadKey,
Expand All @@ -437,7 +437,7 @@ const main = defineCommand({
}
const { key: completionKey } =
await completeMultipartRes.json();
console.log(name, `object:${completionKey}`)

formData.set(name, `object:${completionKey}`);
}
}
Expand Down
7 changes: 3 additions & 4 deletions pnpm-lock.yaml

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

0 comments on commit a78cb0d

Please sign in to comment.