diff --git a/quetz/main.py b/quetz/main.py index 9e527df2..ab1a60fb 100644 --- a/quetz/main.py +++ b/quetz/main.py @@ -1560,17 +1560,6 @@ def serve_path( dao: Dao = Depends(get_dao), ): - if channel.mirror_channel_url and channel.mirror_mode == "proxy": - repository = RemoteRepository(channel.mirror_channel_url, session) - if not pkgstore.file_exists(channel.name, path): - download_remote_file(repository, pkgstore, channel.name, path) - elif path.endswith(".json"): - # repodata.json and current_repodata.json are cached locally - # for channel.ttl seconds - _, fmtime, _ = pkgstore.get_filemetadata(channel.name, path) - if time.time() - fmtime >= channel.ttl: - download_remote_file(repository, pkgstore, channel.name, path) - chunk_size = 10_000 is_package_request = path.endswith((".tar.bz2", ".conda")) @@ -1598,6 +1587,17 @@ def serve_path( if channel_proxylist and package_name and package_name in channel_proxylist: return RedirectResponse(f"{channel.mirror_channel_url}/{path}") + if channel.mirror_channel_url and channel.mirror_mode == "proxy": + repository = RemoteRepository(channel.mirror_channel_url, session) + if not pkgstore.file_exists(channel.name, path): + download_remote_file(repository, pkgstore, channel.name, path) + elif path.endswith(".json"): + # repodata.json and current_repodata.json are cached locally + # for channel.ttl seconds + _, fmtime, _ = pkgstore.get_filemetadata(channel.name, path) + if time.time() - fmtime >= channel.ttl: + download_remote_file(repository, pkgstore, channel.name, path) + if ( is_package_request or pkgstore.kind == "LocalStore" ) and pkgstore.support_redirect: diff --git a/quetz/tests/test_mirror.py b/quetz/tests/test_mirror.py index c0980a36..f9fef49e 100644 --- a/quetz/tests/test_mirror.py +++ b/quetz/tests/test_mirror.py @@ -1029,6 +1029,34 @@ def test_includelist_and_excludelist_mirror_channel(owner, client): assert response.status_code == 422 +@pytest.mark.parametrize("mirror_mode", ["proxy", "mirror"]) +def test_proxylist_mirror_channel(owner, client, mirror_mode): + response = client.get("/api/dummylogin/bartosz") + assert response.status_code == 200 + + response = client.post( + "/api/channels", + json={ + "name": "mirror-channel-btel", + "private": False, + "mirror_channel_url": "https://conda.anaconda.org/btel", + "mirror_mode": mirror_mode, + "metadata": {"proxylist": ["nrnpython"]}, + }, + ) + assert response.status_code == 201 + + response = client.get( + "/get/mirror-channel-btel/linux-64/nrnpython-0.1-0.tar.bz2", + allow_redirects=False, + ) + assert response.status_code == 307 + assert ( + response.headers.get("location") + == "https://conda.anaconda.org/btel/linux-64/nrnpython-0.1-0.tar.bz2" + ) + + def test_sync_local_channel(local_channel, user, client, dummy_repo): response = client.put( f"/api/channels/{local_channel.name}/actions", json={"action": "synchronize"}