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"],
"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:
# 1. 获取CivitAI元数据
civitai_metadata = await client.get_model_by_hash(data["sha256"])
if not civitai_metadata:
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. 更新元数据字段
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
)
local_metadata['civitai']=civitai_metadata
# 更新模型名称优先使用CivitAI名称

View File

@@ -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;

View File

@@ -164,8 +164,10 @@ let currentImageIndex = 0;
document.querySelectorAll('.lora-card').forEach(card => {
card.addEventListener('click', () => {
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) {
<div class="modal-content">
<h2>${lora.model.name}</h2>
<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 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>
</div>
`;

View File

@@ -70,8 +70,9 @@
</span>
<div class="card-actions">
<i class="fas fa-globe"
title="View on Civitai"
onclick="event.stopPropagation(); openCivitai('{{ lora.model_name }}')"></i>
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 %}></i>
<i class="fas fa-copy"
title="Copy Model Name"
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),
sha256=await calculate_sha256(file_path),
base_model="Unknown", # Will be updated later
from_civitai=True,
preview_url="",
)

View File

@@ -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
@@ -34,3 +35,5 @@ class LoraMetadata:
def update_civitai_info(self, civitai_data: Dict) -> None:
"""Update Civitai information"""
self.civitai = civitai_data