Skip to content

Commit

Permalink
Fixes URL resolution on Windows (#3108)
Browse files Browse the repository at this point in the history
* windows urls

* changelog

* formatting
  • Loading branch information
abidlabs committed Feb 2, 2023
1 parent 0448462 commit 431a987
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions gradio/routes.py
Expand Up @@ -261,15 +261,17 @@ async def favicon():
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:
Expand All @@ -291,7 +293,7 @@ async def file(path: str, request: fastapi.Request):

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)])
Expand Down

0 comments on commit 431a987

Please sign in to comment.