Add rename functionality for checkpoint and LoRA files with loading indicators

This commit is contained in:
Will Miao
2025-05-30 16:38:18 +08:00
parent cbb25b4ac0
commit 8063cee3cd
4 changed files with 78 additions and 28 deletions

View File

@@ -153,4 +153,40 @@ export async function saveModelMetadata(filePath, data) {
*/
export function excludeCheckpoint(filePath) {
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();
}
}

View File

@@ -181,4 +181,40 @@ export async function fetchModelDescription(modelId, filePath) {
console.error('Error fetching model description:', 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();
}
}

View File

@@ -5,7 +5,7 @@
import { showToast } from '../../utils/uiHelpers.js';
import { BASE_MODELS } from '../../utils/constants.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
@@ -419,19 +419,8 @@ export function setupFileNameEditing(filePath) {
try {
// Use the passed filePath (which includes the original filename)
// Call API to rename the file
const response = await fetch('/api/rename_checkpoint', {
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();
// Call API to rename the file using the new function from checkpointApi.js
const result = await renameCheckpointFile(filePath, newFileName);
if (result.success) {
showToast('File name updated successfully', 'success');

View File

@@ -5,7 +5,7 @@
import { showToast } from '../../utils/uiHelpers.js';
import { BASE_MODELS } from '../../utils/constants.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
const filePath = this.dataset.filePath;
// Call API to rename the 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
})
});
const result = await response.json();
// Call API to rename the file using the new function from loraApi.js
const result = await renameLoraFile(filePath, newFileName);
if (result.success) {
showToast('File name updated successfully', 'success');