diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-02-19 09:30:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-19 09:30:58 +0000 |
commit | cfc9849f3f64977936769b6479d6b2231ecbfc5b (patch) | |
tree | 51b29ea3b255fe43b0fe7560f9f7fdd23a475427 /modules/ui_extra_networks.py | |
parent | 5afd9e82c3829348c58803cd85b02c87308fffae (diff) | |
parent | d99bd04b3f8c7753e31aa6dea6109785c4bb92c9 (diff) | |
download | stable-diffusion-webui-gfx803-cfc9849f3f64977936769b6479d6b2231ecbfc5b.tar.gz stable-diffusion-webui-gfx803-cfc9849f3f64977936769b6479d6b2231ecbfc5b.tar.bz2 stable-diffusion-webui-gfx803-cfc9849f3f64977936769b6479d6b2231ecbfc5b.zip |
Merge branch 'master' into 6866-fix-hires-prompt-matrix
Diffstat (limited to 'modules/ui_extra_networks.py')
-rw-r--r-- | modules/ui_extra_networks.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index 83367968..71f1d81f 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -26,11 +26,12 @@ def add_pages_to_demo(app): def fetch_file(filename: str = ""):
from starlette.responses import FileResponse
- if not any([Path(x).resolve() in Path(filename).resolve().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.")
- if os.path.splitext(filename)[1].lower() != ".png":
- raise ValueError(f"File cannot be fetched: {filename}. Only png.")
+ ext = os.path.splitext(filename)[1].lower()
+ if ext not in (".png", ".jpg"):
+ raise ValueError(f"File cannot be fetched: {filename}. Only png and jpg.")
# would profit from returning 304
return FileResponse(filename, headers={"Accept-Ranges": "bytes"})
@@ -75,6 +76,10 @@ class ExtraNetworksPage: while subdir.startswith("/"):
subdir = subdir[1:]
+ is_empty = len(os.listdir(x)) == 0
+ if not is_empty and not subdir.endswith("/"):
+ subdir = subdir + "/"
+
subdirs[subdir] = 1
if subdirs:
@@ -93,11 +98,13 @@ class ExtraNetworksPage: dirs = "".join([f"<li>{x}</li>" for x in self.allowed_directories_for_previews()])
items_html = shared.html("extra-networks-no-cards.html").format(dirs=dirs)
+ self_name_id = self.name.replace(" ", "_")
+
res = f"""
-<div id='{tabname}_{self.name}_subdirs' class='extra-network-subdirs extra-network-subdirs-{view}'>
+<div id='{tabname}_{self_name_id}_subdirs' class='extra-network-subdirs extra-network-subdirs-{view}'>
{subdirs_html}
</div>
-<div id='{tabname}_{self.name}_cards' class='extra-network-{view}'>
+<div id='{tabname}_{self_name_id}_cards' class='extra-network-{view}'>
{items_html}
</div>
"""
|