add support for video previews (#197)
* add support for video previews * fix two cases where video previews did not show
This commit is contained in:
@@ -355,23 +355,17 @@ class Information:
|
||||
@routes.get("/model-manager/preview/{type}/{index}/{filename:.*}")
|
||||
async def read_model_preview(request):
|
||||
"""
|
||||
Get the file stream of the specified image.
|
||||
Get the file stream of the specified preview
|
||||
If the file does not exist, no-preview.png is returned.
|
||||
|
||||
:param type: The type of the model. eg.checkpoints, loras, vae, etc.
|
||||
:param index: The index of the model folders.
|
||||
:param filename: The filename of the image.
|
||||
:param filename: The filename of the preview.
|
||||
"""
|
||||
model_type = request.match_info.get("type", None)
|
||||
index = int(request.match_info.get("index", None))
|
||||
filename = request.match_info.get("filename", None)
|
||||
|
||||
content_type = utils.resolve_file_content_type(filename)
|
||||
|
||||
if content_type == "video":
|
||||
abs_path = utils.get_full_path(model_type, index, filename)
|
||||
return web.FileResponse(abs_path)
|
||||
|
||||
extension_uri = config.extension_uri
|
||||
|
||||
try:
|
||||
@@ -388,8 +382,16 @@ class Information:
|
||||
if not os.path.isfile(abs_path):
|
||||
abs_path = utils.join_path(extension_uri, "assets", "no-preview.png")
|
||||
|
||||
image_data = self.get_image_preview_data(abs_path)
|
||||
return web.Response(body=image_data.getvalue(), content_type="image/webp")
|
||||
# Determine content type from the actual file
|
||||
content_type = utils.resolve_file_content_type(abs_path)
|
||||
|
||||
if content_type == "video":
|
||||
# Serve video files directly
|
||||
return web.FileResponse(abs_path)
|
||||
else:
|
||||
# Serve image files (WebP or fallback images)
|
||||
image_data = self.get_image_preview_data(abs_path)
|
||||
return web.Response(body=image_data.getvalue(), content_type="image/webp")
|
||||
|
||||
@routes.get("/model-manager/preview/download/{filename}")
|
||||
async def read_download_preview(request):
|
||||
@@ -546,10 +548,10 @@ class Information:
|
||||
model_info = CivitaiModelSearcher().search_by_hash(hash_value)
|
||||
|
||||
preview_url_list = model_info.get("preview", [])
|
||||
preview_image_url = preview_url_list[0] if preview_url_list else None
|
||||
if preview_image_url:
|
||||
utils.print_debug(f"Save preview image to {abs_image_path}")
|
||||
utils.save_model_preview_image(abs_model_path, preview_image_url)
|
||||
preview_url = preview_url_list[0] if preview_url_list else None
|
||||
if preview_url:
|
||||
utils.print_debug(f"Save preview to {abs_model_path}")
|
||||
utils.save_model_preview(abs_model_path, preview_url)
|
||||
|
||||
description = model_info.get("description", None)
|
||||
if description:
|
||||
|
||||
Reference in New Issue
Block a user