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

Allow gif and svg to be uploaded #18

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

evoactivity
Copy link

Allows gif and svg to be uploaded without being converted by sharp for breakpoints and thumbnails.

I'm running this on several projects with no problems.

Copy link
Owner

@ndianabasi ndianabasi left a comment

Choose a reason for hiding this comment

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

Hello @evoactivity. Thank you for the PR. Please take a look at the comments below.

Copy link
Owner

@ndianabasi ndianabasi Mar 1, 2024

Choose a reason for hiding this comment

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

Since we are now maintaining two set of formats: generally-allowed formats and processable formats, you need to improve the tests to show that the non-processable formats are merely uploaded without formatting.

]

// Formats we want to be safely processed by sharp
export const conversionFormats: Array<AllowedFormats> = ['jpeg', 'png', 'webp', 'avif', 'tiff']
Copy link
Owner

Choose a reason for hiding this comment

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

Rename variable to processableFormats. Also append as const to the array.

You should also exclude the non-processable formats from the assigned type: Array<AllowedFormat>. E.g. Array<Exclude<AllowedFormat, 'gif' | 'svg' | 'svg+xml'>>

@@ -67,17 +67,26 @@ export const resizeTo = async function (
export const breakpointSmallerThan = (breakpoint: number, { width, height }: FileDimensions) =>
breakpoint < width! || breakpoint < height!

export const allowedFormats: Array<AttachmentOptions['forceFormat']> = [
export type AllowedFormats = 'jpeg' | 'png' | 'webp' | 'avif' | 'tiff' | 'gif' | 'svg' | 'svg+xml'
Copy link
Owner

Choose a reason for hiding this comment

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

Rename union type to single: AllowedFormat

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.

2 participants