mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
feat: Add endpoint for scanning and rebuilding recipe cache, and update UI to use new refresh method
This commit is contained in:
@@ -75,6 +75,9 @@ class RecipeRoutes:
|
|||||||
# Add route to get recipes for a specific Lora
|
# Add route to get recipes for a specific Lora
|
||||||
app.router.add_get('/api/recipes/for-lora', routes.get_recipes_for_lora)
|
app.router.add_get('/api/recipes/for-lora', routes.get_recipes_for_lora)
|
||||||
|
|
||||||
|
# Add new endpoint for scanning and rebuilding the recipe cache
|
||||||
|
app.router.add_get('/api/recipes/scan', routes.scan_recipes)
|
||||||
|
|
||||||
async def _init_cache(self, app):
|
async def _init_cache(self, app):
|
||||||
"""Initialize cache on startup"""
|
"""Initialize cache on startup"""
|
||||||
try:
|
try:
|
||||||
@@ -1255,3 +1258,24 @@ class RecipeRoutes:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error getting recipes for Lora: {str(e)}")
|
logger.error(f"Error getting recipes for Lora: {str(e)}")
|
||||||
return web.json_response({'success': False, 'error': str(e)}, status=500)
|
return web.json_response({'success': False, 'error': str(e)}, status=500)
|
||||||
|
|
||||||
|
async def scan_recipes(self, request: web.Request) -> web.Response:
|
||||||
|
"""API endpoint for scanning and rebuilding the recipe cache"""
|
||||||
|
try:
|
||||||
|
# Ensure services are initialized
|
||||||
|
await self.init_services()
|
||||||
|
|
||||||
|
# Force refresh the recipe cache
|
||||||
|
logger.info("Manually triggering recipe cache rebuild")
|
||||||
|
await self.recipe_scanner.get_cached_data(force_refresh=True)
|
||||||
|
|
||||||
|
return web.json_response({
|
||||||
|
'success': True,
|
||||||
|
'message': 'Recipe cache refreshed successfully'
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error refreshing recipe cache: {e}", exc_info=True)
|
||||||
|
return web.json_response({
|
||||||
|
'success': False,
|
||||||
|
'error': str(e)
|
||||||
|
}, status=500)
|
||||||
|
|||||||
@@ -268,6 +268,32 @@ class RecipeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes the recipe list by first rebuilding the cache and then loading recipes
|
||||||
|
*/
|
||||||
|
async refreshRecipes() {
|
||||||
|
try {
|
||||||
|
// Call the new endpoint to rebuild the recipe cache
|
||||||
|
const response = await fetch('/api/recipes/scan');
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
throw new Error(data.error || 'Failed to refresh recipe cache');
|
||||||
|
}
|
||||||
|
|
||||||
|
// After successful cache rebuild, load the recipes
|
||||||
|
await this.loadRecipes(true);
|
||||||
|
|
||||||
|
appCore.showToast('Refresh complete', 'success');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error refreshing recipes:', error);
|
||||||
|
appCore.showToast(error.message || 'Failed to refresh recipes', 'error');
|
||||||
|
|
||||||
|
// Still try to load recipes even if scan failed
|
||||||
|
await this.loadRecipes(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _loadSpecificRecipe(recipeId) {
|
async _loadSpecificRecipe(recipeId) {
|
||||||
try {
|
try {
|
||||||
// Fetch specific recipe by ID
|
// Fetch specific recipe by ID
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
<div class="action-buttons">
|
<div class="action-buttons">
|
||||||
<div title="Refresh recipe list" class="control-group">
|
<div title="Refresh recipe list" class="control-group">
|
||||||
<button onclick="recipeManager.loadRecipes(true)"><i class="fas fa-sync"></i> Refresh</button>
|
<button onclick="recipeManager.refreshRecipes()"><i class="fas fa-sync"></i> Refresh</button>
|
||||||
</div>
|
</div>
|
||||||
<div title="Import recipes" class="control-group">
|
<div title="Import recipes" class="control-group">
|
||||||
<button onclick="importManager.showImportModal()"><i class="fas fa-file-import"></i> Import</button>
|
<button onclick="importManager.showImportModal()"><i class="fas fa-file-import"></i> Import</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user