feat:adjust input media#469
Open
faishalmhmd wants to merge 3 commits into
Open
Conversation
Contributor
|
@faishalmhmd is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary: Media Upload Restrict & Server-Side Image Compression
Summary
Implements custom media upload restrictions (allowed file formats) across the UI, and adds high-performance server-side image compression using
sharpto dramatically reduce the file sizes of uploaded assets without visual quality loss.Users can:
['.jpg', '.jpeg']) in theirnuxt.config.tsor environment variables.public/directory) and external cloud storage (NuxtHub / S3 Blob).Approach
1. Allowed Media Format Restrictions (UI & Validation)
mediaoptions block ofnuxt.config.tsand mapping them through the runtime config.isAllowedType): Created a modular utility helper insrc/app/src/utils/file.tsto dynamically validate file extensions and MIME types against the configuredallowedTypes.ItemActionsToolbar.vue(toolbar file uploads).MediaCardForm.vue(media selection inputs).media.vue(drag-and-drop zone with event listeners to block default browser tab opening for disallowed dropped files).2. High-Performance Image Compression (
sharp)sharplibrary as a dependency to execute optimized server-side image operations.fit: 'inside',withoutEnlargement: true) to shrink raw camera photos down to web-friendly sizes while preserving smaller images.mozjpeg: trueat82quality (superior compression algorithms).compressionLevel: 9andeffort: 10.82quality andeffort: 6.routes/dev/public/[...path].ts(handles default local development uploads to/public).routes/medias/[...path].ts(handles cloud buckets/NuxtHub Blob storage).What's in scope
Custom Allowed Formats
allowedTypesarray understudio.mediaoptionsisAllowedTypefor extension & MIME validationServer-Side Image Compression
mozjpeg)[sharp-dev] Compressed images/photo.jpg: 3200KB → 720KB (saved 77.5%))Notable implementation details
routes/dev/public/[...path].ts) for local development filesystem writes and another for external buckets (routes/medias/[...path].ts), the compression engine is implemented in both handlers to guarantee identical compression performance regardless of the storage destination.mozjpeginside the sharp configuration ensures that JPEGs are compressed using advanced trellis quantization, reducing files up to 30% further than default JPEG encoders with zero visible artifacts.application/octet-streamPUT bodies are intercepted and converted to Node Buffers for processing throughsharpbefore being written back to storage.Test plan
Allowed Types Validation
media.allowedTypes = ['.jpg', '.jpeg']innuxt.config.ts..pngor.pdffile via the toolbar or file input — verified that a custom validation error blocks the upload..pdffile onto the media upload page drop-zone — verified that the drop is blocked, and the browser does not open the PDF in a new tab.Server-Side Image Compression
[sharp-dev] Compressed images/photo.jpg: 5120.0KB → 890.0KB (saved 82.6%)public/images/photo.jpg— verified that the resolution is maxed at 2560px and the file size is successfully reduced.