Deploy to subdirectory

This commit is contained in:
Matthias 2021-01-31 15:37:57 +01:00
parent e4a085027b
commit 06e2bc94c3
4 changed files with 8 additions and 4 deletions

View File

@ -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()

View File

@ -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))

View File

@ -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