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 @@
+ title="{% if lora.from_civitai %}View on Civitai{% else %}Not available from Civitai{% endif %}" + {% if lora.from_civitai %}onclick="event.stopPropagation(); openCivitai('{{ lora.model_name }}')"{% endif %} + {% if not lora.from_civitai %}style="opacity: 0.5; cursor: not-allowed"{% endif %}> diff --git a/utils/file_utils.py b/utils/file_utils.py index 8eec80ac..4c483e60 100644 --- a/utils/file_utils.py +++ b/utils/file_utils.py @@ -22,6 +22,7 @@ async def get_file_info(file_path: str) -> LoraMetadata: modified=os.path.getmtime(file_path), sha256=await calculate_sha256(file_path), base_model="Unknown", # Will be updated later + from_civitai=True, preview_url="", ) diff --git a/utils/models.py b/utils/models.py index e5e43c7f..07d3d54c 100644 --- a/utils/models.py +++ b/utils/models.py @@ -13,6 +13,7 @@ class LoraMetadata: sha256: str # SHA256 hash of the file base_model: str # Base model (SD1.5/SD2.1/SDXL/etc.) preview_url: str # Preview image URL + from_civitai: bool = True # Whether the lora is from Civitai civitai: Optional[Dict] = None # Civitai API data if available @classmethod @@ -33,4 +34,6 @@ class LoraMetadata: def update_civitai_info(self, civitai_data: Dict) -> None: """Update Civitai information""" - self.civitai = civitai_data \ No newline at end of file + self.civitai = civitai_data + + \ No newline at end of file