Fixes URL resolution on Windows (#3108)

* windows urls

* changelog

* formatting
This commit is contained in:
Abubakar Abid 2023-02-02 08:47:17 -08:00 committed by GitHub
parent 04484621c2
commit 431a987d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -4,7 +4,7 @@
No changes to highlight.
## Bug Fixes:
No changes to highlight.
- Fixes URL resolution on Windows by [@abidlabs](https://github.com/abidlabs) in [PR 3108](https://github.com/gradio-app/gradio/pull/3108)
## Documentation Changes:
- Added a guide on the 4 kinds of Gradio Interfaces by [@yvrjsharma](https://github.com/yvrjsharma) and [@abidlabs](https://github.com/abidlabs) in [PR 3003](https://github.com/gradio-app/gradio/pull/3003)

View File

@ -261,15 +261,17 @@ class App(FastAPI):
else:
return FileResponse(blocks.favicon_path)
@app.head("/file={path:path}", dependencies=[Depends(login_check)])
@app.get("/file={path:path}", dependencies=[Depends(login_check)])
async def file(path: str, request: fastapi.Request):
abs_path = str(utils.abspath(path))
@app.head("/file={path_or_url:path}", dependencies=[Depends(login_check)])
@app.get("/file={path_or_url:path}", dependencies=[Depends(login_check)])
async def file(path_or_url: str, request: fastapi.Request):
blocks = app.get_blocks()
if utils.validate_url(path):
return RedirectResponse(url=path, status_code=status.HTTP_302_FOUND)
in_app_dir = utils.abspath(app.cwd) in utils.abspath(path).parents
created_by_app = str(utils.abspath(path)) in set().union(
if utils.validate_url(path_or_url):
return RedirectResponse(
url=path_or_url, status_code=status.HTTP_302_FOUND
)
abs_path = str(utils.abspath(path_or_url))
in_app_dir = utils.abspath(app.cwd) in utils.abspath(path_or_url).parents
created_by_app = str(utils.abspath(path_or_url)) in set().union(
*blocks.temp_file_sets
)
if in_app_dir or created_by_app:
@ -291,7 +293,7 @@ class App(FastAPI):
else:
raise ValueError(
f"File cannot be fetched: {path}. All files must contained within the Gradio python app working directory, or be a temp file created by the Gradio python app."
f"File cannot be fetched: {path_or_url}. All files must contained within the Gradio python app working directory, or be a temp file created by the Gradio python app."
)
@app.get("/file/{path:path}", dependencies=[Depends(login_check)])