Release 2.21.5: hide generated image copies from media library
This commit is contained in:
1 parent
b80d4aa9c7
commit
9e988c307e
7 files changed
+32
-7
No files matched your search
@@ -26,6 +26,10 @@ const IMAGE_VARIANT_DIMENSIONS = [2048, 4096, 8192, 16384];
|
||||
const IMAGE_THUMBNAIL_EXTENSIONS = new Set(['.jpg', '.jpeg', '.png', '.webp', '.gif', '.svg']);
|
||||
const IMAGE_THUMBNAIL_MAX_DIMENSION = 480;
|
||||
|
||||
function isGeneratedImageCopyName(name) {
|
||||
return /^image-(?:crop|playback)-[a-f0-9]{64}\.(?:jpe?g|png|webp|gif)$/i.test(String(name || ''));
|
||||
}
|
||||
|
||||
function getImageVariantPath(filePath, dimension) {
|
||||
const extension = path.extname(filePath);
|
||||
const baseName = path.basename(filePath, extension);
|
||||
@@ -352,7 +356,7 @@ async function fetchMediaAssets(pool) {
|
||||
WHERE is_published = 1
|
||||
ORDER BY created_at DESC, id DESC`
|
||||
);
|
||||
return rows || [];
|
||||
return (rows || []).filter(asset => !isGeneratedImageCopyName(path.basename(String(asset.media_path || ''))));
|
||||
}
|
||||
|
||||
async function syncMediaAssetsFromDirectory(pool, uploadDir, userId) {
|
||||
@@ -377,7 +381,7 @@ async function syncMediaAssetsFromDirectory(pool, uploadDir, userId) {
|
||||
continue;
|
||||
}
|
||||
const originalName = String(entry.name || '').trim();
|
||||
if (/\.variant-\d+\.(?:jpe?g|png|webp)$/i.test(originalName) || /\.(?:thumb|poster)\.webp$/i.test(originalName)) {
|
||||
if (isGeneratedImageCopyName(originalName) || /\.variant-\d+\.(?:jpe?g|png|webp)$/i.test(originalName) || /\.(?:thumb|poster)\.webp$/i.test(originalName)) {
|
||||
continue;
|
||||
}
|
||||
const mimeType = MEDIA_MIME_TYPES[path.extname(originalName).toLowerCase()];
|
||||
|
||||
Reference in new issue
Block a user