mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 14:42:11 -03:00
refactor: consolidate save model metadata functionality across APIs
This commit is contained in:
@@ -62,8 +62,13 @@ export async function refreshSingleCheckpointMetadata(filePath) {
|
|||||||
return refreshSingleModelMetadata(filePath, 'checkpoint');
|
return refreshSingleModelMetadata(filePath, 'checkpoint');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save checkpoint metadata (similar to the Lora version)
|
/**
|
||||||
export async function saveCheckpointMetadata(filePath, data) {
|
* Save model metadata to the server
|
||||||
|
* @param {string} filePath - Path to the model file
|
||||||
|
* @param {Object} data - Metadata to save
|
||||||
|
* @returns {Promise} - Promise that resolves with the server response
|
||||||
|
*/
|
||||||
|
export async function saveModelMetadata(filePath, data) {
|
||||||
const response = await fetch('/api/checkpoints/save-metadata', {
|
const response = await fetch('/api/checkpoints/save-metadata', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -79,5 +84,5 @@ export async function saveCheckpointMetadata(filePath, data) {
|
|||||||
throw new Error('Failed to save metadata');
|
throw new Error('Failed to save metadata');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,31 @@ import {
|
|||||||
refreshSingleModelMetadata
|
refreshSingleModelMetadata
|
||||||
} from './baseModelApi.js';
|
} from './baseModelApi.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save model metadata to the server
|
||||||
|
* @param {string} filePath - File path
|
||||||
|
* @param {Object} data - Data to save
|
||||||
|
* @returns {Promise} Promise of the save operation
|
||||||
|
*/
|
||||||
|
export async function saveModelMetadata(filePath, data) {
|
||||||
|
const response = await fetch('/api/loras/save-metadata', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
file_path: filePath,
|
||||||
|
...data
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to save metadata');
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
export async function loadMoreLoras(resetPage = false, updateFolders = false) {
|
export async function loadMoreLoras(resetPage = false, updateFolders = false) {
|
||||||
return loadMoreModels({
|
return loadMoreModels({
|
||||||
resetPage,
|
resetPage,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BaseContextMenu } from './BaseContextMenu.js';
|
import { BaseContextMenu } from './BaseContextMenu.js';
|
||||||
import { refreshSingleCheckpointMetadata, saveCheckpointMetadata } from '../../api/checkpointApi.js';
|
import { refreshSingleCheckpointMetadata, saveModelMetadata } from '../../api/checkpointApi.js';
|
||||||
import { showToast, getNSFWLevelName } from '../../utils/uiHelpers.js';
|
import { showToast, getNSFWLevelName } from '../../utils/uiHelpers.js';
|
||||||
import { NSFW_LEVELS } from '../../utils/constants.js';
|
import { NSFW_LEVELS } from '../../utils/constants.js';
|
||||||
import { getStorageItem } from '../../utils/storageHelpers.js';
|
import { getStorageItem } from '../../utils/storageHelpers.js';
|
||||||
@@ -82,7 +82,7 @@ export class CheckpointContextMenu extends BaseContextMenu {
|
|||||||
if (!filePath) return;
|
if (!filePath) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await saveCheckpointMetadata(filePath, { preview_nsfw_level: level });
|
await saveModelMetadata(filePath, { preview_nsfw_level: level });
|
||||||
|
|
||||||
// Update card data
|
// Update card data
|
||||||
const card = document.querySelector(`.lora-card[data-filepath="${filePath}"]`);
|
const card = document.querySelector(`.lora-card[data-filepath="${filePath}"]`);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { BaseContextMenu } from './BaseContextMenu.js';
|
import { BaseContextMenu } from './BaseContextMenu.js';
|
||||||
import { refreshSingleLoraMetadata } from '../../api/loraApi.js';
|
import { refreshSingleLoraMetadata, saveModelMetadata } from '../../api/loraApi.js';
|
||||||
import { showToast, getNSFWLevelName } from '../../utils/uiHelpers.js';
|
import { showToast, getNSFWLevelName } from '../../utils/uiHelpers.js';
|
||||||
import { NSFW_LEVELS } from '../../utils/constants.js';
|
import { NSFW_LEVELS } from '../../utils/constants.js';
|
||||||
import { getStorageItem } from '../../utils/storageHelpers.js';
|
import { getStorageItem } from '../../utils/storageHelpers.js';
|
||||||
@@ -111,22 +111,7 @@ export class LoraContextMenu extends BaseContextMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async saveModelMetadata(filePath, data) {
|
async saveModelMetadata(filePath, data) {
|
||||||
const response = await fetch('/api/loras/save-metadata', {
|
return saveModelMetadata(filePath, data);
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
file_path: filePath,
|
|
||||||
...data
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to save metadata');
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCardBlurEffect(card, level) {
|
updateCardBlurEffect(card, level) {
|
||||||
|
|||||||
@@ -5,31 +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';
|
||||||
/**
|
|
||||||
* Save model metadata to the server
|
|
||||||
* @param {string} filePath - Path to the model file
|
|
||||||
* @param {Object} data - Metadata to save
|
|
||||||
* @returns {Promise} - Promise that resolves with the server response
|
|
||||||
*/
|
|
||||||
export async function saveModelMetadata(filePath, data) {
|
|
||||||
const response = await fetch('/api/checkpoints/save-metadata', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
file_path: filePath,
|
|
||||||
...data
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to save metadata');
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up model name editing functionality
|
* Set up model name editing functionality
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import { setupTabSwitching, loadModelDescription } from './ModelDescription.js';
|
|||||||
import {
|
import {
|
||||||
setupModelNameEditing,
|
setupModelNameEditing,
|
||||||
setupBaseModelEditing,
|
setupBaseModelEditing,
|
||||||
setupFileNameEditing,
|
setupFileNameEditing
|
||||||
saveModelMetadata
|
|
||||||
} from './ModelMetadata.js';
|
} from './ModelMetadata.js';
|
||||||
|
import { saveModelMetadata } from '../../api/checkpointApi.js';
|
||||||
import { renderCompactTags, setupTagTooltip, formatFileSize } from './utils.js';
|
import { renderCompactTags, setupTagTooltip, formatFileSize } from './utils.js';
|
||||||
import { updateCheckpointCard } from '../../utils/cardUpdater.js';
|
import { updateCheckpointCard } from '../../utils/cardUpdater.js';
|
||||||
|
|
||||||
|
|||||||
@@ -5,31 +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';
|
||||||
/**
|
|
||||||
* 保存模型元数据到服务器
|
|
||||||
* @param {string} filePath - 文件路径
|
|
||||||
* @param {Object} data - 要保存的数据
|
|
||||||
* @returns {Promise} 保存操作的Promise
|
|
||||||
*/
|
|
||||||
export async function saveModelMetadata(filePath, data) {
|
|
||||||
const response = await fetch('/api/loras/save-metadata', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
file_path: filePath,
|
|
||||||
...data
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to save metadata');
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置模型名称编辑功能
|
* 设置模型名称编辑功能
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
* PresetTags.js
|
* PresetTags.js
|
||||||
* 处理LoRA模型预设参数标签相关的功能模块
|
* 处理LoRA模型预设参数标签相关的功能模块
|
||||||
*/
|
*/
|
||||||
import { saveModelMetadata } from './ModelMetadata.js';
|
import { saveModelMetadata } from '../../api/loraApi.js';
|
||||||
import { showToast } from '../../utils/uiHelpers.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析预设参数
|
* 解析预设参数
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* 处理LoRA模型触发词相关的功能模块
|
* 处理LoRA模型触发词相关的功能模块
|
||||||
*/
|
*/
|
||||||
import { showToast, copyToClipboard } from '../../utils/uiHelpers.js';
|
import { showToast, copyToClipboard } from '../../utils/uiHelpers.js';
|
||||||
import { saveModelMetadata } from './ModelMetadata.js';
|
import { saveModelMetadata } from '../../api/loraApi.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染触发词
|
* 渲染触发词
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import { loadRecipesForLora } from './RecipeTab.js'; // Add import for recipe ta
|
|||||||
import {
|
import {
|
||||||
setupModelNameEditing,
|
setupModelNameEditing,
|
||||||
setupBaseModelEditing,
|
setupBaseModelEditing,
|
||||||
setupFileNameEditing,
|
setupFileNameEditing
|
||||||
saveModelMetadata
|
|
||||||
} from './ModelMetadata.js';
|
} from './ModelMetadata.js';
|
||||||
|
import { saveModelMetadata } from '../../api/loraApi.js';
|
||||||
import { renderCompactTags, setupTagTooltip, formatFileSize } from './utils.js';
|
import { renderCompactTags, setupTagTooltip, formatFileSize } from './utils.js';
|
||||||
import { updateLoraCard } from '../../utils/cardUpdater.js';
|
import { updateLoraCard } from '../../utils/cardUpdater.js';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user