Add toast for indexing images

This commit is contained in:
Lucas Sköld
2025-06-28 21:41:54 +02:00
parent 25ffb9731b
commit e2f5726aec
2 changed files with 25 additions and 7 deletions
+6 -5
View File
@@ -31,7 +31,7 @@ def index_images():
# Ensure directory exists
if not images_dir.exists():
print(f"Warning: Directory not found: {images_dir}")
return False
return {"success": False}
# Get all image files recursively
image_files = []
@@ -59,11 +59,12 @@ def index_images():
json.dump(output, f, indent=2)
print(f"Created index with {len(images)} images at {json_path}")
return True
return_data = {"success": True, "count": len(images)}
return return_data
except Exception as e:
print(f"Error creating image index: {str(e)}")
return False
return {"success": False}
# Create image index
@@ -89,8 +90,8 @@ async def get_enabled(request):
@PromptServer.instance.routes.get(f"{API_PREFIX}/index")
async def index_images_endpoint(request):
success = index_images()
return web.json_response({"success": success})
data = index_images()
return web.json_response(data)
@PromptServer.instance.routes.get(f"{API_PREFIX}/favorites")
+19 -2
View File
@@ -1,4 +1,4 @@
import { SettingsHelper } from "./settings/ComfyHelper.js";
import { SettingsHelper, UiHelper } from "./settings/ComfyHelper.js";
export const API_PREFIX = "/SyntaxHighlighting";
export const settingsHelper = new SettingsHelper("SyntaxHighlighting");
@@ -86,7 +86,24 @@ const settingsDefinitions = [
name: "Index Images",
category: ["Syntax Highlighting", "Preview Image", "IndexImages"],
type: SettingsHelper.ST.BUTTON("Index Images", async () => {
await fetch(`${API_PREFIX}/index`);
const response = await fetch(`${API_PREFIX}/index`);
if (!response.ok) {
settingsHelper.uiHelper.addToast(
UiHelper.Severity.ERROR,
"Indexing Images Failed",
"",
5000
);
return;
}
const data = await response.json();
settingsHelper.uiHelper.addToast(
UiHelper.Severity.INFO,
"Indexing Images",
`Indexed ${data.count} images.`,
5000
);
SettingsHelper.PresetOnChange.reloadSettings();
}),
tooltip: "Update images available for preview.",