Add delete model

This commit is contained in:
Will Miao
2025-01-26 16:32:19 +08:00
parent 0e4a9ab6d4
commit 72e121c145
2 changed files with 12 additions and 9 deletions

View File

@@ -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 = []

View File

@@ -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
})
});