From 45881703c5b1c0499406a76fa49ec7bd408a4898 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:11:36 +0900 Subject: [PATCH] consolidated allowed preview formats --- modules/ui_extra_networks.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index 063bd7b80e6..2e816254d0b 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -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""" @@ -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 @@ -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):