mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-26 15:38:52 -03:00
Refactor logging and update badge visibility in UpdateService; improve path normalization in file_utils
This commit is contained in:
@@ -25,7 +25,6 @@ class TriggerWordToggle:
|
|||||||
FUNCTION = "process_trigger_words"
|
FUNCTION = "process_trigger_words"
|
||||||
|
|
||||||
def process_trigger_words(self, id, group_mode, **kwargs):
|
def process_trigger_words(self, id, group_mode, **kwargs):
|
||||||
print("process_trigger_words kwargs: ", kwargs)
|
|
||||||
trigger_words = kwargs.get("trigger_words", "")
|
trigger_words = kwargs.get("trigger_words", "")
|
||||||
# Send trigger words to frontend
|
# Send trigger words to frontend
|
||||||
PromptServer.instance.send_sync("trigger_word_update", {
|
PromptServer.instance.send_sync("trigger_word_update", {
|
||||||
|
|||||||
@@ -177,8 +177,6 @@ class CivitaiClient:
|
|||||||
headers = self._get_request_headers()
|
headers = self._get_request_headers()
|
||||||
url = f"{self.base_url}/models/{model_id}"
|
url = f"{self.base_url}/models/{model_id}"
|
||||||
|
|
||||||
logger.info(f"Fetching model metadata from {url}")
|
|
||||||
|
|
||||||
async with session.get(url, headers=headers) as response:
|
async with session.get(url, headers=headers) as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
logger.warning(f"Failed to fetch model metadata: Status {response.status}")
|
logger.warning(f"Failed to fetch model metadata: Status {response.status}")
|
||||||
@@ -193,7 +191,6 @@ class CivitaiClient:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if metadata["description"] or metadata["tags"]:
|
if metadata["description"] or metadata["tags"]:
|
||||||
logger.info(f"Successfully retrieved metadata for model {model_id}")
|
|
||||||
return metadata
|
return metadata
|
||||||
else:
|
else:
|
||||||
logger.warning(f"No metadata found for model {model_id}")
|
logger.warning(f"No metadata found for model {model_id}")
|
||||||
|
|||||||
@@ -106,8 +106,11 @@ async def load_metadata(file_path: str) -> Optional[LoraMetadata]:
|
|||||||
|
|
||||||
needs_update = False
|
needs_update = False
|
||||||
|
|
||||||
if data['file_path'] != normalize_path(data['file_path']):
|
# Compare paths without extensions
|
||||||
data['file_path'] = normalize_path(data['file_path'])
|
stored_path_base = os.path.splitext(data['file_path'])[0]
|
||||||
|
current_path_base = os.path.splitext(normalize_path(file_path))[0]
|
||||||
|
if stored_path_base != current_path_base:
|
||||||
|
data['file_path'] = normalize_path(file_path)
|
||||||
needs_update = True
|
needs_update = True
|
||||||
|
|
||||||
preview_url = data.get('preview_url', '')
|
preview_url = data.get('preview_url', '')
|
||||||
@@ -118,11 +121,15 @@ async def load_metadata(file_path: str) -> Optional[LoraMetadata]:
|
|||||||
if new_preview_url != preview_url:
|
if new_preview_url != preview_url:
|
||||||
data['preview_url'] = new_preview_url
|
data['preview_url'] = new_preview_url
|
||||||
needs_update = True
|
needs_update = True
|
||||||
elif preview_url != normalize_path(preview_url):
|
else:
|
||||||
|
# Compare preview paths without extensions
|
||||||
|
stored_preview_base = os.path.splitext(preview_url)[0]
|
||||||
|
current_preview_base = os.path.splitext(normalize_path(preview_url))[0]
|
||||||
|
if stored_preview_base != current_preview_base:
|
||||||
data['preview_url'] = normalize_path(preview_url)
|
data['preview_url'] = normalize_path(preview_url)
|
||||||
needs_update = True
|
needs_update = True
|
||||||
|
|
||||||
# Ensure all fields are present, due to updates adding new fields
|
# Ensure all fields are present
|
||||||
if 'tags' not in data:
|
if 'tags' not in data:
|
||||||
data['tags'] = []
|
data['tags'] = []
|
||||||
needs_update = True
|
needs_update = True
|
||||||
|
|||||||
@@ -28,7 +28,10 @@ export class UpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform update check if needed
|
// Perform update check if needed
|
||||||
this.checkForUpdates();
|
this.checkForUpdates().then(() => {
|
||||||
|
// Ensure badges are updated after checking
|
||||||
|
this.updateBadgeVisibility();
|
||||||
|
});
|
||||||
|
|
||||||
// Set up event listener for update button
|
// Set up event listener for update button
|
||||||
const updateToggle = document.getElementById('updateToggleBtn');
|
const updateToggle = document.getElementById('updateToggleBtn');
|
||||||
@@ -43,7 +46,9 @@ export class UpdateService {
|
|||||||
async checkForUpdates() {
|
async checkForUpdates() {
|
||||||
// Check if we should perform an update check
|
// Check if we should perform an update check
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - this.lastCheckTime < this.updateCheckInterval) {
|
const forceCheck = this.lastCheckTime === 0;
|
||||||
|
|
||||||
|
if (!forceCheck && now - this.lastCheckTime < this.updateCheckInterval) {
|
||||||
// If we already have update info, just update the UI
|
// If we already have update info, just update the UI
|
||||||
if (this.updateAvailable) {
|
if (this.updateAvailable) {
|
||||||
this.updateBadgeVisibility();
|
this.updateBadgeVisibility();
|
||||||
@@ -61,8 +66,8 @@ export class UpdateService {
|
|||||||
this.latestVersion = data.latest_version || "v0.0.0";
|
this.latestVersion = data.latest_version || "v0.0.0";
|
||||||
this.updateInfo = data;
|
this.updateInfo = data;
|
||||||
|
|
||||||
// Determine if update is available
|
// Explicitly set update availability based on version comparison
|
||||||
this.updateAvailable = data.update_available;
|
this.updateAvailable = this.isNewerVersion(this.latestVersion, this.currentVersion);
|
||||||
|
|
||||||
// Update last check time
|
// Update last check time
|
||||||
this.lastCheckTime = now;
|
this.lastCheckTime = now;
|
||||||
@@ -83,6 +88,37 @@ export class UpdateService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper method to compare version strings
|
||||||
|
isNewerVersion(latestVersion, currentVersion) {
|
||||||
|
if (!latestVersion || !currentVersion) return false;
|
||||||
|
|
||||||
|
// Remove 'v' prefix if present
|
||||||
|
const latest = latestVersion.replace(/^v/, '');
|
||||||
|
const current = currentVersion.replace(/^v/, '');
|
||||||
|
|
||||||
|
// Split version strings into components
|
||||||
|
const latestParts = latest.split(/[-\.]/);
|
||||||
|
const currentParts = current.split(/[-\.]/);
|
||||||
|
|
||||||
|
// Compare major, minor, patch versions
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
const latestNum = parseInt(latestParts[i] || '0', 10);
|
||||||
|
const currentNum = parseInt(currentParts[i] || '0', 10);
|
||||||
|
|
||||||
|
if (latestNum > currentNum) return true;
|
||||||
|
if (latestNum < currentNum) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If numeric versions are the same, check for beta/alpha status
|
||||||
|
const latestIsBeta = latest.includes('beta') || latest.includes('alpha');
|
||||||
|
const currentIsBeta = current.includes('beta') || current.includes('alpha');
|
||||||
|
|
||||||
|
// Release version is newer than beta/alpha
|
||||||
|
if (!latestIsBeta && currentIsBeta) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
updateBadgeVisibility() {
|
updateBadgeVisibility() {
|
||||||
const updateToggle = document.querySelector('.update-toggle');
|
const updateToggle = document.querySelector('.update-toggle');
|
||||||
const updateBadge = document.querySelector('.update-toggle .update-badge');
|
const updateBadge = document.querySelector('.update-toggle .update-badge');
|
||||||
@@ -94,14 +130,17 @@ export class UpdateService {
|
|||||||
: "Check Updates";
|
: "Check Updates";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateBadge) {
|
// Force updating badges visibility based on current state
|
||||||
const shouldShow = this.updateNotificationsEnabled && this.updateAvailable;
|
const shouldShow = this.updateNotificationsEnabled && this.updateAvailable;
|
||||||
|
|
||||||
|
if (updateBadge) {
|
||||||
updateBadge.classList.toggle('hidden', !shouldShow);
|
updateBadge.classList.toggle('hidden', !shouldShow);
|
||||||
|
console.log("Update badge visibility:", !shouldShow ? "hidden" : "visible");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cornerBadge) {
|
if (cornerBadge) {
|
||||||
const shouldShow = this.updateNotificationsEnabled && this.updateAvailable;
|
|
||||||
cornerBadge.classList.toggle('hidden', !shouldShow);
|
cornerBadge.classList.toggle('hidden', !shouldShow);
|
||||||
|
console.log("Corner badge visibility:", !shouldShow ? "hidden" : "visible");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +233,8 @@ export class UpdateService {
|
|||||||
async manualCheckForUpdates() {
|
async manualCheckForUpdates() {
|
||||||
this.lastCheckTime = 0; // Reset last check time to force check
|
this.lastCheckTime = 0; // Reset last check time to force check
|
||||||
await this.checkForUpdates();
|
await this.checkForUpdates();
|
||||||
|
// Ensure badge visibility is updated after manual check
|
||||||
|
this.updateBadgeVisibility();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user