refactor(showcase): improve custom image identification logic in renderMediaItem and findLocalFile functions

This commit is contained in:
Will Miao
2025-09-15 20:18:39 +08:00
parent 86074c87d7
commit 0dc4b6f728
2 changed files with 2 additions and 4 deletions

View File

@@ -75,8 +75,6 @@ export function generateImageWrapper(media, heightPercent, shouldBlur, nsfwText,
data-remote-src="${remoteUrl}" data-remote-src="${remoteUrl}"
data-nsfw-level="${nsfwLevel}" data-nsfw-level="${nsfwLevel}"
alt="Preview" alt="Preview"
crossorigin="anonymous"
referrerpolicy="no-referrer"
width="${media.width}" width="${media.width}"
height="${media.height}" height="${media.height}"
class="lazy ${shouldBlur ? 'blurred' : ''}"> class="lazy ${shouldBlur ? 'blurred' : ''}">

View File

@@ -191,7 +191,7 @@ function renderMediaItem(img, index, exampleFiles) {
); );
// Determine if this is a custom image (has id property) // Determine if this is a custom image (has id property)
const isCustomImage = Boolean(img.id); const isCustomImage = Boolean(typeof img.id === 'string' && img.id);
// Create the media control buttons HTML // Create the media control buttons HTML
const mediaControlsHtml = ` const mediaControlsHtml = `
@@ -235,7 +235,7 @@ function findLocalFile(img, index, exampleFiles) {
let localFile = null; let localFile = null;
if (img.id) { if (typeof img.id === 'string' && img.id) {
// This is a custom image, find by custom_<id> // This is a custom image, find by custom_<id>
const customPrefix = `custom_${img.id}`; const customPrefix = `custom_${img.id}`;
localFile = exampleFiles.find(file => file.name.startsWith(customPrefix)); localFile = exampleFiles.find(file => file.name.startsWith(customPrefix));