feat(base): default ImageUpload compression on
Flip ImageUploadOptions.compress so undefined/true → compress with default knobs, false → skip, object → compress with merged knobs. A future <ImageUpload> consumer that forgets the prop now gets safe behavior (small WebP) instead of dumping a 5–8 MB phone photo to pict-rs. Drop the now-redundant :compress="true" from the events banner and market product call sites. Profile keeps its object override since it tunes maxWidthOrHeight: 512 / maxSizeMB: 0.2 for avatars. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
67dbfb16e1
commit
e5f0202a4a
4 changed files with 10 additions and 7 deletions
|
|
@ -396,7 +396,6 @@ const handleOpenChange = (open: boolean) => {
|
||||||
:show-primary-button="false"
|
:show-primary-button="false"
|
||||||
:disabled="isLoading"
|
:disabled="isLoading"
|
||||||
:allow-camera="true"
|
:allow-camera="true"
|
||||||
:compress="true"
|
|
||||||
placeholder="Add a poster or banner"
|
placeholder="Add a poster or banner"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -176,9 +176,10 @@ const props = defineProps<{
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
allowCamera?: boolean
|
allowCamera?: boolean
|
||||||
/**
|
/**
|
||||||
* Client-side resize + re-encode before upload. Pass `true` for the
|
* Client-side resize + re-encode before upload. Default-on with the
|
||||||
* service defaults (1920px max edge, WebP, ~1MB target), or an object
|
* service defaults (1920px max edge, WebP, ~1MB target). Pass an
|
||||||
* to tune individual knobs.
|
* object to tune individual knobs, or `false` to upload the original
|
||||||
|
* untouched.
|
||||||
*/
|
*/
|
||||||
compress?: boolean | CompressOptions
|
compress?: boolean | CompressOptions
|
||||||
}>()
|
}>()
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,9 @@ export interface ImageUploadOptions {
|
||||||
maxSizeMB?: number
|
maxSizeMB?: number
|
||||||
acceptedTypes?: string[]
|
acceptedTypes?: string[]
|
||||||
generateThumbnail?: boolean
|
generateThumbnail?: boolean
|
||||||
/** Enable client-side resize + re-encode before upload. */
|
/** Client-side resize + re-encode before upload. Default `true` with
|
||||||
|
* default knobs (1920 px, WebP, ~1 MB). Pass an object to tune knobs
|
||||||
|
* or `false` to upload the original untouched. */
|
||||||
compress?: boolean | CompressOptions
|
compress?: boolean | CompressOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,7 +335,9 @@ export class ImageUploadService extends BaseService {
|
||||||
* JPEG if the browser can't encode WebP.
|
* JPEG if the browser can't encode WebP.
|
||||||
*/
|
*/
|
||||||
private async maybeCompress(file: File, options: ImageUploadOptions): Promise<File> {
|
private async maybeCompress(file: File, options: ImageUploadOptions): Promise<File> {
|
||||||
if (!options.compress) return file
|
// Default-on: undefined / true → compress with default knobs;
|
||||||
|
// object → compress with merged knobs; false → skip entirely.
|
||||||
|
if (options.compress === false) return file
|
||||||
|
|
||||||
const opts: Required<CompressOptions> = {
|
const opts: Required<CompressOptions> = {
|
||||||
...DEFAULT_COMPRESS,
|
...DEFAULT_COMPRESS,
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@
|
||||||
:show-primary-button="true"
|
:show-primary-button="true"
|
||||||
:disabled="isCreating"
|
:disabled="isCreating"
|
||||||
:allow-camera="true"
|
:allow-camera="true"
|
||||||
:compress="true"
|
|
||||||
placeholder="Add product photos"
|
placeholder="Add product photos"
|
||||||
/>
|
/>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue