From 1a942066ec3e6edf689a7c58367ac7836cc25994 Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Thu, 16 Jul 2026 19:55:14 +0200 Subject: [PATCH] hgfhfd --- public/s/js/settings.js | 7 +++++-- src/banner_handler.mjs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/public/s/js/settings.js b/public/s/js/settings.js index a59a038..9ef05ac 100644 --- a/public/s/js/settings.js +++ b/public/s/js/settings.js @@ -647,7 +647,7 @@ } const croppedFile = new File([blob], file.name.replace(/\.[^/.]+$/, "") + ".webp", { type: 'image/webp' }); cleanup(); - resolve({ file: croppedFile, banner_position: 'center', banner_size: 'cover' }); + resolve({ file: croppedFile, file_orig: file, banner_position: 'center', banner_size: 'cover' }); }, 'image/webp', 0.9); }); @@ -682,6 +682,7 @@ const formData = new FormData(); formData.append('file', payload.file); + if (payload.file_orig) formData.append('file_orig', payload.file_orig); formData.append('banner_position', payload.banner_position); formData.append('banner_size', payload.banner_size); @@ -824,12 +825,14 @@ const urlMatch = bgImg.match(/url\(['"]?(.*?)['"]?\)/); if (!urlMatch) return; const url = urlMatch[1].split('?')[0]; // Strip cache buster if present + const origUrl = url.replace('.webp', '_orig.webp'); try { e.target.disabled = true; e.target.textContent = 'Loading...'; - const res = await fetch(url); + let res = await fetch(origUrl); + if (!res.ok) { res = await fetch(url); } const blob = await res.blob(); const file = new File([blob], 'banner.webp', { type: blob.type }); diff --git a/src/banner_handler.mjs b/src/banner_handler.mjs index cb275f4..27cedf2 100644 --- a/src/banner_handler.mjs +++ b/src/banner_handler.mjs @@ -148,6 +148,20 @@ export const handleBannerUpload = async (req, res) => { } console.log('[BANNER HANDLER] Magick done, output:', finalPath); + const file_orig = parts.file_orig; + if (file_orig && file_orig.data) { + console.log('[BANNER HANDLER] Processing original file...'); + const origTmpPath = path.join(cfg.paths.tmp, `banner_${uuid}_orig_tmp`); + const finalOrigPath = path.join(cfg.paths.a, `banner_${uuid}_orig.webp`); + await fs.writeFile(origTmpPath, file_orig.data); + try { + await execFile('magick', [`${origTmpPath}[0]`, '-resize', '3840x3840>', '-quality', '85', finalOrigPath]); + } catch (err) { + console.error('[BANNER HANDLER] Magick error on original:', err.message); + } + await fs.unlink(origTmpPath).catch(() => { }); + } + // Get current banner_file to delete old one (after magick succeeds) let currentBanner = null; try { @@ -165,6 +179,8 @@ export const handleBannerUpload = async (req, res) => { if (currentBanner) { const oldPath = path.join(cfg.paths.a, currentBanner); await fs.unlink(oldPath).catch(() => { }); + const oldOrigPath = path.join(cfg.paths.a, currentBanner.replace('.webp', '_orig.webp')); + await fs.unlink(oldOrigPath).catch(() => { }); } // Update database @@ -240,6 +256,8 @@ export const handleBannerDelete = async (req, res) => { if (currentBanner) { const oldPath = path.join(cfg.paths.a, currentBanner); await fs.unlink(oldPath).catch(() => { }); + const oldOrigPath = path.join(cfg.paths.a, currentBanner.replace('.webp', '_orig.webp')); + await fs.unlink(oldOrigPath).catch(() => { }); } await db`