mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
refactor: Replace direct model metadata API calls with unified model API client
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// AlphabetBar.js - Component for alphabet filtering
|
// AlphabetBar.js - Component for alphabet filtering
|
||||||
import { getCurrentPageState, setCurrentPageType } from '../../state/index.js';
|
import { getCurrentPageState } from '../../state/index.js';
|
||||||
import { getStorageItem, setStorageItem } from '../../utils/storageHelpers.js';
|
import { getStorageItem, setStorageItem } from '../../utils/storageHelpers.js';
|
||||||
import { resetAndReload } from '../../api/loraApi.js';
|
import { resetAndReload } from '../../api/loraApi.js';
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
import { appCore } from '../core.js';
|
import { appCore } from '../core.js';
|
||||||
import { getSessionItem, setSessionItem } from '../utils/storageHelpers.js';
|
import { getSessionItem, setSessionItem } from '../utils/storageHelpers.js';
|
||||||
import { state, getCurrentPageState } from '../state/index.js';
|
|
||||||
|
|
||||||
class InitializationManager {
|
class InitializationManager {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -4,9 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
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 { state } from '../../state/index.js';
|
|
||||||
import { saveModelMetadata as saveLoraMetadata, renameLoraFile } from '../../api/loraApi.js';
|
|
||||||
import { saveModelMetadata as saveCheckpointMetadata, renameCheckpointFile } from '../../api/checkpointApi.js';
|
|
||||||
import { getModelApiClient } from '../../api/baseModelApi.js';
|
import { getModelApiClient } from '../../api/baseModelApi.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ import {
|
|||||||
setupFileNameEditing
|
setupFileNameEditing
|
||||||
} from './ModelMetadata.js';
|
} from './ModelMetadata.js';
|
||||||
import { setupTagEditMode } from './ModelTags.js';
|
import { setupTagEditMode } from './ModelTags.js';
|
||||||
import { saveModelMetadata as saveLoraMetadata } from '../../api/loraApi.js';
|
import { getModelApiClient } from '../../api/baseModelApi.js';
|
||||||
import { saveModelMetadata as saveCheckpointMetadata } from '../../api/checkpointApi.js';
|
|
||||||
import { renderCompactTags, setupTagTooltip, formatFileSize } from './utils.js';
|
import { renderCompactTags, setupTagTooltip, formatFileSize } from './utils.js';
|
||||||
import { renderTriggerWords, setupTriggerWordsEditMode } from './TriggerWords.js';
|
import { renderTriggerWords, setupTriggerWordsEditMode } from './TriggerWords.js';
|
||||||
import { parsePresets, renderPresetTags } from './PresetTags.js';
|
import { parsePresets, renderPresetTags } from './PresetTags.js';
|
||||||
@@ -378,9 +377,7 @@ function setupLoraSpecificFields(filePath) {
|
|||||||
currentPresets[key] = parseFloat(value);
|
currentPresets[key] = parseFloat(value);
|
||||||
const newPresetsJson = JSON.stringify(currentPresets);
|
const newPresetsJson = JSON.stringify(currentPresets);
|
||||||
|
|
||||||
await saveLoraMetadata(filePath, {
|
await getModelApiClient().saveModelMetadata(filePath, { usage_tips: newPresetsJson });
|
||||||
usage_tips: newPresetsJson
|
|
||||||
});
|
|
||||||
|
|
||||||
presetTags.innerHTML = renderPresetTags(currentPresets);
|
presetTags.innerHTML = renderPresetTags(currentPresets);
|
||||||
|
|
||||||
@@ -406,8 +403,7 @@ function setupLoraSpecificFields(filePath) {
|
|||||||
async function saveNotes(filePath, modelType) {
|
async function saveNotes(filePath, modelType) {
|
||||||
const content = document.querySelector('.notes-content').textContent;
|
const content = document.querySelector('.notes-content').textContent;
|
||||||
try {
|
try {
|
||||||
const saveFunction = modelType === 'lora' ? saveLoraMetadata : saveCheckpointMetadata;
|
await getModelApiClient().saveModelMetadata(filePath, { notes: content });
|
||||||
await saveFunction(filePath, { notes: content });
|
|
||||||
|
|
||||||
showToast('Notes saved successfully', 'success');
|
showToast('Notes saved successfully', 'success');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -3,9 +3,7 @@
|
|||||||
* Module for handling model tag editing functionality - 共享版本
|
* Module for handling model tag editing functionality - 共享版本
|
||||||
*/
|
*/
|
||||||
import { showToast } from '../../utils/uiHelpers.js';
|
import { showToast } from '../../utils/uiHelpers.js';
|
||||||
import { saveModelMetadata as saveLoraMetadata } from '../../api/loraApi.js';
|
import { getModelApiClient } from '../../api/baseModelApi.js';
|
||||||
import { saveModelMetadata as saveCheckpointMetadata } from '../../api/checkpointApi.js';
|
|
||||||
import { state } from '../../state/index.js';
|
|
||||||
|
|
||||||
// Preset tag suggestions
|
// Preset tag suggestions
|
||||||
const PRESET_TAGS = [
|
const PRESET_TAGS = [
|
||||||
@@ -165,10 +163,8 @@ async function saveTags() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const saveFunction = state.currentPageType === 'checkpoints' ? saveCheckpointMetadata : saveLoraMetadata;
|
|
||||||
|
|
||||||
// Save tags metadata
|
// Save tags metadata
|
||||||
await saveFunction(filePath, { tags: tags });
|
await getModelApiClient().saveModelMetadata(filePath, { tags: tags });
|
||||||
|
|
||||||
// Set flag to skip restoring original tags when exiting edit mode
|
// Set flag to skip restoring original tags when exiting edit mode
|
||||||
editBtn.dataset.skipRestore = "true";
|
editBtn.dataset.skipRestore = "true";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* PresetTags.js
|
* PresetTags.js
|
||||||
* Handles LoRA model preset parameter tags - Shared version
|
* Handles LoRA model preset parameter tags - Shared version
|
||||||
*/
|
*/
|
||||||
import { saveModelMetadata } from '../../api/loraApi.js';
|
import { getModelApiClient } from '../../api/baseModelApi.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse preset parameters
|
* Parse preset parameters
|
||||||
@@ -58,7 +58,7 @@ window.removePreset = async function(key) {
|
|||||||
delete currentPresets[key];
|
delete currentPresets[key];
|
||||||
const newPresetsJson = JSON.stringify(currentPresets);
|
const newPresetsJson = JSON.stringify(currentPresets);
|
||||||
|
|
||||||
await saveModelMetadata(filePath, {
|
await getModelApiClient().saveModelMetadata(filePath, {
|
||||||
usage_tips: newPresetsJson
|
usage_tips: newPresetsJson
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* Moved to shared directory for consistency
|
* Moved to shared directory for consistency
|
||||||
*/
|
*/
|
||||||
import { showToast, copyToClipboard } from '../../utils/uiHelpers.js';
|
import { showToast, copyToClipboard } from '../../utils/uiHelpers.js';
|
||||||
import { saveModelMetadata } from '../../api/loraApi.js';
|
import { getModelApiClient } from '../../api/baseModelApi.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch trained words for a model
|
* Fetch trained words for a model
|
||||||
@@ -610,7 +610,7 @@ async function saveTriggerWords() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Special format for updating nested civitai.trainedWords
|
// Special format for updating nested civitai.trainedWords
|
||||||
await saveModelMetadata(filePath, {
|
await getModelApiClient().saveModelMetadata(filePath, {
|
||||||
civitai: { trainedWords: words }
|
civitai: { trainedWords: words }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user