fix: update model_id and model_version_id handling across various services for improved flexibility

This commit is contained in:
Will Miao
2025-08-11 15:31:49 +08:00
parent b03420faac
commit 96517cbdef
7 changed files with 126 additions and 93 deletions

View File

@@ -17,16 +17,16 @@ export function createModelApiClient(modelType) {
}
}
let _singletonClient = null;
let _singletonClients = new Map();
export function getModelApiClient() {
const currentType = state.currentPageType;
export function getModelApiClient(modelType = null) {
const targetType = modelType || state.currentPageType;
if (!_singletonClient || _singletonClient.modelType !== currentType) {
_singletonClient = createModelApiClient(currentType);
if (!_singletonClients.has(targetType)) {
_singletonClients.set(targetType, createModelApiClient(targetType));
}
return _singletonClient;
return _singletonClients.get(targetType);
}
export function resetAndReload(updateFolders = false) {

View File

@@ -1,4 +1,6 @@
import { showToast } from '../../utils/uiHelpers.js';
import { getModelApiClient } from '../../api/modelApiFactory.js';
import { MODEL_TYPES } from '../../api/apiConfig.js';
export class DownloadManager {
constructor(importManager) {
@@ -199,39 +201,27 @@ export class DownloadManager {
updateProgress(0, completedDownloads, lora.name);
try {
console.log(`lora:`, lora);
// Download the LoRA with download ID
const response = await fetch('/api/download-model', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model_id: lora.modelId,
model_version_id: lora.id,
model_root: loraRoot,
relative_path: targetPath.replace(loraRoot + '/', ''),
download_id: batchDownloadId
})
});
const response = await getModelApiClient(MODEL_TYPES.LORA).downloadModel(
lora.modelId,
lora.modelVersionId,
loraRoot,
targetPath.replace(loraRoot + '/', ''),
batchDownloadId
);
if (!response.ok) {
const errorText = await response.text();
console.error(`Failed to download LoRA ${lora.name}: ${errorText}`);
// Check if this is an early access error (status 401 is the key indicator)
if (response.status === 401) {
accessFailures++;
this.importManager.loadingManager.setStatus(
`Failed to download ${lora.name}: Access restricted`
);
}
if (!response.success) {
console.error(`Failed to download LoRA ${lora.name}: ${response.error}`);
failedDownloads++;
// Continue with next download
} else {
completedDownloads++;
// Update progress to show completion of current LoRA
updateProgress(100, completedDownloads, '');
if (completedDownloads + failedDownloads < this.importManager.downloadableLoRAs.length) {
this.importManager.loadingManager.setStatus(
`Completed ${completedDownloads}/${this.importManager.downloadableLoRAs.length} LoRAs. Starting next download...`