mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 15:15:44 -03:00
feat(download): download to current version's directory in versions tab
Instead of always using default paths, downloads from the model versions tab now target the same directory as the current in-library version. Falls back silently to default paths if the current version path cannot be resolved.
This commit is contained in:
@@ -1091,6 +1091,56 @@ export function initVersionsTab({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resolveDownloadPathFromCurrentVersion() {
|
||||||
|
if (!normalizedCurrentVersionId || !controller.record?.versions) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentVersion = controller.record.versions.find(
|
||||||
|
v => v.versionId === normalizedCurrentVersionId && v.isInLibrary && v.filePath
|
||||||
|
);
|
||||||
|
if (!currentVersion?.filePath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const client = ensureClient();
|
||||||
|
const rootsData = await client.fetchModelRoots();
|
||||||
|
const roots = rootsData?.roots;
|
||||||
|
if (!Array.isArray(roots) || roots.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedFilePath = currentVersion.filePath.replace(/\\/g, '/');
|
||||||
|
let matchedRoot = null;
|
||||||
|
let relativePath = null;
|
||||||
|
|
||||||
|
for (const root of roots) {
|
||||||
|
const normalizedRoot = root.replace(/\\/g, '/');
|
||||||
|
if (normalizedFilePath.startsWith(normalizedRoot)) {
|
||||||
|
matchedRoot = root;
|
||||||
|
relativePath = normalizedFilePath.slice(normalizedRoot.length);
|
||||||
|
if (relativePath.startsWith('/')) {
|
||||||
|
relativePath = relativePath.slice(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matchedRoot || !relativePath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastSlash = relativePath.lastIndexOf('/');
|
||||||
|
const targetFolder = lastSlash > 0 ? relativePath.slice(0, lastSlash) : '';
|
||||||
|
|
||||||
|
return { modelRoot: matchedRoot, targetFolder };
|
||||||
|
} catch (error) {
|
||||||
|
console.debug('Failed to resolve download path from current version:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleDownloadVersion(button, versionId) {
|
async function handleDownloadVersion(button, versionId) {
|
||||||
if (!controller.record) {
|
if (!controller.record) {
|
||||||
return;
|
return;
|
||||||
@@ -1105,8 +1155,11 @@ export function initVersionsTab({
|
|||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const pathInfo = await resolveDownloadPathFromCurrentVersion();
|
||||||
const success = await downloadManager.downloadVersionWithDefaults(modelType, modelId, versionId, {
|
const success = await downloadManager.downloadVersionWithDefaults(modelType, modelId, versionId, {
|
||||||
versionName: version.name || `#${version.versionId}`,
|
versionName: version.name || `#${version.versionId}`,
|
||||||
|
modelRoot: pathInfo?.modelRoot || '',
|
||||||
|
targetFolder: pathInfo?.targetFolder || '',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|||||||
@@ -620,7 +620,12 @@ export class DownloadManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadVersionWithDefaults(modelType, modelId, versionId, { versionName = '', source = null } = {}) {
|
async downloadVersionWithDefaults(modelType, modelId, versionId, {
|
||||||
|
versionName = '',
|
||||||
|
source = null,
|
||||||
|
modelRoot = '',
|
||||||
|
targetFolder = ''
|
||||||
|
} = {}) {
|
||||||
try {
|
try {
|
||||||
this.apiClient = getModelApiClient(modelType);
|
this.apiClient = getModelApiClient(modelType);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -630,13 +635,14 @@ export class DownloadManager {
|
|||||||
this.modelId = modelId ? modelId.toString() : null;
|
this.modelId = modelId ? modelId.toString() : null;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
|
||||||
|
const useDefaultPaths = !modelRoot;
|
||||||
return this.executeDownloadWithProgress({
|
return this.executeDownloadWithProgress({
|
||||||
modelId,
|
modelId,
|
||||||
versionId,
|
versionId,
|
||||||
versionName,
|
versionName,
|
||||||
modelRoot: '',
|
modelRoot: modelRoot || '',
|
||||||
targetFolder: '',
|
targetFolder: targetFolder || '',
|
||||||
useDefaultPaths: true,
|
useDefaultPaths,
|
||||||
source,
|
source,
|
||||||
closeModal: false,
|
closeModal: false,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user