Skip to content

✨ Add upload option to strip file extensions#434

Merged
wwilsman merged 1 commit intomasterfrom
ww/upload-strip-extensions
Jul 20, 2021
Merged

✨ Add upload option to strip file extensions#434
wwilsman merged 1 commit intomasterfrom
ww/upload-strip-extensions

Conversation

@wwilsman
Copy link
Copy Markdown
Contributor

What is this?

This implements and resolves #412 with a new --strip-extensions flag and accompanying config file option.

The upload config options spreading was growing, so was adjusted to reference the config object rather than spread each individual config option.

The extensions are removed from file paths by parsing the path and rejoining without the extension. While doing this, I realized that the name parameter does not include parent directories and updated the resource helper accordingly.

The allowed file type regular expression was also updated since it now tests the file extension only and not the entire path.

@wwilsman wwilsman added the ✨ enhancement New feature or request label Jul 20, 2021
@wwilsman wwilsman requested a review from Robdel12 July 20, 2021 20:03
Copy link
Copy Markdown
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

🏁

@wwilsman wwilsman merged commit 43a608c into master Jul 20, 2021
@wwilsman wwilsman deleted the ww/upload-strip-extensions branch July 20, 2021 21:54
import pkg from '../../package.json';

const ALLOWED_FILE_TYPES = /\.(png|jpg|jpeg)$/i;
const ALLOWED_FILE_TYPES = /^\.(png|jpg|jpeg)$/i;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@wwilsman Should this also include uppercase for windows users where windows defaults the file type extension to upper case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@andressalinero no need, as the i at the end of the regular expression means it's case insensitive.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's very elegant!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an option to remove the file extension from image uploads

3 participants