Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
UploadPartCopySourceData,
UploadPartCopyOptions,
UploadPartCopyResult,
UploadPartOptions,
UploadPartResult,
PartInfo,
SourceData,
IncomingHttpHeaders,
Expand Down Expand Up @@ -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<UploadPartResult> {
console.log(name, uploadId, partNo, file, start, end, options);
return {} as any;
}
Comment on lines +159 to +162

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To maintain consistency with the suggested change in the IObjectSimple interface, the file parameter in this mock implementation of uploadPart should also be updated from any to string | Blob. This ensures the type tests accurately reflect and validate the updated interface.

  async uploadPart(name: string, uploadId: string, partNo: number, file: string | Blob, start: number, end: number, options?: UploadPartOptions): Promise<UploadPartResult> {
    console.log(name, uploadId, partNo, file, start, end, options);
    return {} as any;
  }


async asyncSignatureUrl(name: string, options?: SignatureUrlOptions): Promise<string> {
console.log(name, options);
return '';
Expand Down Expand Up @@ -476,3 +483,62 @@ const uploadPartCopyResult4 = await simpleClient.uploadPartCopy(
partCopySourceData
);
expectType<string>(uploadPartCopyResult4.etag);

// Test uploadPart basic usage
const uploadPartResult1 = await simpleClient.uploadPart(
'large-file.bin',
'uploadId123',
1,
'/path/to/file.bin',
0,
1048576
);
expectType<string>(uploadPartResult1.name);
expectType<string>(uploadPartResult1.etag);
expectType<number>(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<string>(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<string>(uploadPartResult3.name);
expectType<string>(uploadPartResult3.etag);
expectType<number>(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<string>(uploadPartResult4.etag);
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -557,6 +571,11 @@ export interface IObjectSimple {
*/
uploadPartCopy(name: string, uploadId: string, partNo: number, range: string, sourceData: UploadPartCopySourceData, options?: UploadPartCopyOptions): Promise<UploadPartCopyResult>;

/**
* Upload a part in a multipart upload transaction.
*/
uploadPart(name: string, uploadId: string, partNo: number, file: string | Buffer | Readable, start: number, end: number, options?: UploadPartOptions): Promise<UploadPartResult>;

/**
* Signature a url for the object.
* @param name
Expand Down
Loading