mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
109 lines
3.3 KiB
JavaScript
109 lines
3.3 KiB
JavaScript
import { modalManager } from '../managers/ModalManager.js';
|
|
import { excludeLora } from '../api/loraApi.js';
|
|
import { excludeCheckpoint } from '../api/checkpointApi.js';
|
|
|
|
let pendingDeletePath = null;
|
|
let pendingModelType = null;
|
|
let pendingExcludePath = null;
|
|
let pendingExcludeModelType = null;
|
|
|
|
export function showDeleteModal(filePath, modelType = 'lora') {
|
|
pendingDeletePath = filePath;
|
|
pendingModelType = modelType;
|
|
|
|
const card = document.querySelector(`.lora-card[data-filepath="${filePath}"]`);
|
|
const modelName = card ? card.dataset.name : filePath.split('/').pop();
|
|
const modal = modalManager.getModal('deleteModal').element;
|
|
const modelInfo = modal.querySelector('.delete-model-info');
|
|
|
|
modelInfo.innerHTML = `
|
|
<strong>Model:</strong> ${modelName}
|
|
<br>
|
|
<strong>File:</strong> ${filePath}
|
|
`;
|
|
|
|
modalManager.showModal('deleteModal');
|
|
}
|
|
|
|
export async function confirmDelete() {
|
|
if (!pendingDeletePath) return;
|
|
|
|
const card = document.querySelector(`.lora-card[data-filepath="${pendingDeletePath}"]`);
|
|
|
|
try {
|
|
// Use the appropriate endpoint based on model type
|
|
const endpoint = pendingModelType === 'checkpoint' ?
|
|
'/api/checkpoints/delete' :
|
|
'/api/delete_model';
|
|
|
|
const response = await fetch(endpoint, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
file_path: pendingDeletePath
|
|
})
|
|
});
|
|
|
|
if (response.ok) {
|
|
if (card) {
|
|
card.remove();
|
|
}
|
|
closeDeleteModal();
|
|
} else {
|
|
const error = await response.text();
|
|
alert(`Failed to delete model: ${error}`);
|
|
}
|
|
} catch (error) {
|
|
alert(`Error deleting model: ${error}`);
|
|
}
|
|
}
|
|
|
|
export function closeDeleteModal() {
|
|
modalManager.closeModal('deleteModal');
|
|
pendingDeletePath = null;
|
|
pendingModelType = null;
|
|
}
|
|
|
|
// Functions for the exclude modal
|
|
export function showExcludeModal(filePath, modelType = 'lora') {
|
|
pendingExcludePath = filePath;
|
|
pendingExcludeModelType = modelType;
|
|
|
|
const card = document.querySelector(`.lora-card[data-filepath="${filePath}"]`);
|
|
const modelName = card ? card.dataset.name : filePath.split('/').pop();
|
|
const modal = modalManager.getModal('excludeModal').element;
|
|
const modelInfo = modal.querySelector('.exclude-model-info');
|
|
|
|
modelInfo.innerHTML = `
|
|
<strong>Model:</strong> ${modelName}
|
|
<br>
|
|
<strong>File:</strong> ${filePath}
|
|
`;
|
|
|
|
modalManager.showModal('excludeModal');
|
|
}
|
|
|
|
export function closeExcludeModal() {
|
|
modalManager.closeModal('excludeModal');
|
|
pendingExcludePath = null;
|
|
pendingExcludeModelType = null;
|
|
}
|
|
|
|
export async function confirmExclude() {
|
|
if (!pendingExcludePath) return;
|
|
|
|
try {
|
|
// Use appropriate exclude function based on model type
|
|
if (pendingExcludeModelType === 'checkpoint') {
|
|
await excludeCheckpoint(pendingExcludePath);
|
|
} else {
|
|
await excludeLora(pendingExcludePath);
|
|
}
|
|
|
|
closeExcludeModal();
|
|
} catch (error) {
|
|
console.error('Error excluding model:', error);
|
|
}
|
|
} |