Skip to content

Commit

Permalink
refactor: abortMultipartUpload in TypeScript (#1188)
Browse files Browse the repository at this point in the history
* abortMultipartUpload

* avoid promise return

---------

Co-authored-by: Prakash Senthil Vel <[email protected]>
  • Loading branch information
trim21 and prakashsvmx authored Jul 25, 2023
1 parent 3140ab7 commit 72147de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
15 changes: 15 additions & 0 deletions src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,21 @@ export class TypedClient {
await this.makeRequestAsyncOmit({ method, bucketName, objectName, headers, query }, '', [200, 204])
}

/**
* Internal Method to abort a multipart upload request in case of any errors.
*
* @param bucketName - Bucket Name
* @param objectName - Object Name
* @param uploadId - id of a multipart upload to cancel during compose object sequence.
*/
async abortMultipartUpload(bucketName: string, objectName: string, uploadId: string): Promise<void> {
const method = 'DELETE'
const query = `uploadId=${uploadId}`

const requestOptions = { method, bucketName, objectName: objectName, query }
await this.makeRequestAsyncOmit(requestOptions, '', [204])
}

/**
* Get part-info of all parts of an incomplete upload specified by uploadId.
*/
Expand Down
21 changes: 5 additions & 16 deletions src/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2436,21 +2436,6 @@ export class Client extends TypedClient {
this.makeRequest({ method, bucketName, objectName, query, headers }, payload, [200], '', false, cb)
}

/**
* Internal Method to abort a multipart upload request in case of any errors.
* @param bucketName __string__ Bucket Name
* @param objectName __string__ Object Name
* @param uploadId __string__ id of a multipart upload to cancel during compose object sequence.
* @param cb __function__ callback function
*/
abortMultipartUpload(bucketName, objectName, uploadId, cb) {
const method = 'DELETE'
let query = `uploadId=${uploadId}`

const requestOptions = { method, bucketName, objectName: objectName, query }
this.makeRequest(requestOptions, '', [204], '', false, cb)
}

/**
* Internal method to upload a part during compose object.
* @param partConfig __object__ contains the following.
Expand Down Expand Up @@ -2640,7 +2625,11 @@ export class Client extends TypedClient {

async.map(uploadList, me.uploadPartCopy.bind(me), (err, res) => {
if (err) {
return this.abortMultipartUpload(destObjConfig.Bucket, destObjConfig.Object, uploadId, cb)
this.abortMultipartUpload(destObjConfig.Bucket, destObjConfig.Object, uploadId).then(
() => cb(),
(err) => cb(err),
)
return
}
const partsDone = res.map((partCopy) => ({ etag: partCopy.etag, part: partCopy.part }))
return me.completeMultipartUpload(destObjConfig.Bucket, destObjConfig.Object, uploadId, partsDone, cb)
Expand Down

0 comments on commit 72147de

Please sign in to comment.