From 26a84afb2033e349798ec8f2eb4be37de219f0f9 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Mon, 27 Jan 2025 00:42:33 +0800 Subject: [PATCH] Fix modal window display --- nodes.py | 29 +++++++++++++++++++---------- static/css/style.css | 6 ++++++ static/js/script.js | 10 ++++++---- templates/loras.html | 5 +++-- utils/file_utils.py | 1 + utils/models.py | 5 ++++- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/nodes.py b/nodes.py index 421bfef5..5d86ee42 100644 --- a/nodes.py +++ b/nodes.py @@ -162,6 +162,7 @@ class LorasEndpoint: "sha256": lora["sha256"], "file_path": lora["file_path"], "modified": lora["modified"], + "from_civitai": lora.get("from_civitai", True), "civitai": lora.get("civitai", {}) or {} # 确保当 civitai 为 None 时返回空字典 } except Exception as e: @@ -176,6 +177,7 @@ class LorasEndpoint: "sha256": lora.get("sha256", ""), "file_path": lora.get("file_path", ""), "modified": lora.get("modified", ""), + "from_civitai": lora.get("from_civitai", True), "civitai": { "id": "", "modelId": "", @@ -268,24 +270,31 @@ class LorasEndpoint: client = CivitaiClient() try: + metadata_path = os.path.splitext(data['file_path'])[0] + '.metadata.json' + + local_metadata = {} + if os.path.exists(metadata_path): + with open(metadata_path, 'r', encoding='utf-8') as f: + local_metadata = json.load(f) + + + if not local_metadata.get('from_civitai', True): + return web.json_response( + {"success": True, "Notice": "Not from CivitAI"}, + status=200 + ) + # 1. 获取CivitAI元数据 civitai_metadata = await client.get_model_by_hash(data["sha256"]) if not civitai_metadata: + local_metadata['from_civitai'] = False + with open(metadata_path, 'w', encoding='utf-8') as f: + json.dump(local_metadata, f, indent=2, ensure_ascii=False) return web.json_response( {"success": False, "error": "Not found on CivitAI"}, status=404 ) - # 2. 读取/创建本地元数据文件 - metadata_path = os.path.splitext(data['file_path'])[0] + '.metadata.json' - - # 合并元数据 - local_metadata = {} - if os.path.exists(metadata_path): - with open(metadata_path, 'r', encoding='utf-8') as f: - local_metadata = json.load(f) - - # 3. 更新元数据字段 local_metadata['civitai']=civitai_metadata # 更新模型名称(优先使用CivitAI名称) diff --git a/static/css/style.css b/static/css/style.css index 8c0fe2e1..d5448639 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -245,6 +245,12 @@ body.modal-open { object-fit: contain; } +.carousel video { + scroll-snap-align: start; + max-height: 60vh; + object-fit: contain; +} + /* 主题切换按钮 */ .theme-toggle { position: fixed; diff --git a/static/js/script.js b/static/js/script.js index 5c19396b..f311df41 100644 --- a/static/js/script.js +++ b/static/js/script.js @@ -164,8 +164,10 @@ let currentImageIndex = 0; document.querySelectorAll('.lora-card').forEach(card => { card.addEventListener('click', () => { - currentLora = JSON.parse(card.dataset.meta); - showModal(currentLora); + if (card.dataset.meta && Object.keys(JSON.parse(card.dataset.meta)).length > 0) { + currentLora = JSON.parse(card.dataset.meta); + showModal(currentLora); + } }); }); @@ -175,9 +177,9 @@ function showModal(lora) {
`; diff --git a/templates/loras.html b/templates/loras.html index 4955801a..527188fa 100644 --- a/templates/loras.html +++ b/templates/loras.html @@ -70,8 +70,9 @@