-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
204 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
playground/server/api/blob/multipart/[...pathname].post.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { z } from 'zod' | ||
|
||
export default eventHandler(async (event) => { | ||
const { pathname } = await getValidatedRouterParams(event, z.object({ | ||
pathname: z.string().min(1) | ||
}).parse) | ||
|
||
const options = await readValidatedBody(event, z.record(z.string(), z.any()).optional().parse) | ||
|
||
const { createMultipartUpload } = hubBlob() | ||
try { | ||
const object = await createMultipartUpload(pathname, options) | ||
return { | ||
uploadId: object.uploadId, | ||
pathname: object.pathname, | ||
} | ||
} catch (e: any) { | ||
throw createError({ | ||
statusCode: 400, | ||
message: e.message | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { z } from 'zod' | ||
|
||
export default eventHandler(async (event) => { | ||
const { pathname, uploadId } = await getValidatedQuery(event, z.object({ | ||
pathname: z.string().min(1), | ||
uploadId: z.string().min(1), | ||
}).parse) | ||
|
||
const { parts } = await readValidatedBody(event,z.object({ | ||
parts: z.array(z.object({ | ||
partNumber: z.number(), | ||
etag: z.string(), | ||
})) | ||
}).parse) | ||
|
||
const { resumeMultipartUpload } = hubBlob() | ||
const mpu = resumeMultipartUpload(pathname, uploadId) | ||
try { | ||
const object = await mpu.complete(parts) | ||
return object | ||
} catch (e: any) { | ||
throw createError({ | ||
statusCode: 400, | ||
message: e.message | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export async function streamToArrayBuffer(stream: ReadableStream, streamSize: number) { | ||
const result = new Uint8Array(streamSize) | ||
let bytesRead = 0 | ||
const reader = stream.getReader() | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const { done, value } = await reader.read() | ||
if (done) { | ||
break | ||
} | ||
result.set(value, bytesRead) | ||
bytesRead += value.length | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.