Skip to content

Commit

Permalink
Merge pull request AUTOMATIC1111#13121 from AUTOMATIC1111/consolidate…
Browse files Browse the repository at this point in the history
…d-allowed-preview-formats

Consolidated allowed preview formats, Fix extra network `.gif` not woking as preview
  • Loading branch information
AUTOMATIC1111 authored Sep 30, 2023
2 parents 951842d + 4588170 commit 416fbde
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit 416fbde

Please sign in to comment.