mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
Add delete model
This commit is contained in:
13
nodes.py
13
nodes.py
@@ -190,9 +190,9 @@ class LorasEndpoint:
|
||||
async def delete_model(self, request):
|
||||
try:
|
||||
data = await request.json()
|
||||
model_name = data.get('model_name')
|
||||
file_name = data.get('file_name')
|
||||
folder = data.get('folder') # 从请求中获取folder信息
|
||||
if not model_name:
|
||||
if not file_name:
|
||||
return web.Response(text='Model name is required', status=400)
|
||||
|
||||
# 构建完整的目录路径
|
||||
@@ -201,10 +201,13 @@ class LorasEndpoint:
|
||||
target_dir = os.path.join(self.loras_root, folder)
|
||||
|
||||
# List of file patterns to delete
|
||||
required_file = f"{model_name}.safetensors" # 主文件必须存在
|
||||
required_file = f"{file_name}.safetensors" # 主文件必须存在
|
||||
optional_files = [ # 这些文件可能不存在
|
||||
f"{model_name}.civitai.info",
|
||||
f"{model_name}.preview.png"
|
||||
f"{file_name}.metadata.json",
|
||||
f"{file_name}.preview.png",
|
||||
f"{file_name}.preview.jpg",
|
||||
f"{file_name}.preview.jpeg",
|
||||
f"{file_name}.preview.webp"
|
||||
]
|
||||
|
||||
deleted_files = []
|
||||
|
||||
@@ -52,16 +52,16 @@ function openCivitai(modelName) {
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteModel(modelName) {
|
||||
async function deleteModel(fileName) {
|
||||
// Prevent event bubbling
|
||||
event.stopPropagation();
|
||||
|
||||
// Get the folder from the card's data attributes
|
||||
const card = document.querySelector(`.lora-card[data-file_name="${modelName}"]`);
|
||||
const card = document.querySelector(`.lora-card[data-file_name="${fileName}"]`);
|
||||
const folder = card ? card.dataset.folder : null;
|
||||
|
||||
// Show confirmation dialog
|
||||
const confirmed = confirm(`Are you sure you want to delete "${modelName}" and all associated files?`);
|
||||
const confirmed = confirm(`Are you sure you want to delete "${fileName}" and all associated files?`);
|
||||
|
||||
if (confirmed) {
|
||||
try {
|
||||
@@ -71,7 +71,7 @@ async function deleteModel(modelName) {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model_name: modelName,
|
||||
file_name: fileName,
|
||||
folder: folder
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user