Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Enhance File Path Customization #977

Closed
wants to merge 3 commits into from
Closed

Conversation

MoritzGruber
Copy link

@MoritzGruber MoritzGruber commented Jul 5, 2023

Hello, tusd maintainers and community,

In our organization, we employ a tenant structure akin to GitHub or GitLab, where we have organizations containing multiple projects. Each project can upload assets using tusd.

To efficiently manage permissions and quotas on files, we would like to incorporate the project_id into the file path of each asset. For example, the desired format is assets/<project_id>/<asset_id>/filename.png.

In order to achieve this, we needed to modify the file ID within fileInfo beforehand. Furthermore, we had to override the ExtractIDFromPath to align with our use case.

We have initially implemented this in a fork. However, we believe that integrating this enhancement into the core library would be beneficial for other users who might have similar use cases requiring flexible path customization.

Proposed Changes:

  1. Allow passing a custom function for ExtractIDFromPath in the configuration, which can be used to customize how file IDs are extracted from URLs.

  2. Update references to ExtractIDFromPath to use the custom function if provided, else default to the existing implementation.

These changes are backward compatible and allow for greater flexibility in accommodating various file path structures.

We kindly ask for your review and consideration in integrating these changes into the core library.

Special Thanks:

Big shoutout to the tusd maintainers and contributors! You guys rock for keeping this library on point. It's great that we can just plug in your library and rely on it working rock solid. Keep up the awesome work! 👏

Best regards,
Moritz

Summary of Code Changes:

  1. pkg/handler/config.go: Added ExtractIDFromPath to the Config struct.
  2. pkg/handler/unrouted_handler.go: Various changes to reference ExtractIDFromPath from Config and to pass file information by reference.

@Acconut
Copy link
Member

Acconut commented Jul 6, 2023

Thank you for your efforts on this and the kind words! We have received requests about more detailed customization like this for a long time and finally managed to implement it a few weeks ago: #962 It has not been (properly) released yet because it is still part of the ongoing development on tusd v2. There are pre-releases available and I would recommend you to check them out. Documentation is still lacking, but the examples from the PR might help you enough already.

Given that we already have implemented something similar in v2, I sadly don't think we can accept this PR. However, please provide any feedback for our implementation in v2, so can we improve it!

@MoritzGruber
Copy link
Author

Thanks for sharing. Makes sense!. We will check v2, thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants