mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 14:42:11 -03:00
Refactor API and DownloadManager to utilize version-level properties for model file existence and size, improving data handling and UI responsiveness.
This commit is contained in:
@@ -529,12 +529,23 @@ class ApiRoutes:
|
|||||||
|
|
||||||
# Check local availability for each version
|
# Check local availability for each version
|
||||||
for version in versions:
|
for version in versions:
|
||||||
for file in version.get('files', []):
|
# Find the model file (type="Model") in the files list
|
||||||
sha256 = file.get('hashes', {}).get('SHA256')
|
model_file = next((file for file in version.get('files', [])
|
||||||
|
if file.get('type') == 'Model'), None)
|
||||||
|
|
||||||
|
if model_file:
|
||||||
|
sha256 = model_file.get('hashes', {}).get('SHA256')
|
||||||
if sha256:
|
if sha256:
|
||||||
file['existsLocally'] = self.scanner.has_lora_hash(sha256)
|
# Set existsLocally and localPath at the version level
|
||||||
if file['existsLocally']:
|
version['existsLocally'] = self.scanner.has_lora_hash(sha256)
|
||||||
file['localPath'] = self.scanner.get_lora_path_by_hash(sha256)
|
if version['existsLocally']:
|
||||||
|
version['localPath'] = self.scanner.get_lora_path_by_hash(sha256)
|
||||||
|
|
||||||
|
# Also set the model file size at the version level for easier access
|
||||||
|
version['modelSizeKB'] = model_file.get('sizeKB')
|
||||||
|
else:
|
||||||
|
# No model file found in this version
|
||||||
|
version['existsLocally'] = False
|
||||||
|
|
||||||
return web.json_response(versions)
|
return web.json_response(versions)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -120,16 +120,21 @@ export class DownloadManager {
|
|||||||
versionList.innerHTML = this.versions.map(version => {
|
versionList.innerHTML = this.versions.map(version => {
|
||||||
const firstImage = version.images?.find(img => !img.url.endsWith('.mp4'));
|
const firstImage = version.images?.find(img => !img.url.endsWith('.mp4'));
|
||||||
const thumbnailUrl = firstImage ? firstImage.url : '/loras_static/images/no-preview.png';
|
const thumbnailUrl = firstImage ? firstImage.url : '/loras_static/images/no-preview.png';
|
||||||
const fileSize = (version.files[0]?.sizeKB / 1024).toFixed(2);
|
|
||||||
|
|
||||||
const existsLocally = version.files[0]?.existsLocally;
|
// Use version-level size or fallback to first file
|
||||||
const localPath = version.files[0]?.localPath;
|
const fileSize = version.modelSizeKB ?
|
||||||
|
(version.modelSizeKB / 1024).toFixed(2) :
|
||||||
|
(version.files[0]?.sizeKB / 1024).toFixed(2);
|
||||||
|
|
||||||
|
// Use version-level existsLocally flag
|
||||||
|
const existsLocally = version.existsLocally;
|
||||||
|
const localPath = version.localPath;
|
||||||
|
|
||||||
// 更新本地状态指示器为badge样式
|
// 更新本地状态指示器为badge样式
|
||||||
const localStatus = existsLocally ?
|
const localStatus = existsLocally ?
|
||||||
`<div class="local-badge">
|
`<div class="local-badge">
|
||||||
<i class="fas fa-check"></i> In Library
|
<i class="fas fa-check"></i> In Library
|
||||||
<div class="local-path">${localPath}</div>
|
<div class="local-path">${localPath || ''}</div>
|
||||||
</div>` : '';
|
</div>` : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
@@ -177,12 +182,12 @@ export class DownloadManager {
|
|||||||
this.updateNextButtonState();
|
this.updateNextButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new method to update Next button state
|
// Update this method to use version-level existsLocally
|
||||||
updateNextButtonState() {
|
updateNextButtonState() {
|
||||||
const nextButton = document.querySelector('#versionStep .primary-btn');
|
const nextButton = document.querySelector('#versionStep .primary-btn');
|
||||||
if (!nextButton) return;
|
if (!nextButton) return;
|
||||||
|
|
||||||
const existsLocally = this.currentVersion?.files[0]?.existsLocally;
|
const existsLocally = this.currentVersion?.existsLocally;
|
||||||
|
|
||||||
if (existsLocally) {
|
if (existsLocally) {
|
||||||
nextButton.disabled = true;
|
nextButton.disabled = true;
|
||||||
@@ -202,7 +207,7 @@ export class DownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Double-check if the version exists locally
|
// Double-check if the version exists locally
|
||||||
const existsLocally = this.currentVersion.files[0]?.existsLocally;
|
const existsLocally = this.currentVersion.existsLocally;
|
||||||
if (existsLocally) {
|
if (existsLocally) {
|
||||||
showToast('This version already exists in your library', 'info');
|
showToast('This version already exists in your library', 'info');
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user