From 06e2bc94c3e111bcea180485018fd081da176104 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 31 Jan 2021 15:37:57 +0100 Subject: [PATCH] Deploy to subdirectory --- freqtrade/commands/deploy_commands.py | 5 +++-- freqtrade/rpc/api_server/ui/installed/.gitkeep | 0 freqtrade/rpc/api_server/web_ui.py | 4 ++-- tests/commands/test_commands.py | 3 +++ 4 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 freqtrade/rpc/api_server/ui/installed/.gitkeep diff --git a/freqtrade/commands/deploy_commands.py b/freqtrade/commands/deploy_commands.py index 797e9f87d..5ba3db9f9 100644 --- a/freqtrade/commands/deploy_commands.py +++ b/freqtrade/commands/deploy_commands.py @@ -146,7 +146,7 @@ def clean_ui_subdir(directory: Path): logger.info("Removing UI directory content.") for p in reversed(list(directory.glob('**/*'))): # iterate contents from leaves to root - if p.name in ('favicon.ico', 'fallback_file.html'): + if p.name in ('.gitkeep', 'fallback_file.html'): continue if p.is_file(): p.unlink() @@ -169,6 +169,7 @@ def download_and_install_ui(dest_folder: Path, dl_url: str, version: str): logger.info(f"Downloading {dl_url}") resp = requests.get(dl_url).content + dest_folder.mkdir(parents=True, exist_ok=True) with ZipFile(BytesIO(resp)) as zf: for fn in zf.filelist: with zf.open(fn) as x: @@ -207,7 +208,7 @@ def get_ui_download_url() -> Tuple[str, str]: def start_install_ui(args: Dict[str, Any]) -> None: - dest_folder = Path(__file__).parents[1] / 'rpc/api_server/ui' + dest_folder = Path(__file__).parents[1] / 'rpc/api_server/ui/installed/' # First make sure the assets are removed. dl_url, latest_version = get_ui_download_url() diff --git a/freqtrade/rpc/api_server/ui/installed/.gitkeep b/freqtrade/rpc/api_server/ui/installed/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/freqtrade/rpc/api_server/web_ui.py b/freqtrade/rpc/api_server/web_ui.py index 4876c9077..6d7e77953 100644 --- a/freqtrade/rpc/api_server/web_ui.py +++ b/freqtrade/rpc/api_server/web_ui.py @@ -20,12 +20,12 @@ async def index_html(rest_of_path: str): """ if rest_of_path.startswith('api') or rest_of_path.startswith('.'): raise HTTPException(status_code=404, detail="Not Found") - uibase = Path(__file__).parent / 'ui' + uibase = Path(__file__).parent / 'ui/installed/' if (uibase / rest_of_path).is_file(): return FileResponse(str(uibase / rest_of_path)) index_file = uibase / 'index.html' if not index_file.is_file(): - return FileResponse(str(uibase / 'fallback_file.html')) + return FileResponse(str(uibase.parent / 'fallback_file.html')) # Fall back to index.html, as indicated by vue router docs return FileResponse(str(index_file)) diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 0d2b9e394..cec0b168e 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -622,6 +622,9 @@ def test_download_and_install_ui(mocker, tmpdir): folder = Path(tmpdir) / "uitests_dl" folder.mkdir(exist_ok=True) + + assert read_ui_version(folder) is None + download_and_install_ui(folder, 'http://whatever.xxx/download/file.zip', '22') assert wb_mock.call_count == 2