Skip to content

Commit

Permalink
consolidated allowed preview formats
Browse files Browse the repository at this point in the history
  • Loading branch information
w-e-w committed Sep 7, 2023
1 parent d39440b commit 4588170
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 4588170

Please sign in to comment.