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
+ ${hiddenNotification}
- ${images.map(img => {
+ ${filteredImages.map(img => {
// 计算适当的展示高度:
// 1. 保持原始宽高比
// 2. 限制最大高度为视窗高度的60%
diff --git a/static/js/managers/SettingsManager.js b/static/js/managers/SettingsManager.js
index 0af6b5c8..2afea5a0 100644
--- a/static/js/managers/SettingsManager.js
+++ b/static/js/managers/SettingsManager.js
@@ -44,6 +44,12 @@ export class SettingsManager {
blurMatureContentCheckbox.checked = state.settings.blurMatureContent;
}
+ const showOnlySFWCheckbox = document.getElementById('showOnlySFW');
+ if (showOnlySFWCheckbox) {
+ // Sync with state (backend will set this via template)
+ state.settings.show_only_sfw = showOnlySFWCheckbox.checked;
+ }
+
// Backend settings are loaded from the template directly
}
@@ -60,14 +66,15 @@ export class SettingsManager {
// Get frontend settings from UI
const blurMatureContent = document.getElementById('blurMatureContent').checked;
- // Update frontend state and save to localStorage
- state.settings.blurMatureContent = blurMatureContent;
- saveSettings();
-
// Get backend settings
const apiKey = document.getElementById('civitaiApiKey').value;
const showOnlySFW = document.getElementById('showOnlySFW').checked;
+ // Update frontend state and save to localStorage
+ state.settings.blurMatureContent = blurMatureContent;
+ state.settings.show_only_sfw = showOnlySFW;
+ saveSettings();
+
try {
// Save backend settings via API
const response = await fetch('/api/settings', {
@@ -108,6 +115,9 @@ export class SettingsManager {
img.classList.remove('nsfw-blur');
}
});
+
+ // For show_only_sfw, there's no immediate action needed as it affects content loading
+ // The setting will take effect on next reload
}
}
diff --git a/static/js/state/index.js b/static/js/state/index.js
index b9339349..cde287b1 100644
--- a/static/js/state/index.js
+++ b/static/js/state/index.js
@@ -22,7 +22,8 @@ export const state = {
selectedLoras: new Set(),
loraMetadataCache: new Map(),
settings: {
- blurMatureContent: true
+ blurMatureContent: true,
+ show_only_sfw: false
}
};