Fix modal window display

This commit is contained in:
Will Miao
2025-01-27 00:42:33 +08:00
parent 87c64f9b71
commit 26a84afb20
6 changed files with 39 additions and 17 deletions

View File

@@ -162,6 +162,7 @@ class LorasEndpoint:
"sha256": lora["sha256"], "sha256": lora["sha256"],
"file_path": lora["file_path"], "file_path": lora["file_path"],
"modified": lora["modified"], "modified": lora["modified"],
"from_civitai": lora.get("from_civitai", True),
"civitai": lora.get("civitai", {}) or {} # 确保当 civitai 为 None 时返回空字典 "civitai": lora.get("civitai", {}) or {} # 确保当 civitai 为 None 时返回空字典
} }
except Exception as e: except Exception as e:
@@ -176,6 +177,7 @@ class LorasEndpoint:
"sha256": lora.get("sha256", ""), "sha256": lora.get("sha256", ""),
"file_path": lora.get("file_path", ""), "file_path": lora.get("file_path", ""),
"modified": lora.get("modified", ""), "modified": lora.get("modified", ""),
"from_civitai": lora.get("from_civitai", True),
"civitai": { "civitai": {
"id": "", "id": "",
"modelId": "", "modelId": "",
@@ -268,24 +270,31 @@ class LorasEndpoint:
client = CivitaiClient() client = CivitaiClient()
try: 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元数据 # 1. 获取CivitAI元数据
civitai_metadata = await client.get_model_by_hash(data["sha256"]) civitai_metadata = await client.get_model_by_hash(data["sha256"])
if not civitai_metadata: 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( return web.json_response(
{"success": False, "error": "Not found on CivitAI"}, {"success": False, "error": "Not found on CivitAI"},
status=404 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 local_metadata['civitai']=civitai_metadata
# 更新模型名称优先使用CivitAI名称 # 更新模型名称优先使用CivitAI名称

View File

@@ -245,6 +245,12 @@ body.modal-open {
object-fit: contain; object-fit: contain;
} }
.carousel video {
scroll-snap-align: start;
max-height: 60vh;
object-fit: contain;
}
/* 主题切换按钮 */ /* 主题切换按钮 */
.theme-toggle { .theme-toggle {
position: fixed; position: fixed;

View File

@@ -164,8 +164,10 @@ let currentImageIndex = 0;
document.querySelectorAll('.lora-card').forEach(card => { document.querySelectorAll('.lora-card').forEach(card => {
card.addEventListener('click', () => { card.addEventListener('click', () => {
currentLora = JSON.parse(card.dataset.meta); if (card.dataset.meta && Object.keys(JSON.parse(card.dataset.meta)).length > 0) {
showModal(currentLora); currentLora = JSON.parse(card.dataset.meta);
showModal(currentLora);
}
}); });
}); });
@@ -175,9 +177,9 @@ function showModal(lora) {
<div class="modal-content"> <div class="modal-content">
<h2>${lora.model.name}</h2> <h2>${lora.model.name}</h2>
<div class="carousel"> <div class="carousel">
${lora.images.map(img => `<img src="${img.url}" alt="Preview">`).join('')} ${lora.images.map(img => img.type === 'video' ? `<video controls autoplay muted loop><source src="${img.url}" type="video/mp4">Your browser does not support the video tag.</video>` : `<img src="${img.url}" alt="Preview">`).join('')}
</div> </div>
<div class="description">${lora.description}</div> <div class="description">About this version: ${lora.description ? lora.description : 'N/A'}</div>
<button class="close" onclick="closeModal()">&times;</button> <button class="close" onclick="closeModal()">&times;</button>
</div> </div>
`; `;

View File

@@ -70,8 +70,9 @@
</span> </span>
<div class="card-actions"> <div class="card-actions">
<i class="fas fa-globe" <i class="fas fa-globe"
title="View on Civitai" title="{% if lora.from_civitai %}View on Civitai{% else %}Not available from Civitai{% endif %}"
onclick="event.stopPropagation(); openCivitai('{{ lora.model_name }}')"></i> {% 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 %}></i>
<i class="fas fa-copy" <i class="fas fa-copy"
title="Copy Model Name" title="Copy Model Name"
onclick="event.stopPropagation(); navigator.clipboard.writeText(this.closest('.lora-card').dataset.file_name)"></i> onclick="event.stopPropagation(); navigator.clipboard.writeText(this.closest('.lora-card').dataset.file_name)"></i>

View File

@@ -22,6 +22,7 @@ async def get_file_info(file_path: str) -> LoraMetadata:
modified=os.path.getmtime(file_path), modified=os.path.getmtime(file_path),
sha256=await calculate_sha256(file_path), sha256=await calculate_sha256(file_path),
base_model="Unknown", # Will be updated later base_model="Unknown", # Will be updated later
from_civitai=True,
preview_url="", preview_url="",
) )

View File

@@ -13,6 +13,7 @@ class LoraMetadata:
sha256: str # SHA256 hash of the file sha256: str # SHA256 hash of the file
base_model: str # Base model (SD1.5/SD2.1/SDXL/etc.) base_model: str # Base model (SD1.5/SD2.1/SDXL/etc.)
preview_url: str # Preview image URL 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 civitai: Optional[Dict] = None # Civitai API data if available
@classmethod @classmethod
@@ -33,4 +34,6 @@ class LoraMetadata:
def update_civitai_info(self, civitai_data: Dict) -> None: def update_civitai_info(self, civitai_data: Dict) -> None:
"""Update Civitai information""" """Update Civitai information"""
self.civitai = civitai_data self.civitai = civitai_data