/** * ShowcaseView.js * Shared showcase component for displaying examples in model modals (Lora/Checkpoint) */ import { showToast } from '../../../utils/uiHelpers.js'; import { state } from '../../../state/index.js'; import { NSFW_LEVELS } from '../../../utils/constants.js'; import { initLazyLoading, initNsfwBlurHandlers, initMetadataPanelHandlers, initMediaControlHandlers } from './MediaUtils.js'; import { generateMetadataPanel } from './MetadataPanel.js'; import { generateImageWrapper, generateVideoWrapper } from './MediaRenderers.js'; /** * Load example images asynchronously * @param {Array} images - Array of image objects (both regular and custom) * @param {string} modelHash - Model hash for fetching local files */ export async function loadExampleImages(images, modelHash) { try { const showcaseTab = document.getElementById('showcase-tab'); if (!showcaseTab) return; // First fetch local example files let localFiles = []; try { const endpoint = '/api/example-image-files'; const params = `model_hash=${modelHash}`; const response = await fetch(`${endpoint}?${params}`); const result = await response.json(); if (result.success) { localFiles = result.files; } } catch (error) { console.error("Failed to get example files:", error); } // Then render with both remote images and local files showcaseTab.innerHTML = renderShowcaseContent(images, localFiles); // Re-initialize the showcase event listeners initShowcaseContent(showcaseTab); // Initialize the example import functionality // initExampleImport(modelHash, showcaseTab); } catch (error) { console.error('Error loading example images:', error); const showcaseTab = document.getElementById('showcase-tab'); if (showcaseTab) { showcaseTab.innerHTML = `
`; } } } /** * Render showcase content * @param {Array} images - Array of images/videos to show * @param {Array} exampleFiles - Local example files * @param {boolean} startExpanded - Whether to start in expanded state (unused in new design) * @returns {string} HTML content */ export function renderShowcaseContent(images, exampleFiles = [], startExpanded = false) { if (!images?.length) { // Show empty state with import interface return renderEmptyShowcase(); } // Filter images based on SFW setting const showOnlySFW = state.settings.show_only_sfw; let filteredImages = images; let hiddenCount = 0; if (showOnlySFW) { filteredImages = images.filter(img => { const nsfwLevel = img.nsfwLevel !== undefined ? img.nsfwLevel : 0; const isSfw = nsfwLevel < NSFW_LEVELS.R; if (!isSfw) hiddenCount++; return isSfw; }); } // Show message if no images are available after filtering if (filteredImages.length === 0) { return `All example images are filtered due to NSFW content settings
Your settings are currently set to show only safe-for-work content
You can change this in Settings
Import images or videos using the sidebar