From 631700e75adf40cb971512090abf5f0cf67b02e7 Mon Sep 17 00:00:00 2001 From: killagu Date: Mon, 17 Nov 2025 19:24:49 +0800 Subject: [PATCH 1/2] feat: add uploadPart method type definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add uploadPart method for uploading a part in a multipart upload transaction: - UploadPartOptions interface with headers, mime, and disabledMD5 fields - UploadPartResult interface with name, etag, and res fields - Method signature supporting file path or File object with byte range (start, end) - Comprehensive type tests covering various usage scenarios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- index.test-d.ts | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 19 ++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/index.test-d.ts b/index.test-d.ts index 7a9a5d0..28fcd13 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -40,6 +40,8 @@ import { UploadPartCopySourceData, UploadPartCopyOptions, UploadPartCopyResult, + UploadPartOptions, + UploadPartResult, PartInfo, SourceData, IncomingHttpHeaders, @@ -154,6 +156,11 @@ class SimpleClient implements IObjectSimple { return {} as any; } + async uploadPart(name: string, uploadId: string, partNo: number, file: any, start: number, end: number, options?: UploadPartOptions): Promise { + console.log(name, uploadId, partNo, file, start, end, options); + return {} as any; + } + async asyncSignatureUrl(name: string, options?: SignatureUrlOptions): Promise { console.log(name, options); return ''; @@ -476,3 +483,62 @@ const uploadPartCopyResult4 = await simpleClient.uploadPartCopy( partCopySourceData ); expectType(uploadPartCopyResult4.etag); + +// Test uploadPart basic usage +const uploadPartResult1 = await simpleClient.uploadPart( + 'large-file.bin', + 'uploadId123', + 1, + '/path/to/file.bin', + 0, + 1048576 +); +expectType(uploadPartResult1.name); +expectType(uploadPartResult1.etag); +expectType(uploadPartResult1.res.status); + +// Test uploadPart with options +const uploadPartResult2 = await simpleClient.uploadPart( + 'large-file.bin', + 'uploadId123', + 2, + '/path/to/file.bin', + 1048576, + 2097152, + { + timeout: 60000, + disabledMD5: false + } +); +expectType(uploadPartResult2.etag); + +// Test uploadPart with File object (browser environment) +const fileObject = new File(['content'], 'test.txt'); +const uploadPartResult3 = await simpleClient.uploadPart( + 'upload.txt', + 'uploadId456', + 3, + fileObject, + 0, + 100000, + { + headers: { + 'x-oss-server-side-encryption': 'AES256' + }, + mime: 'text/plain' + } +); +expectType(uploadPartResult3.name); +expectType(uploadPartResult3.etag); +expectType(uploadPartResult3.res.status); + +// Test uploadPart with different byte ranges +const uploadPartResult4 = await simpleClient.uploadPart( + 'video.mp4', + 'uploadId789', + 5, + '/path/to/video.mp4', + 5242880, + 10485760 +); +expectType(uploadPartResult4.etag); diff --git a/src/index.ts b/src/index.ts index efecf25..3411aee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -410,6 +410,20 @@ export interface UploadPartCopyResult { res: NormalSuccessResponse; } +export interface UploadPartOptions extends RequestOptions { + headers?: IncomingHttpHeaders; + mime?: string; + /** disable MD5 check */ + disabledMD5?: boolean; +} + +export interface UploadPartResult { + name: string; + /** part etag */ + etag: string; + res: NormalSuccessResponse; +} + export type HTTPMethods = 'GET' | 'POST' | 'DELETE' | 'PUT'; export interface ResponseHeaderType { @@ -557,6 +571,11 @@ export interface IObjectSimple { */ uploadPartCopy(name: string, uploadId: string, partNo: number, range: string, sourceData: UploadPartCopySourceData, options?: UploadPartCopyOptions): Promise; + /** + * Upload a part in a multipart upload transaction. + */ + uploadPart(name: string, uploadId: string, partNo: number, file: any, start: number, end: number, options?: UploadPartOptions): Promise; + /** * Signature a url for the object. * @param name From 15ff18b64879b4ce2b2a30f81c3fdd44c57153f2 Mon Sep 17 00:00:00 2001 From: killagu Date: Mon, 17 Nov 2025 19:36:57 +0800 Subject: [PATCH 2/2] f --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 3411aee..7b30565 100644 --- a/src/index.ts +++ b/src/index.ts @@ -574,7 +574,7 @@ export interface IObjectSimple { /** * Upload a part in a multipart upload transaction. */ - uploadPart(name: string, uploadId: string, partNo: number, file: any, start: number, end: number, options?: UploadPartOptions): Promise; + uploadPart(name: string, uploadId: string, partNo: number, file: string | Buffer | Readable, start: number, end: number, options?: UploadPartOptions): Promise; /** * Signature a url for the object.