mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-09-20 18:51:26 -03:00
feat(recipes): add reconnect remediation paths for missing recipe LoRAs
- Snapshot pre-rematch entry state (reconnectSnapshot) so rematched entries can be undone via the existing restore flow - Bulk missing-LoRA downloads mark unresolvable failures hash-invalid, flipping those entries from download to reconnect candidacy - Recipe modal always offers a reconnect action next to download for missing LoRA entries - Rematch runs collect an opt-in relaxed-matching choice (also reconnect missing models by file name) via a pre-run options dialog on the global, bulk and single-recipe entries - L4 (filename-level) matches are listed in a results dialog with per-entry undo
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { showToast } from '../utils/uiHelpers.js';
|
||||
import { isUnresolvableDownloadError } from '../utils/uiHelpers.js';
|
||||
import { translate } from '../utils/i18nHelpers.js';
|
||||
import { getModelApiClient } from '../api/modelApiFactory.js';
|
||||
import { MODEL_TYPES } from '../api/apiConfig.js';
|
||||
import { extractRecipeId } from '../api/recipeApi.js';
|
||||
import { state } from '../state/index.js';
|
||||
import { modalManager } from './ModalManager.js';
|
||||
|
||||
@@ -13,6 +15,7 @@ export class BulkMissingLoraDownloadManager {
|
||||
this.loraApiClient = getModelApiClient(MODEL_TYPES.LORA);
|
||||
this.pendingLoras = [];
|
||||
this.pendingRecipes = [];
|
||||
this.pendingMissingByRecipe = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,6 +139,7 @@ export class BulkMissingLoraDownloadManager {
|
||||
// Execute download
|
||||
await this.executeDownload(this.pendingLoras);
|
||||
this.pendingLoras = [];
|
||||
this.pendingMissingByRecipe = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,6 +157,9 @@ export class BulkMissingLoraDownloadManager {
|
||||
|
||||
// Collect missing LoRAs with deduplication
|
||||
const stats = this.collectMissingLoras(selectedRecipes);
|
||||
// Kept so executeDownload can mark unresolvable failures back onto
|
||||
// every recipe occurrence (hashInvalid → reconnect candidacy).
|
||||
this.pendingMissingByRecipe = stats.missingLorasByRecipe;
|
||||
|
||||
if (stats.uniqueCount === 0) {
|
||||
showToast('toast.recipes.noMissingLorasInSelection', {}, 'info');
|
||||
@@ -196,6 +203,7 @@ export class BulkMissingLoraDownloadManager {
|
||||
|
||||
let completedDownloads = 0;
|
||||
let failedDownloads = 0;
|
||||
let markedInvalidCount = 0;
|
||||
let currentLoraProgress = 0;
|
||||
let cancelled = false;
|
||||
|
||||
@@ -304,6 +312,12 @@ export class BulkMissingLoraDownloadManager {
|
||||
if (!response.success) {
|
||||
console.error(`Failed to download LoRA ${lora.name || lora.file_name}: ${response.error}`);
|
||||
failedDownloads++;
|
||||
// An unresolvable failure (model gone on CivitAI) flips
|
||||
// every recipe occurrence to reconnect candidacy — same
|
||||
// rule as the single-LoRA download in RecipeModal.
|
||||
if (isUnresolvableDownloadError(response.error)) {
|
||||
markedInvalidCount += await this.markLoraHashInvalidInRecipes(lora);
|
||||
}
|
||||
} else {
|
||||
completedDownloads++;
|
||||
updateProgress(100, completedDownloads, '');
|
||||
@@ -312,6 +326,9 @@ export class BulkMissingLoraDownloadManager {
|
||||
if (!cancelled) {
|
||||
console.error(`Error downloading LoRA ${lora.name || lora.file_name}:`, error);
|
||||
failedDownloads++;
|
||||
if (isUnresolvableDownloadError(error?.message)) {
|
||||
markedInvalidCount += await this.markLoraHashInvalidInRecipes(lora);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,9 +352,16 @@ export class BulkMissingLoraDownloadManager {
|
||||
}, 'warning');
|
||||
}
|
||||
|
||||
// Unresolvable failures were marked hash-invalid during the loop;
|
||||
// tell the user those entries now offer reconnect instead of download.
|
||||
if (markedInvalidCount > 0) {
|
||||
showToast('toast.recipes.unresolvableMarkedForReconnect', {
|
||||
count: markedInvalidCount
|
||||
}, 'info', `${markedInvalidCount} unresolvable entr(ies) marked — they can now be reconnected to a local LoRA.`);
|
||||
}
|
||||
|
||||
// Update each affected recipe card with fresh data (LoRA inLibrary flags changed)
|
||||
if (state.virtualScroller) {
|
||||
const { extractRecipeId } = await import('../api/recipeApi.js');
|
||||
for (const recipe of this.pendingRecipes) {
|
||||
const recipeId = extractRecipeId(recipe.file_path);
|
||||
if (!recipeId) continue;
|
||||
@@ -354,6 +378,59 @@ export class BulkMissingLoraDownloadManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark every recipe occurrence of a failed LoRA as hash-invalid.
|
||||
*
|
||||
* Mirrors RecipeModal.markLoraHashInvalid for the bulk flow: the flag
|
||||
* makes each occurrence an unresolved rematch candidate and swaps its
|
||||
* action from download to reconnect. Only called for unresolvable
|
||||
* failures — transient errors leave entries untouched.
|
||||
*
|
||||
* @param {Object} failedLora - The deduplicated LoRA that failed
|
||||
* @returns {Promise<number>} - How many recipe entries were marked
|
||||
*/
|
||||
async markLoraHashInvalidInRecipes(failedLora) {
|
||||
const failedKey = failedLora.hash || failedLora.id || failedLora.modelVersionId;
|
||||
if (!failedKey || !this.pendingMissingByRecipe) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let marked = 0;
|
||||
for (const { recipe, missingLoras } of this.pendingMissingByRecipe.values()) {
|
||||
const recipeId = extractRecipeId(recipe.file_path) || recipe.id;
|
||||
if (!recipeId || !Array.isArray(recipe.loras)) {
|
||||
continue;
|
||||
}
|
||||
for (const entry of missingLoras) {
|
||||
const entryKey = entry.hash || entry.id || entry.modelVersionId;
|
||||
if (entryKey !== failedKey) {
|
||||
continue;
|
||||
}
|
||||
const loraIndex = recipe.loras.indexOf(entry);
|
||||
if (loraIndex < 0) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const response = await fetch('/api/lm/recipe/lora/mark-hash-invalid', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
recipe_id: recipeId,
|
||||
lora_index: loraIndex,
|
||||
}),
|
||||
});
|
||||
if (response.ok) {
|
||||
entry.hashInvalid = true;
|
||||
marked++;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to mark LoRA hash invalid:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
return marked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get LoRA root directory from API
|
||||
* @returns {Promise<string|null>} - LoRA root directory or null
|
||||
|
||||
Reference in New Issue
Block a user