feat: auto-optimize images on CMS upload via AssetBucketBrowser
Deploy to VPS / deploy (push) Has been cancelled
Deploy to VPS / deploy (push) Has been cancelled
Enables the existing Sharp pipeline for all uploads — WebP conversion, auto-orient, 2560px cap, content-hash filenames. Upload toast now shows compression savings percentage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -193,10 +193,17 @@ export default function AssetBucketBrowser({
|
|||||||
fd.append("slug", slug);
|
fd.append("slug", slug);
|
||||||
fd.append("path", activeBucket.path);
|
fd.append("path", activeBucket.path);
|
||||||
fd.append("file", file);
|
fd.append("file", file);
|
||||||
|
fd.append("optimize", "1");
|
||||||
const res = await fetch("/api/assets", { method: "POST", body: fd });
|
const res = await fetch("/api/assets", { method: "POST", body: fd });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
setUploadProgress(`✓ ${data.file.name}`);
|
const f = data.file;
|
||||||
|
if (f.optimized && f.savedBytes > 0) {
|
||||||
|
const pct = Math.round((f.savedBytes / f.originalBytes) * 100);
|
||||||
|
setUploadProgress(`✓ ${f.name} (−${pct}% optimized)`);
|
||||||
|
} else {
|
||||||
|
setUploadProgress(`✓ ${f.name}`);
|
||||||
|
}
|
||||||
await fetchItems();
|
await fetchItems();
|
||||||
setTimeout(() => setUploadProgress(""), 1500);
|
setTimeout(() => setUploadProgress(""), 1500);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user