Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

@tus/s3-store: add maxMultipartParts option #712

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/tricky-emus-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/s3-store": minor
---

Add `maxMultipartParts` option. This can be used when using S3-compatible storage provider with different part number limitations.
11 changes: 9 additions & 2 deletions packages/s3-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export type Options = {
* Can not be lower than 5MiB or more than 5GiB.
*/
minPartSize?: number
/**
* The maximum number of parts allowed in a multipart upload. Defaults to 10,000.
*/
maxMultipartParts?: number
useTags?: boolean
maxConcurrentPartUploads?: number
cache?: KvStore<MetadataValue>
Expand Down Expand Up @@ -97,13 +101,13 @@ export class S3Store extends DataStore {
protected expirationPeriodInMilliseconds = 0
protected useTags = true
protected partUploadSemaphore: Semaphore
public maxMultipartParts = 10_000 as const
public maxMultipartParts = 10_000
public minPartSize = 5_242_880 // 5MiB
public maxUploadSize = 5_497_558_138_880 as const // 5TiB

constructor(options: Options) {
super()
const {partSize, minPartSize, s3ClientConfig} = options
const { maxMultipartParts, partSize, minPartSize, s3ClientConfig } = options
const {bucket, ...restS3ClientConfig} = s3ClientConfig
this.extensions = [
'creation',
Expand All @@ -117,6 +121,9 @@ export class S3Store extends DataStore {
if (minPartSize) {
this.minPartSize = minPartSize
}
if (maxMultipartParts) {
this.maxMultipartParts = maxMultipartParts
}
this.expirationPeriodInMilliseconds = options.expirationPeriodInMilliseconds ?? 0
this.useTags = options.useTags ?? true
this.cache = options.cache ?? new MemoryKvStore<MetadataValue>()
Expand Down
16 changes: 16 additions & 0 deletions packages/s3-store/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ describe('S3DataStore', () => {
}
})

it.only('should use default maxMultipartParts when not specified', function () {
const store = new S3Store({
s3ClientConfig,
})
assert.equal(store.maxMultipartParts, 10000)
})

it.only('should use custom maxMultipartParts when specified', function () {
const customMaxParts = 5000
const store = new S3Store({
s3ClientConfig,
maxMultipartParts: customMaxParts,
})
assert.equal(store.maxMultipartParts, customMaxParts)
})

shared.shouldHaveStoreMethods()
shared.shouldCreateUploads()
shared.shouldRemoveUploads() // Termination extension
Expand Down
Loading