mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Fixes method to resolve the root
URLs (#7565)
* fix * fix * add changeset * fix test --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
3940490fc0
commit
1c22123268
5
.changeset/deep-teeth-sleep.md
Normal file
5
.changeset/deep-teeth-sleep.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Fixes method to resolve the `root` URLs
|
@ -299,10 +299,11 @@ def move_files_to_cache(
|
||||
|
||||
def add_root_url(data: dict, root_url: str, previous_root_url: str | None) -> dict:
|
||||
def _add_root_url(file_dict: dict):
|
||||
if not client_utils.is_http_url_like(file_dict["url"]):
|
||||
if previous_root_url and file_dict["url"].startswith(previous_root_url):
|
||||
file_dict["url"] = file_dict["url"][len(previous_root_url) :]
|
||||
file_dict["url"] = f'{root_url}{file_dict["url"]}'
|
||||
if previous_root_url and file_dict["url"].startswith(previous_root_url):
|
||||
file_dict["url"] = file_dict["url"][len(previous_root_url) :]
|
||||
elif client_utils.is_http_url_like(file_dict["url"]):
|
||||
return file_dict
|
||||
file_dict["url"] = f'{root_url}{file_dict["url"]}'
|
||||
return file_dict
|
||||
|
||||
return client_utils.traverse(data, _add_root_url, client_utils.is_file_obj_with_url)
|
||||
|
@ -361,7 +361,7 @@ def test_add_root_url():
|
||||
new_expected = {
|
||||
"file": {
|
||||
"path": "path",
|
||||
"url": f"{root_url}/file=path",
|
||||
"url": f"{new_root_url}/file=path",
|
||||
},
|
||||
"file2": {
|
||||
"path": "path2",
|
||||
@ -369,5 +369,5 @@ def test_add_root_url():
|
||||
},
|
||||
}
|
||||
assert (
|
||||
processing_utils.add_root_url(expected, root_url, new_root_url) == new_expected
|
||||
processing_utils.add_root_url(expected, new_root_url, root_url) == new_expected
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user