Preview URLs now carry a cache-busting `&v=<mtime_ns>` suffix, so the media type could no longer be read from the end of the string. Model cards, duplicates, recipe cards and modals, the showcase thumbnail and the ComfyUI preview tooltip all fell into the image branch and rendered `<img>` for video previews, which browsers cannot decode. Move the query-aware video detection that already lived in the versions tab into a shared mediaTypes helper and use it everywhere a server-provided preview URL is inspected. The web UI and the ComfyUI widget bundle each keep a copy because they are served from different mounts. Video previews that turn out to be webm now also get the right `<source type>`. Add regression coverage for versioned mp4/webm/image URLs. Fixes #1168
2.6 KiB
Library Switching and Preview Routes
Deprecated: Multi-library support (and therefore library switching) is deprecated and will be removed in an upcoming release. The dynamic preview route described here will remain — it also serves single-library installations.
Library switching no longer requires restarting the backend. The preview thumbnails shown in the UI are now served through a dynamic endpoint that resolves files against the folders registered for the active library at request time. This allows the multi-library flow to update model roots without touching the aiohttp router, so previews remain available immediately after a switch.
How the dynamic preview endpoint works
config.get_preview_static_url()now returns/api/lm/previews?path=<encoded>&v=<mtime_ns>for any preview path. The raw filesystem location is URL encoded so that it can be passed through the query string without leaking directory structure in the route itself. Thevparameter carries the preview file's modification time so a rewritten preview (e.g. delete + recreate an LM-managed workflow) produces a fresh URL that bypasses the browser's day-long cache; the handler ignores it.【F:py/config.py†L398-L404】 Because the URL no longer ends with the media extension, clients must not pick between<img>and<video>with a suffix check: derive the extension from the decodedpathvalue (static/js/utils/mediaTypes.jsfor the web UI,web/comfyui/mediaTypes.jsfor the ComfyUI widgets).PreviewRoutesexposes the/api/lm/previewshandler which validates the decoded path against the directories registered for the current library. The request is rejected if it falls outside those roots or if the file does not exist.【F:py/routes/preview_routes.py†L5-L21】【F:py/routes/handlers/preview_handlers.py†L9-L48】Configkeeps an up-to-date cache of allowed preview roots. Every time a library is applied the cache is rebuilt using the declared LoRA, checkpoint and embedding directories (including symlink targets). The validation logic checks preview requests against this cache.【F:py/config.py†L51-L68】【F:py/config.py†L180-L248】【F:py/config.py†L332-L346】
Both the ComfyUI runtime (LoraManager.add_routes) and the standalone launcher
(StandaloneLoraManager.add_routes) register the new preview routes instead of
mounting a static directory per root. Switching libraries therefore works
without restarting the application, and preview URLs generated before or after a
switch continue to resolve correctly.【F:py/lora_manager.py†L21-L82】【F:standalone.py†L302-L315】