mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
Add rename functionality for checkpoint and LoRA files with loading indicators
This commit is contained in:
@@ -153,4 +153,40 @@ export async function saveModelMetadata(filePath, data) {
|
|||||||
*/
|
*/
|
||||||
export function excludeCheckpoint(filePath) {
|
export function excludeCheckpoint(filePath) {
|
||||||
return baseExcludeModel(filePath, 'checkpoint');
|
return baseExcludeModel(filePath, 'checkpoint');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a checkpoint file
|
||||||
|
* @param {string} filePath - Current file path
|
||||||
|
* @param {string} newFileName - New file name (without path)
|
||||||
|
* @returns {Promise<Object>} - Promise that resolves with the server response
|
||||||
|
*/
|
||||||
|
export async function renameCheckpointFile(filePath, newFileName) {
|
||||||
|
try {
|
||||||
|
// Show loading indicator
|
||||||
|
state.loadingManager.showSimpleLoading('Renaming checkpoint file...');
|
||||||
|
|
||||||
|
const response = await fetch('/api/rename_checkpoint', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
file_path: filePath,
|
||||||
|
new_file_name: newFileName
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error renaming checkpoint file:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
// Hide loading indicator
|
||||||
|
state.loadingManager.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -181,4 +181,40 @@ export async function fetchModelDescription(modelId, filePath) {
|
|||||||
console.error('Error fetching model description:', error);
|
console.error('Error fetching model description:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a LoRA file
|
||||||
|
* @param {string} filePath - Current file path
|
||||||
|
* @param {string} newFileName - New file name (without path)
|
||||||
|
* @returns {Promise<Object>} - Promise that resolves with the server response
|
||||||
|
*/
|
||||||
|
export async function renameLoraFile(filePath, newFileName) {
|
||||||
|
try {
|
||||||
|
// Show loading indicator
|
||||||
|
state.loadingManager.showSimpleLoading('Renaming LoRA file...');
|
||||||
|
|
||||||
|
const response = await fetch('/api/rename_lora', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
file_path: filePath,
|
||||||
|
new_file_name: newFileName
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Server returned ${response.status}: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error renaming LoRA file:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
// Hide loading indicator
|
||||||
|
state.loadingManager.hide();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
import { showToast } from '../../utils/uiHelpers.js';
|
import { showToast } from '../../utils/uiHelpers.js';
|
||||||
import { BASE_MODELS } from '../../utils/constants.js';
|
import { BASE_MODELS } from '../../utils/constants.js';
|
||||||
import { updateCheckpointCard } from '../../utils/cardUpdater.js';
|
import { updateCheckpointCard } from '../../utils/cardUpdater.js';
|
||||||
import { saveModelMetadata } from '../../api/checkpointApi.js';
|
import { saveModelMetadata, renameCheckpointFile } from '../../api/checkpointApi.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up model name editing functionality
|
* Set up model name editing functionality
|
||||||
@@ -419,19 +419,8 @@ export function setupFileNameEditing(filePath) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Use the passed filePath (which includes the original filename)
|
// Use the passed filePath (which includes the original filename)
|
||||||
// Call API to rename the file
|
// Call API to rename the file using the new function from checkpointApi.js
|
||||||
const response = await fetch('/api/rename_checkpoint', {
|
const result = await renameCheckpointFile(filePath, newFileName);
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
file_path: filePath, // Use the full original path
|
|
||||||
new_file_name: newFileName
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
showToast('File name updated successfully', 'success');
|
showToast('File name updated successfully', 'success');
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import { showToast } from '../../utils/uiHelpers.js';
|
import { showToast } from '../../utils/uiHelpers.js';
|
||||||
import { BASE_MODELS } from '../../utils/constants.js';
|
import { BASE_MODELS } from '../../utils/constants.js';
|
||||||
import { updateLoraCard } from '../../utils/cardUpdater.js';
|
import { updateLoraCard } from '../../utils/cardUpdater.js';
|
||||||
import { saveModelMetadata } from '../../api/loraApi.js';
|
import { saveModelMetadata, renameLoraFile } from '../../api/loraApi.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置模型名称编辑功能
|
* 设置模型名称编辑功能
|
||||||
@@ -459,19 +459,8 @@ export function setupFileNameEditing(filePath) {
|
|||||||
// Get the file path from the dataset
|
// Get the file path from the dataset
|
||||||
const filePath = this.dataset.filePath;
|
const filePath = this.dataset.filePath;
|
||||||
|
|
||||||
// Call API to rename the file
|
// Call API to rename the file using the new function from loraApi.js
|
||||||
const response = await fetch('/api/rename_lora', {
|
const result = await renameLoraFile(filePath, newFileName);
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
file_path: filePath,
|
|
||||||
new_file_name: newFileName
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
showToast('File name updated successfully', 'success');
|
showToast('File name updated successfully', 'success');
|
||||||
|
|||||||
Reference in New Issue
Block a user