mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-01-29 17:52:56 +08:00
get #13121 to work without restart
This commit is contained in:
parent
5cc7bf3876
commit
b2f9709538
@ -1,3 +1,4 @@
|
|||||||
|
import functools
|
||||||
import os.path
|
import os.path
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -15,10 +16,16 @@ from modules.ui_components import ToolButton
|
|||||||
extra_pages = []
|
extra_pages = []
|
||||||
allowed_dirs = set()
|
allowed_dirs = set()
|
||||||
|
|
||||||
allowed_preview_extensions = ["png", "jpg", "jpeg", "webp", "gif"]
|
default_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]
|
@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):
|
def register_page(page):
|
||||||
@ -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):
|
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.")
|
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()
|
ext = os.path.splitext(filename)[1].lower()[1:]
|
||||||
if ext not in allowed_preview_extensions_dot:
|
if ext not in allowed_preview_extensions():
|
||||||
raise ValueError(f"File cannot be fetched: {filename}. Only png, jpg, webp, and gif.")
|
raise ValueError(f"File cannot be fetched: {filename}. Extensions allowed: {allowed_preview_extensions()}.")
|
||||||
|
|
||||||
# would profit from returning 304
|
# would profit from returning 304
|
||||||
return FileResponse(filename, headers={"Accept-Ranges": "bytes"})
|
return FileResponse(filename, headers={"Accept-Ranges": "bytes"})
|
||||||
@ -278,7 +285,7 @@ class ExtraNetworksPage:
|
|||||||
Find a preview PNG for a given path (without extension) and call link_preview on it.
|
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:
|
for file in potential_files:
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
|
Loading…
Reference in New Issue
Block a user