hgfhfd
This commit is contained in:
@@ -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 });
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user