Add Lora syntax send to comfyui functionality: implement API endpoint and frontend integration for sending and updating LoRA codes in ComfyUI nodes.

This commit is contained in:
Will Miao
2025-05-14 21:09:36 +08:00
parent 99b36442bb
commit 64a906ca5e
4 changed files with 186 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { showToast, openCivitai, copyToClipboard } from '../utils/uiHelpers.js';
import { showToast, openCivitai, copyToClipboard, sendLoraToWorkflow } from '../utils/uiHelpers.js';
import { state } from '../state/index.js';
import { showLoraModal } from './loraModal/index.js';
import { bulkManager } from '../managers/BulkManager.js';
@@ -51,9 +51,14 @@ function handleLoraCardEvent(event) {
return;
}
if (event.target.closest('.fa-copy')) {
if (event.target.closest('.fa-copy') || event.target.closest('.fa-paper-plane')) {
event.stopPropagation();
copyLoraCode(card);
const useSendButton = state.settings.useSendButton || true;
if (useSendButton) {
sendLoraToComfyUI(card, event.shiftKey);
} else {
copyLoraCode(card);
}
return;
}
@@ -181,6 +186,15 @@ async function copyLoraCode(card) {
await copyToClipboard(loraSyntax, 'LoRA syntax copied');
}
// New function to send LoRA to ComfyUI workflow
async function sendLoraToComfyUI(card, replaceMode) {
const usageTips = JSON.parse(card.dataset.usage_tips || '{}');
const strength = usageTips.strength || 1;
const loraSyntax = `<lora:${card.dataset.file_name}:${strength}>`;
sendLoraToWorkflow(loraSyntax, replaceMode);
}
export function createLoraCard(lora) {
const card = document.createElement('div');
card.className = 'lora-card';
@@ -244,6 +258,8 @@ export function createLoraCard(lora) {
// Get favorite status from the lora data
const isFavorite = lora.favorite === true;
// Check if we're using send button instead of copy button
const useSendButton = state.settings.useSendButton || true;
card.innerHTML = `
<div class="card-preview ${shouldBlur ? 'blurred' : ''}">
@@ -269,8 +285,8 @@ export function createLoraCard(lora) {
title="${lora.from_civitai ? 'View on Civitai' : 'Not available from Civitai'}"
${!lora.from_civitai ? 'style="opacity: 0.5; cursor: not-allowed"' : ''}>
</i>
<i class="fas fa-copy"
title="Copy LoRA Syntax">
<i class="${useSendButton ? 'fas fa-paper-plane' : 'fas fa-copy'}"
title="${useSendButton ? 'Send to ComfyUI (Click: Append, Shift+Click: Replace)' : 'Copy LoRA Syntax'}">
</i>
<i class="fas fa-trash"
title="Delete Model">