From dda19b3920a8917aef621bfcf4884db454432e2b Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Fri, 15 Aug 2025 17:15:31 +0800 Subject: [PATCH] feat: add download example images functionality to context menus, see #347 --- .../ContextMenu/ModelContextMenuMixin.js | 20 +++++++++++++++++++ templates/checkpoints.html | 1 + templates/components/context_menu.html | 3 +++ templates/embeddings.html | 1 + 4 files changed, 25 insertions(+) diff --git a/static/js/components/ContextMenu/ModelContextMenuMixin.js b/static/js/components/ContextMenu/ModelContextMenuMixin.js index cd58bc0f..b8eddbd4 100644 --- a/static/js/components/ContextMenu/ModelContextMenuMixin.js +++ b/static/js/components/ContextMenu/ModelContextMenuMixin.js @@ -1,6 +1,7 @@ import { showToast, getNSFWLevelName, openExampleImagesFolder } from '../../utils/uiHelpers.js'; import { modalManager } from '../../managers/ModalManager.js'; import { state } from '../../state/index.js'; +import { getModelApiClient } from '../../api/modelApiFactory.js'; // Mixin with shared functionality for LoraContextMenu and CheckpointContextMenu export const ModelContextMenuMixin = { @@ -202,6 +203,9 @@ export const ModelContextMenuMixin = { case 'preview': openExampleImagesFolder(this.currentCard.dataset.sha256); return true; + case 'download-examples': + this.downloadExampleImages(); + return true; case 'civitai': if (this.currentCard.dataset.from_civitai === 'true') { if (this.currentCard.querySelector('.fa-globe')) { @@ -222,5 +226,21 @@ export const ModelContextMenuMixin = { default: return false; } + }, + + // Download example images method + async downloadExampleImages() { + const modelHash = this.currentCard.dataset.sha256; + if (!modelHash) { + showToast('Model hash not available', 'error'); + return; + } + + try { + const apiClient = getModelApiClient(); + await apiClient.downloadExampleImages([modelHash]); + } catch (error) { + console.error('Error downloading example images:', error); + } } }; diff --git a/templates/checkpoints.html b/templates/checkpoints.html index f717a7bc..893c9eac 100644 --- a/templates/checkpoints.html +++ b/templates/checkpoints.html @@ -18,6 +18,7 @@
Re-link to Civitai
Copy Model Filename
Open Examples Folder
+
Download Example Images
Replace Preview
Set Content Rating
diff --git a/templates/components/context_menu.html b/templates/components/context_menu.html index e83f8489..980ccb9a 100644 --- a/templates/components/context_menu.html +++ b/templates/components/context_menu.html @@ -23,6 +23,9 @@
Open Examples Folder
+
+ Download Example Images +
Replace Preview
diff --git a/templates/embeddings.html b/templates/embeddings.html index a135fe65..5cbec7e5 100644 --- a/templates/embeddings.html +++ b/templates/embeddings.html @@ -18,6 +18,7 @@
Re-link to Civitai
Copy Model Filename
Open Examples Folder
+
Download Example Images
Replace Preview
Set Content Rating