Skip to content

Commit

Permalink
get AUTOMATIC1111#13121 to work without restart
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Sep 30, 2023
1 parent 5cc7bf3 commit b2f9709
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions modules/ui_extra_networks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import os.path
import urllib.parse
from pathlib import Path
Expand All @@ -15,10 +16,16 @@
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]
default_allowed_preview_extensions = ["png", "jpg", "jpeg", "webp", "gif"]


@functools.cache
def allowed_preview_extensions_with_extra(extra_extensions=None):
return set(default_allowed_preview_extensions) | set(extra_extensions or [])


def allowed_preview_extensions():
return allowed_preview_extensions_with_extra((shared.opts.samples_format, ))


def register_page(page):
Expand All @@ -38,9 +45,9 @@ def fetch_file(filename: str = ""):
if not any(Path(x).absolute() in Path(filename).absolute().parents for x in allowed_dirs):
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 allowed_preview_extensions_dot:
raise ValueError(f"File cannot be fetched: {filename}. Only png, jpg, webp, and gif.")
ext = os.path.splitext(filename)[1].lower()[1:]
if ext not in allowed_preview_extensions():
raise ValueError(f"File cannot be fetched: {filename}. Extensions allowed: {allowed_preview_extensions()}.")

# would profit from returning 304
return FileResponse(filename, headers={"Accept-Ranges": "bytes"})
Expand Down Expand Up @@ -278,7 +285,7 @@ def find_preview(self, path):
Find a preview PNG for a given path (without extension) and call link_preview on it.
"""

potential_files = sum([[path + "." + ext, path + ".preview." + ext] for ext in allowed_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 b2f9709

Please sign in to comment.