Skip to content

Commit

Permalink
feat(server): allow main server to be removed from mirror consideration
Browse files Browse the repository at this point in the history
Closes #229
  • Loading branch information
ericswpark committed Jul 18, 2023
1 parent 231c2fa commit eb1bc08
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
14 changes: 9 additions & 5 deletions server/api/views/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import random

from constance import config


def get_distributed_download_url(request, build):
if not build.is_mirrored():
return get_main_download_url(request, build)

available_servers = ["main", *build.get_downloadable_mirrors()]

if config.SHIPPER_DOWNLOADS_DISABLE_MAIN_SERVER:
available_servers.remove("main")

selected_server = random.choice(available_servers)
match selected_server:
case "main":
return get_main_download_url(request, build)
case _:
return selected_server.get_download_url(build)
if selected_server == "main":
return get_main_download_url(request, build)
else:
return selected_server.get_download_url(build)


def get_main_download_url(request, build):
Expand Down
1 change: 1 addition & 0 deletions server/config/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def download_page_processor(_):
"downloads_page_main_branding": config.SHIPPER_DOWNLOADS_PAGE_MAIN_BRANDING,
"downloads_page_donation_url": config.SHIPPER_DOWNLOADS_PAGE_DONATION_URL,
"downloads_page_donation_message": config.SHIPPER_DOWNLOADS_PAGE_DONATION_MESSAGE, # noqa: E501
"downloads_disable_main_server": config.SHIPPER_DOWNLOADS_DISABLE_MAIN_SERVER,
"upload_variants": variants,
}

Expand Down
7 changes: 7 additions & 0 deletions server/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@
"Donation message to show to users in the donation banner.",
str,
),
"SHIPPER_DOWNLOADS_DISABLE_MAIN_SERVER": (
False,
"Disables downloads from the main server. Enable only if you are experiencing "
"load problems.",
bool,
),
"SHIPPER_UPLOAD_VARIANTS": (
'{"gapps": "GApps","vanilla": "Vanilla (no GApps)","foss": "FOSS","goapps": '
'"GoApps (Android Go Edition GApps)"}',
Expand Down Expand Up @@ -284,6 +290,7 @@
"SHIPPER_DOWNLOADS_PAGE_DONATION_URL",
"SHIPPER_DOWNLOADS_PAGE_DONATION_MESSAGE",
),
"Download": ("SHIPPER_DOWNLOADS_PAGE_DISABLE_MAIN_SERVER",),
"Upload": (
"SHIPPER_UPLOAD_VARIANTS",
"SHIPPER_FILE_NAME_FORMAT",
Expand Down
23 changes: 13 additions & 10 deletions server/downloads/templates/downloads_build.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ <h2>{% translate "Mirrors" %}</h2>
</tr>
</thead>
<tbody>
<tr>
<td>{% translate "Main" %}</td>
<td>{% translate "Download builds from the main website." %}</td>
<td><a href="{{ object.zip_file.url }}"
class="btn btn-success btn-sm">
<i class="fa fa-file-archive" aria-hidden="true"></i>
{% translate "Download" %}
</a>
</td>
</tr>

{% if not downloads_disable_main_server %}
<tr>
<td>{% translate "Main" %}</td>
<td>{% translate "Download builds from the main website." %}</td>
<td><a href="{{ object.zip_file.url }}"
class="btn btn-success btn-sm">
<i class="fa fa-file-archive" aria-hidden="true"></i>
{% translate "Download" %}
</a>
</td>
</tr>
{% endif %}

{% for mirror in object.get_downloadable_mirrors %}
<tr>
Expand Down

0 comments on commit eb1bc08

Please sign in to comment.