refactor: Replace direct model metadata API calls with unified model API client

This commit is contained in:
Will Miao
2025-07-25 15:35:16 +08:00
parent 08265a85ec
commit a7d9255c2c
7 changed files with 10 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
// 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 { resetAndReload } from '../../api/loraApi.js';

View File

@@ -4,7 +4,6 @@
*/
import { appCore } from '../core.js';
import { getSessionItem, setSessionItem } from '../utils/storageHelpers.js';
import { state, getCurrentPageState } from '../state/index.js';
class InitializationManager {
constructor() {

View File

@@ -4,9 +4,6 @@
*/
import { showToast } from '../../utils/uiHelpers.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';
/**

View File

@@ -13,8 +13,7 @@ import {
setupFileNameEditing
} from './ModelMetadata.js';
import { setupTagEditMode } from './ModelTags.js';
import { saveModelMetadata as saveLoraMetadata } from '../../api/loraApi.js';
import { saveModelMetadata as saveCheckpointMetadata } from '../../api/checkpointApi.js';
import { getModelApiClient } from '../../api/baseModelApi.js';
import { renderCompactTags, setupTagTooltip, formatFileSize } from './utils.js';
import { renderTriggerWords, setupTriggerWordsEditMode } from './TriggerWords.js';
import { parsePresets, renderPresetTags } from './PresetTags.js';
@@ -378,9 +377,7 @@ function setupLoraSpecificFields(filePath) {
currentPresets[key] = parseFloat(value);
const newPresetsJson = JSON.stringify(currentPresets);
await saveLoraMetadata(filePath, {
usage_tips: newPresetsJson
});
await getModelApiClient().saveModelMetadata(filePath, { usage_tips: newPresetsJson });
presetTags.innerHTML = renderPresetTags(currentPresets);
@@ -406,8 +403,7 @@ function setupLoraSpecificFields(filePath) {
async function saveNotes(filePath, modelType) {
const content = document.querySelector('.notes-content').textContent;
try {
const saveFunction = modelType === 'lora' ? saveLoraMetadata : saveCheckpointMetadata;
await saveFunction(filePath, { notes: content });
await getModelApiClient().saveModelMetadata(filePath, { notes: content });
showToast('Notes saved successfully', 'success');
} catch (error) {

View File

@@ -3,9 +3,7 @@
* Module for handling model tag editing functionality - 共享版本
*/
import { showToast } from '../../utils/uiHelpers.js';
import { saveModelMetadata as saveLoraMetadata } from '../../api/loraApi.js';
import { saveModelMetadata as saveCheckpointMetadata } from '../../api/checkpointApi.js';
import { state } from '../../state/index.js';
import { getModelApiClient } from '../../api/baseModelApi.js';
// Preset tag suggestions
const PRESET_TAGS = [
@@ -165,10 +163,8 @@ async function saveTags() {
}
try {
const saveFunction = state.currentPageType === 'checkpoints' ? saveCheckpointMetadata : saveLoraMetadata;
// 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
editBtn.dataset.skipRestore = "true";

View File

@@ -2,7 +2,7 @@
* PresetTags.js
* Handles LoRA model preset parameter tags - Shared version
*/
import { saveModelMetadata } from '../../api/loraApi.js';
import { getModelApiClient } from '../../api/baseModelApi.js';
/**
* Parse preset parameters
@@ -58,7 +58,7 @@ window.removePreset = async function(key) {
delete currentPresets[key];
const newPresetsJson = JSON.stringify(currentPresets);
await saveModelMetadata(filePath, {
await getModelApiClient().saveModelMetadata(filePath, {
usage_tips: newPresetsJson
});

View File

@@ -4,7 +4,7 @@
* Moved to shared directory for consistency
*/
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
@@ -610,7 +610,7 @@ async function saveTriggerWords() {
try {
// Special format for updating nested civitai.trainedWords
await saveModelMetadata(filePath, {
await getModelApiClient().saveModelMetadata(filePath, {
civitai: { trainedWords: words }
});