diff --git a/static/js/api/loraApi.js b/static/js/api/loraApi.js index 3dae5e81..b34efc77 100644 --- a/static/js/api/loraApi.js +++ b/static/js/api/loraApi.js @@ -163,23 +163,28 @@ export async function replacePreview(filePath) { } const data = await response.json(); - const newPreviewPath = `${data.preview_url}?t=${new Date().getTime()}`; + // 更新预览版本 + state.previewVersions.set(filePath, Date.now()); + + // 更新卡片显示 const card = document.querySelector(`.lora-card[data-filepath="${filePath}"]`); const previewContainer = card.querySelector('.card-preview'); const oldPreview = previewContainer.querySelector('img, video'); + const previewUrl = `${data.preview_url}?t=${state.previewVersions.get(filePath)}`; + if (file.type.startsWith('video/')) { const video = document.createElement('video'); video.controls = true; video.autoplay = true; video.muted = true; video.loop = true; - video.src = newPreviewPath; + video.src = previewUrl; oldPreview.replaceWith(video); } else { const img = document.createElement('img'); - img.src = newPreviewPath; + img.src = previewUrl; oldPreview.replaceWith(img); } diff --git a/static/js/components/LoraCard.js b/static/js/components/LoraCard.js index faf6d52f..7e24c06c 100644 --- a/static/js/components/LoraCard.js +++ b/static/js/components/LoraCard.js @@ -1,5 +1,6 @@ import { showToast } from '../utils/uiHelpers.js'; import { modalManager } from '../managers/ModalManager.js'; +import { state } from '../state/index.js'; export function createLoraCard(lora) { const card = document.createElement('div'); @@ -13,16 +14,17 @@ export function createLoraCard(lora) { card.dataset.from_civitai = lora.from_civitai; card.dataset.meta = JSON.stringify(lora.civitai || {}); - // Add timestamp to preview URL to prevent caching - const previewUrl = lora.preview_url ? `${lora.preview_url}?t=${Date.now()}` : '/loras_static/images/no-preview.png'; + const version = state.previewVersions.get(lora.file_path); + const previewUrl = lora.preview_url || '/loras_static/images/no-preview.png'; + const versionedPreviewUrl = version ? `${previewUrl}?t=${version}` : previewUrl; card.innerHTML = `