Merge pull request #11806 from huchenlei/file_500

404 when thumb file not found
This commit is contained in:
AUTOMATIC1111 2023-07-16 09:26:07 +03:00 committed by GitHub
commit 57e4422bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from modules.ui import up_down_symbol
import gradio as gr import gradio as gr
import json import json
import html import html
from fastapi.exceptions import HTTPException
from modules.generation_parameters_copypaste import image_from_url_text from modules.generation_parameters_copypaste import image_from_url_text
@ -26,6 +27,9 @@ def register_page(page):
def fetch_file(filename: str = ""): def fetch_file(filename: str = ""):
from starlette.responses import FileResponse from starlette.responses import FileResponse
if not os.path.isfile(filename):
raise HTTPException(status_code=404, detail="File not found")
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.")