Refactor logging and update badge visibility in UpdateService; improve path normalization in file_utils

This commit is contained in:
Will Miao
2025-03-12 10:06:15 +08:00
parent 9a4124c709
commit 8e5e16ce68
4 changed files with 60 additions and 16 deletions

View File

@@ -106,8 +106,11 @@ async def load_metadata(file_path: str) -> Optional[LoraMetadata]:
needs_update = False
if data['file_path'] != normalize_path(data['file_path']):
data['file_path'] = normalize_path(data['file_path'])
# Compare paths without extensions
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
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:
data['preview_url'] = new_preview_url
needs_update = True
elif preview_url != normalize_path(preview_url):
data['preview_url'] = normalize_path(preview_url)
needs_update = True
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)
needs_update = True
# Ensure all fields are present, due to updates adding new fields
# Ensure all fields are present
if 'tags' not in data:
data['tags'] = []
needs_update = True