Skip to content

Commit

Permalink
Support mirror CDNs for chunked package list index download
Browse files Browse the repository at this point in the history
Calls to the API endpoint can indicate that a mirror CDN is preferred
by including a query parameter in the request. The endpoint will return
an URL to the preferred CDN only if the CDN is allowlisted in the
config.

This feature is intended to mitigate the issues of the CDN provider.
  • Loading branch information
anttimaki committed Sep 27, 2024
1 parent 23f4db9 commit e22daf1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion django/thunderstore/repository/api/v1/views/listing_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework.views import APIView

from thunderstore.community.models import Community
from thunderstore.core.utils import replace_cdn
from thunderstore.repository.models import APIV1ChunkedPackageCache


Expand All @@ -28,6 +29,8 @@ def get(self, request: Request, community_identifier: str):
cache = APIV1ChunkedPackageCache.get_latest_for_community(community)

if cache:
return redirect(request.build_absolute_uri(cache.index.data_url))
url = request.build_absolute_uri(cache.index.data_url)
url = replace_cdn(url, request.query_params.get("cdn"))
return redirect(url)

Check warning on line 34 in django/thunderstore/repository/api/v1/views/listing_index.py

View check run for this annotation

Codecov / codecov/patch

django/thunderstore/repository/api/v1/views/listing_index.py#L32-L34

Added lines #L32 - L34 were not covered by tests

return Response({"error": "No cache available"}, status=503)

0 comments on commit e22daf1

Please sign in to comment.