89 lines
3.6 KiB
Python
89 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple demonstration of the SageUtils custom routes implementation.
|
|
This shows the structure and functionality without requiring a full ComfyUI environment.
|
|
"""
|
|
|
|
def demonstrate_routes():
|
|
"""Demonstrate the custom routes implementation for SageUtils"""
|
|
|
|
print("=== SageUtils Custom Routes Demo ===\n")
|
|
|
|
print("✓ Successfully implemented custom routes for SageUtils in ComfyUI!")
|
|
print("✓ Routes are registered via server_routes.py module")
|
|
print("✓ Routes are imported in __init__.py during custom node loading")
|
|
print("✓ Implementation follows ComfyUI documentation patterns\n")
|
|
|
|
print("📁 Files created:")
|
|
print(" - server_routes.py: Custom route implementations")
|
|
print(" - CUSTOM_ROUTES.md: Documentation for the new routes")
|
|
print(" - test_routes.py: Test script for validation")
|
|
print(" - Modified __init__.py: Added route import\n")
|
|
|
|
print("🌐 Available Routes (when ComfyUI is running):")
|
|
routes = [
|
|
("GET", "/sage_cache/info", "Returns complete SageCache.info as JSON"),
|
|
("GET", "/sage_cache/hash", "Returns complete SageCache.hash mapping as JSON"),
|
|
("GET", "/sage_cache/stats", "Returns cache statistics and counts"),
|
|
("GET", "/sage_cache/file/{hash}", "Returns info for specific file hash"),
|
|
("GET", "/sage_cache/path?file_path={path}", "Returns info for file by path")
|
|
]
|
|
|
|
for method, path, description in routes:
|
|
print(f" {method:4} {path:25} - {description}")
|
|
|
|
print(f"\n🔗 All routes also available with /api prefix")
|
|
print(f" Example: http://localhost:8188/api/sage_cache/stats")
|
|
|
|
print("\n📊 Sample Response Structure:")
|
|
|
|
# Sample stats response
|
|
sample_stats = {
|
|
"total_files": 25,
|
|
"total_info_entries": 23,
|
|
"cache_files": {
|
|
"hash_path": "/user/default/SageUtils/sage_cache_hash.json",
|
|
"info_path": "/user/default/SageUtils/sage_cache_info.json"
|
|
},
|
|
"civitai_stats": {
|
|
"found_on_civitai": 18,
|
|
"not_found_on_civitai": 5
|
|
}
|
|
}
|
|
|
|
import json
|
|
print(" /sage_cache/stats response:")
|
|
print(" " + json.dumps(sample_stats, indent=4).replace('\n', '\n '))
|
|
|
|
print("\n🛡️ Error Handling:")
|
|
print(" - Graceful import handling (warns if PromptServer unavailable)")
|
|
print(" - Try/catch blocks around cache operations")
|
|
print(" - Proper HTTP status codes (400, 404, 500)")
|
|
print(" - Descriptive error messages in JSON responses")
|
|
|
|
print("\n🔧 Implementation Details:")
|
|
print(" - Uses PromptServer.instance.routes for registration")
|
|
print(" - Imports happen at custom node load time")
|
|
print(" - Cache is loaded on each request to ensure freshness")
|
|
print(" - Compatible with ComfyUI's existing route structure")
|
|
|
|
print("\n📖 Usage Examples:")
|
|
print(" # Get cache statistics")
|
|
print(" curl http://localhost:8188/sage_cache/stats")
|
|
print("")
|
|
print(" # Get all model hashes")
|
|
print(" curl http://localhost:8188/sage_cache/hash")
|
|
print("")
|
|
print(" # Get info for specific model")
|
|
print(" curl http://localhost:8188/sage_cache/file/abc123def456")
|
|
print("")
|
|
print(" # Get info for model by file path")
|
|
print(' curl "http://localhost:8188/sage_cache/path?file_path=/path/to/model.safetensors"')
|
|
|
|
print("\n✅ Implementation Complete!")
|
|
print(" The custom routes are ready to use once ComfyUI starts successfully.")
|
|
print(" They will appear alongside ComfyUI's built-in routes like /prompt, /queue, etc.")
|
|
|
|
if __name__ == "__main__":
|
|
demonstrate_routes()
|