From 7f088e58bc119b8d403a2243a90bf97e213118ce Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Wed, 12 Mar 2025 22:57:21 +0800 Subject: [PATCH] Implement SFW content filtering in LoraModal and update settings management --- static/js/components/LoraModal.js | 36 +++++++++++++++++++++++++-- static/js/managers/SettingsManager.js | 18 +++++++++++--- static/js/state/index.js | 3 ++- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/static/js/components/LoraModal.js b/static/js/components/LoraModal.js index baf520ca..5feaee44 100644 --- a/static/js/components/LoraModal.js +++ b/static/js/components/LoraModal.js @@ -133,14 +133,46 @@ export function showLoraModal(lora) { function renderShowcaseContent(images) { if (!images?.length) return '
No example images available
'; + // 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

+
+ `; + } + + // Show hidden content notification if applicable + const hiddenNotification = hiddenCount > 0 ? + `
+ ${hiddenCount} ${hiddenCount === 1 ? 'image' : 'images'} hidden due to SFW-only setting +
` : ''; + return `
- Scroll or click to show ${images.length} examples + Scroll or click to show ${filteredImages.length} examples