feat(uploads): accept 15 MB / 8000px and every standard image format

- API ceiling 8 MB -> 15 MB, sharp limitInputPixels 64 MP (8000x8000)
- accept AVIF, BMP, TIFF, HEIC/HEIF, JXL alongside JPEG/PNG/WebP/GIF/SVG/PDF;
  fall back to the file extension when the browser sends an empty or
  octet-stream type
- convert formats browsers cannot paint (TIFF, HEIC, JXL) to WebP on upload
- pre-warm 200/400/600/1600 variants so card thumbnails never wait on a render
- nginx: client_max_body_size 20m, proxy_read_timeout 180s (the 1m default
  rejected every real photo with a bare 413, and a slow 8000px render became
  a 504 that left the card thumbnail broken while /uploads worked)
- gallery tile falls back to the original file if a variant fails

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mahmood
2026-11-26 13:30:50 +03:30
co-authored by Claude Sonnet 5.5
parent 072344f85e
commit 387222851c
13 changed files with 163 additions and 36 deletions
+10
View File
@@ -5,6 +5,16 @@ server {
root /usr/share/nginx/html;
index index.html;
# Uploads are capped at 15 MB by the API; nginx's 1 MB default would reject
# any real photo with a bare 413 before the request ever reached it.
client_max_body_size 20m;
# The first request for a given /api/img width renders it on demand; an
# 8000px source can take a while on a small VPS, and nginx's 60s default
# turned that into a 504 — a card thumbnail that stayed broken until the
# variant finished, while the original (/uploads) opened fine.
proxy_read_timeout 180s;
# Docker's embedded DNS. Without re-resolving at request time, nginx caches the
# api container's IP from startup and keeps returning 502 ("no live upstreams")
# after the api container restarts with a new IP.
@@ -7,7 +7,7 @@
-->
<div class="gallery-upload">
<a-upload-dragger
accept="image/*"
accept="image/jpeg,image/png,image/webp,image/gif,image/avif,image/bmp,image/tiff,image/heic,image/heif,image/svg+xml"
multiple
:show-upload-list="false"
:custom-request="doUpload"
@@ -29,7 +29,7 @@
class="tile"
:class="{ 'is-uploading': item.status === 'uploading' }"
>
<img :src="imageUrl(item.url, 400) ?? item.preview" alt="" />
<img :src="imageUrl(item.url, 400) ?? item.preview" alt="" @error="fallback($event, item)" />
<div v-if="item.status === 'uploading'" class="tile__progress">
<a-progress type="circle" :percent="item.percent" :size="40" :stroke-width="8" stroke-color="#fff" trail-color="rgba(255,255,255,.3)" :show-info="false" />
@@ -196,6 +196,18 @@ function preview(item: Item) {
previewVisible.value = true;
}
/**
* A resized preview is a bonus, not a requirement: when the variant endpoint
* fails (for example while the server is still rendering a huge source image)
* fall back to the stored original so the tile never shows a broken image.
*/
function fallback(e: Event, item: Item) {
const img = e.target as HTMLImageElement;
if (item.url && img.src !== new URL(item.url, window.location.origin).href) {
img.src = item.url;
}
}
onBeforeUnmount(() => {
items.value.forEach((i) => i.preview && URL.revokeObjectURL(i.preview));
});
@@ -15,7 +15,7 @@
:file-list="fileList"
list-type="picture-card"
:max-count="1"
accept="image/*"
accept="image/jpeg,image/png,image/webp,image/gif,image/avif,image/bmp,image/tiff,image/heic,image/heif,image/svg+xml"
:custom-request="doUpload"
:before-upload="beforeUpload"
@remove="handleRemove"
+12 -6
View File
@@ -1,16 +1,22 @@
// Checks and error wording shared by the image uploaders. The limits mirror
// AdminUploadsService in apps/api.
export const MAX_UPLOAD_BYTES = 8 * 1024 * 1024;
// AdminUploadsService in apps/api: 15 MB, up to 8000×8000, every standard
// image format (plus PDF for document slots).
export const MAX_UPLOAD_BYTES = 15 * 1024 * 1024;
const IMAGE_TYPES = /^image\/(jpeg|png|gif|webp|svg\+xml)$/;
const IMAGE_TYPES =
/^image\/(jpeg|jpg|pjpeg|png|apng|gif|webp|svg\+xml|avif|bmp|x-ms-bmp|tiff|heic|heif|jxl)$/;
/** Same list by extension, for files the browser reports with an empty type. */
const IMAGE_EXTS = /\.(jpe?g|png|apng|gif|webp|svg|avif|bmp|tiff?|heic|heif|jxl)$/i;
/** Null when the file may be uploaded, otherwise the message to show. */
export function checkImageFile(file: File): string | null {
if (!IMAGE_TYPES.test(file.type)) {
return `«${file.name}» پشتیبانی نمی‌شود؛ فقط تصویر JPG، PNG، WebP، GIF یا SVG`;
const known = file.type ? IMAGE_TYPES.test(file.type) : IMAGE_EXTS.test(file.name);
if (!known) {
return `«${file.name}» پشتیبانی نمی‌شود؛ تصویر JPG، PNG، WebP، GIF، SVG، AVIF، BMP، TIFF یا HEIC انتخاب کنید`;
}
if (file.size > MAX_UPLOAD_BYTES) {
return `حجم «${file.name}» بیشتر از ۸ مگابایت است؛ فایل کوچک‌تری انتخاب کنید`;
return `حجم «${file.name}» بیشتر از ۱۵ مگابایت است؛ فایل کوچک‌تری انتخاب کنید`;
}
return null;
}