Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidated allowed preview formats, Fix extra network .gif not woking as preview #13121

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions modules/ui_extra_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
extra_pages = []
allowed_dirs = set()

allowed_preview_extensions = ["png", "jpg", "jpeg", "webp", "gif"]
if shared.opts.samples_format not in allowed_preview_extensions:
allowed_preview_extensions.append(shared.opts.samples_format)
allowed_preview_extensions_dot = ['.' + extension for extension in allowed_preview_extensions]


def register_page(page):
"""registers extra networks page for the UI; recommend doing it in on_before_ui() callback for extensions"""
Expand All @@ -34,7 +39,7 @@ def fetch_file(filename: str = ""):
raise ValueError(f"File cannot be fetched: {filename}. Must be in one of directories registered by extra pages.")

ext = os.path.splitext(filename)[1].lower()
if ext not in (".png", ".jpg", ".jpeg", ".webp", ".gif"):
if ext not in allowed_preview_extensions_dot:
raise ValueError(f"File cannot be fetched: {filename}. Only png, jpg, webp, and gif.")

# would profit from returning 304
Expand Down Expand Up @@ -273,11 +278,7 @@ def find_preview(self, path):
Find a preview PNG for a given path (without extension) and call link_preview on it.
"""

preview_extensions = ["png", "jpg", "jpeg", "webp"]
if shared.opts.samples_format not in preview_extensions:
preview_extensions.append(shared.opts.samples_format)

potential_files = sum([[path + "." + ext, path + ".preview." + ext] for ext in preview_extensions], [])
potential_files = sum([[path + "." + ext, path + ".preview." + ext] for ext in allowed_preview_extensions], [])

for file in potential_files:
if os.path.isfile(file):
Expand Down