support fingerprintExtra to include metadata in fingerprint #5842
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Problem
The Uppy Tus plugin generates fingerprints for files based on their
idandendpoint, which means identical files (same content and name) uploaded to different contexts, such as separate projects, are treated as the same file. This prevents scoping uploads to specific projects, as the plugin cannot differentiate between identical files uploaded to distinct projects. For example, uploadingfile.jpgto "project-123" and "project-456" results in the same fingerprint, causing conflicts in resumable uploads or incorrect file associations.Solution
To address this, I introduced a new
fingerprintExtraoption to the Tus plugin. This option allows users to include additional metadata, such as a project ID, in the fingerprint calculation. By appending this extra data to the fingerprint, identical files uploaded to different projects generate unique fingerprints, ensuring proper scoping and preventing conflicts. For example, addingfingerprintExtra: 'project-123'ensures the fingerprint is unique to that project, even for identical files.Changes
packages/@uppy/tus/src/index.ts:fingerprintExtraas an optional configuration option in theTusOptstype.uploadOptions.fingerprintassignment to use thegetFingerprintfunction withopts.fingerprintExtra.packages/@uppy/tus/src/getFingerprint.ts:getFingerprintfunction to accept anextraKeysparameter and append the specified metadata values to the fingerprint, joined by colons.extraKeysoptional and handling missing metadata gracefully.packages/@uppy/tus/index.test.ts:describeblock forgetFingerprintwith tests covering:fingerprintExtrais not provided.Example