refactor: unify API client usage across models and remove deprecated API files

This commit is contained in:
Will Miao
2025-07-25 21:38:54 +08:00
parent c5a3af2399
commit 1a3751acfa
11 changed files with 26 additions and 173 deletions

View File

@@ -26,7 +26,7 @@ export const MODEL_CONFIG = {
[MODEL_TYPES.CHECKPOINT]: {
displayName: 'Checkpoint',
singularName: 'checkpoint',
defaultPageSize: 50,
defaultPageSize: 100,
supportsLetterFilter: false,
supportsBulkOperations: true,
supportsMove: false,

View File

@@ -1,39 +0,0 @@
import { createModelApiClient } from './baseModelApi.js';
import { MODEL_TYPES } from './apiConfig.js';
// Create Checkpoint-specific API client
const checkpointApiClient = createModelApiClient(MODEL_TYPES.CHECKPOINT);
// Export all common operations using the unified client
export const deleteModel = (filePath) => checkpointApiClient.deleteModel(filePath);
export const excludeCheckpoint = (filePath) => checkpointApiClient.excludeModel(filePath);
export const renameCheckpointFile = (filePath, newFileName) => checkpointApiClient.renameModelFile(filePath, newFileName);
export const replacePreview = (filePath) => checkpointApiClient.replaceModelPreview(filePath);
export const saveModelMetadata = (filePath, data) => checkpointApiClient.saveModelMetadata(filePath, data);
export const refreshCheckpoints = (fullRebuild = false) => checkpointApiClient.refreshModels(fullRebuild);
export const refreshSingleCheckpointMetadata = (filePath) => checkpointApiClient.refreshSingleModelMetadata(filePath);
export const fetchCivitai = () => checkpointApiClient.fetchCivitaiMetadata();
// Pagination functions
export const fetchCheckpointsPage = (page = 1, pageSize = 50) => checkpointApiClient.fetchModelsPage(page, pageSize);
// Virtual scrolling operations
export async function loadMoreCheckpoints(resetPage = false, updateFolders = false) {
return checkpointApiClient.loadMoreWithVirtualScroll(resetPage, updateFolders);
}
// Checkpoint-specific functions
export async function getCheckpointInfo(name) {
try {
const response = await fetch(`${checkpointApiClient.apiConfig.endpoints.specific.info}/${encodeURIComponent(name)}`);
if (!response.ok) {
throw new Error(`Failed to fetch checkpoint info: ${response.statusText}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching checkpoint info:', error);
throw error;
}
}

View File

@@ -1,84 +0,0 @@
import { createModelApiClient } from './baseModelApi.js';
import { MODEL_TYPES } from './apiConfig.js';
// Create LoRA-specific API client
const loraApiClient = createModelApiClient(MODEL_TYPES.LORA);
// Export all common operations using the unified client
export const deleteModel = (filePath) => loraApiClient.deleteModel(filePath);
export const excludeLora = (filePath) => loraApiClient.excludeModel(filePath);
export const renameLoraFile = (filePath, newFileName) => loraApiClient.renameModelFile(filePath, newFileName);
export const replacePreview = (filePath) => loraApiClient.replaceModelPreview(filePath);
export const saveModelMetadata = (filePath, data) => loraApiClient.saveModelMetadata(filePath, data);
export const refreshLoras = (fullRebuild = false) => loraApiClient.refreshModels(fullRebuild);
export const refreshSingleLoraMetadata = (filePath) => loraApiClient.refreshSingleModelMetadata(filePath);
export const fetchCivitai = () => loraApiClient.fetchCivitaiMetadata();
// Pagination functions
export const fetchLorasPage = (page = 1, pageSize = 100) => loraApiClient.fetchModelsPage(page, pageSize);
// Virtual scrolling operations
export async function loadMoreLoras(resetPage = false, updateFolders = false) {
return loraApiClient.loadMoreWithVirtualScroll(resetPage, updateFolders);
}
// LoRA-specific functions that don't have common equivalents
export async function fetchModelDescription(modelId, filePath) {
try {
const response = await fetch(`${loraApiClient.apiConfig.endpoints.specific.modelDescription}?model_id=${modelId}&file_path=${encodeURIComponent(filePath)}`);
if (!response.ok) {
throw new Error(`Failed to fetch model description: ${response.statusText}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching model description:', error);
throw error;
}
}
// Move operations (LoRA-specific)
export async function moveModel(filePath, targetPath) {
try {
const response = await fetch(loraApiClient.apiConfig.endpoints.specific.moveModel, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
file_path: filePath,
target_path: targetPath
})
});
if (!response.ok) {
throw new Error('Failed to move model');
}
return await response.json();
} catch (error) {
console.error('Error moving model:', error);
throw error;
}
}
export async function moveModelsBulk(filePaths, targetPath) {
try {
const response = await fetch(loraApiClient.apiConfig.endpoints.specific.moveBulk, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
file_paths: filePaths,
target_path: targetPath
})
});
if (!response.ok) {
throw new Error('Failed to move models');
}
return await response.json();
} catch (error) {
console.error('Error moving models in bulk:', error);
throw error;
}
}