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

feat: Allow File adapter to create file with specific locations or dynamic filenames #9557

Open
wants to merge 9 commits into
base: alpha
Choose a base branch
from

Conversation

AdrianCurtin
Copy link

@AdrianCurtin AdrianCurtin commented Jan 16, 2025

Allow file adapter to override file name and location + give createFile access to config to allow getFileLocation calls internally

File adapter may specify a different filename or location during creation which should be returned after content storage.

Example, adapter timestamps upload filenames. getFileLocation may result in a slightly different url than the one used to create the file.

In the case where the url returned is identical this is not a problem. Additionally file adapter could call getFile location internally if it wanted to (and should probably have access to config for that reason).

In principle, if user wanted to name every file uploaded in an ordinal fashion (eg 1.jpg,2.jpg,3.jpg), they should allowed to do this.

As a separate improvement, this allows the url to be assigned during createFile as well (to prevent extra calls if the url is already known). Passing config to createFile allows getFileLocation to be called internally). Otherwise if url is not assigned, then getFileLocation can be called to retrieve it with the updated filename.

If url is not provided and filename is unchanged by createFile, then this code will not alter current functionality

Pull Request

Issue

Closes: #9556

Approach

  1. Allow file location and filename as generated to be overwritten by adapter.createFile if the file adapter desires
  2. Pass config as additional argument to fileadapter so that the adapter can call getFileLocation during createFile if desired (optional)

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check

…le access to config to allow getFileLocation calls internally

File adapter may specify a different filename or location during creation which should be returned after content storage.

Example, adapter timestamps upload filenames. getFileLocation may result in a slightly different url than the one used to create the file.

In the case where the url returned is identical this is not a problem. Additionally file adapter could call getFile location internally if it wanted to (and should probably have access to config for that reason)
Copy link

parse-github-assistant bot commented Jan 16, 2025

Thanks for opening this pull request!

@AdrianCurtin AdrianCurtin changed the title Allow File adapter to create file with specific locations Feature: Allow File adapter to create file with specific locations or dynamic filenames Jan 16, 2025
@AdrianCurtin AdrianCurtin changed the title Feature: Allow File adapter to create file with specific locations or dynamic filenames feat: Allow File adapter to create file with specific locations or dynamic filenames Jan 16, 2025
but use updated filename in getFileLocation
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

Could you add a test for this?

*
* @return {Promise} a promise that should fail if the storage didn't succeed
* @return {Promise<any>|Promise<{url?: string, name?: string, location?: string}>} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename and/or location (if relevant)
Copy link
Member

Choose a reason for hiding this comment

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

From the description I believe the notation would be {Promise<{url?: string, name?: string, location?: string}|undefined>}, i.e. a promise that resolves with ... or rejects with undefined?

Copy link
Author

@AdrianCurtin AdrianCurtin Jan 17, 2025

Choose a reason for hiding this comment

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

I switched it to
{Promise<{url?: string, name?: string, location?: string}>|Promise<undefined>}

@AdrianCurtin
Copy link
Author

@mtrezza
Tests added

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