mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
Refactor recipe saving process to utilize workflow JSON and enhance Lora handling
- Updated the recipe saving logic to accept a workflow JSON input instead of individual fields like name, tags, and metadata. - Implemented parsing of the workflow to extract generation parameters and Lora stack, improving the recipe creation process. - Enhanced error handling for missing workflow data and invalid Lora formats. - Removed deprecated code related to individual field handling, streamlining the recipe saving functionality. - Updated the front-end widget to send the workflow JSON directly, simplifying the data preparation process.
This commit is contained in:
@@ -769,28 +769,8 @@ export function addLorasWidget(node, name, opts, callback) {
|
||||
// Function to directly save the recipe without dialog
|
||||
async function saveRecipeDirectly(widget) {
|
||||
try {
|
||||
// Get the workflow data from the ComfyUI app
|
||||
const prompt = await app.graphToPrompt();
|
||||
console.log("prompt", prompt);
|
||||
// Filter active loras
|
||||
const activeLoras = widget.value.filter(lora => lora.active);
|
||||
|
||||
if (activeLoras.length === 0) {
|
||||
// Show toast notification for no active LoRAs
|
||||
if (app && app.extensionManager && app.extensionManager.toast) {
|
||||
app.extensionManager.toast.add({
|
||||
severity: 'warn',
|
||||
summary: 'No Active LoRAs',
|
||||
detail: 'Please activate at least one LoRA to save a recipe',
|
||||
life: 3000
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate a name based on active LoRAs
|
||||
const recipeName = activeLoras.map(lora =>
|
||||
`${lora.name.split('/').pop().split('\\').pop()}:${lora.strength}`
|
||||
).join(' ');
|
||||
|
||||
// Show loading toast
|
||||
if (app && app.extensionManager && app.extensionManager.toast) {
|
||||
@@ -802,21 +782,9 @@ async function saveRecipeDirectly(widget) {
|
||||
});
|
||||
}
|
||||
|
||||
// Prepare the data
|
||||
// Prepare the data - only send workflow JSON
|
||||
const formData = new FormData();
|
||||
formData.append('name', recipeName);
|
||||
formData.append('tags', JSON.stringify([]));
|
||||
|
||||
// Prepare metadata with loras
|
||||
const metadata = {
|
||||
loras: activeLoras.map(lora => ({
|
||||
name: lora.name,
|
||||
weight: parseFloat(lora.strength),
|
||||
active: true
|
||||
}))
|
||||
};
|
||||
|
||||
formData.append('metadata', JSON.stringify(metadata));
|
||||
formData.append('workflow_json', JSON.stringify(prompt.output));
|
||||
|
||||
// Send the request
|
||||
const response = await fetch('/api/recipes/save-from-widget', {
|
||||
|
||||
Reference in New Issue
Block a user