From af78eed6ec9d22e5ac907a3563d5e69e3403d597 Mon Sep 17 00:00:00 2001 From: Eric Park Date: Wed, 11 Oct 2023 15:41:44 -0400 Subject: [PATCH 1/7] feat(docker): add internal configuration to nginx for checking downloads --- docker/nginx/nginx.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index 953bf6ae..f5a3a2b5 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -42,6 +42,7 @@ server { limit_req zone=media burst=3 nodelay; limit_conn addr 1; limit_rate 3m; + internal; alias /home/shipper/web/media/; } From 530a27dd88f17fee7c9d649b2598a98e90c7f2eb Mon Sep 17 00:00:00 2001 From: Eric Park Date: Wed, 11 Oct 2023 15:42:20 -0400 Subject: [PATCH 2/7] feat(server): add setting to adjust archive download throttle speed --- server/config/settings.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/config/settings.py b/server/config/settings.py index 0f64d4b3..ef335142 100644 --- a/server/config/settings.py +++ b/server/config/settings.py @@ -262,6 +262,11 @@ "load problems.", bool, ), + "SHIPPER_DOWNLOADS_ARCHIVE_THROTTLE": ( + 1, + "Throttles the download speed of archived builds, in MB/s.", + int, + ), "SHIPPER_UPLOAD_VARIANTS": ( '{"gapps": "GApps","vanilla": "Vanilla (no GApps)","foss": "FOSS","goapps": ' '"GoApps (Android Go Edition GApps)"}', @@ -296,7 +301,10 @@ "SHIPPER_DOWNLOADS_PAGE_DONATION_URL", "SHIPPER_DOWNLOADS_PAGE_DONATION_MESSAGE", ), - "Download": ("SHIPPER_DOWNLOADS_DISABLE_MAIN_SERVER",), + "Download": ( + "SHIPPER_DOWNLOADS_DISABLE_MAIN_SERVER", + "SHIPPER_DOWNLOADS_ARCHIVE_THROTTLE", + ), "Upload": ( "SHIPPER_UPLOAD_VARIANTS", "SHIPPER_FILE_NAME_FORMAT", From 05d611700d3983d948d7a1ea765c618bf6174b4f Mon Sep 17 00:00:00 2001 From: Eric Park Date: Wed, 11 Oct 2023 15:42:45 -0400 Subject: [PATCH 3/7] feat(server): add download view for checking download requests --- server/downloads/urls.py | 4 ++++ server/downloads/views.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/server/downloads/urls.py b/server/downloads/urls.py index 6a2b246b..02d969fa 100644 --- a/server/downloads/urls.py +++ b/server/downloads/urls.py @@ -5,6 +5,7 @@ DownloadsDeviceView, DownloadsMainView, LanguageSwitchView, + download_view, ) urlpatterns = [ @@ -20,4 +21,7 @@ name="downloads_build", ), path("language_switch/", LanguageSwitchView.as_view(), name="language_switch"), + path( + "media///", download_view, name="download_view" + ), ] diff --git a/server/downloads/views.py b/server/downloads/views.py index afee3d15..5bf25826 100644 --- a/server/downloads/views.py +++ b/server/downloads/views.py @@ -1,9 +1,12 @@ +from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.urls import reverse from django.views.generic import DetailView, ListView, TemplateView from django.shortcuts import render from core.models import Build, Device +from constance import config + class DownloadsMainView(TemplateView): template_name = "downloads_main.html" @@ -53,3 +56,15 @@ def get(self, request, *args, **kwargs): if not redirect_url: redirect_url = "/" return render(request, self.template_name, {"redirect_to": redirect_url}) + + +def download_view(request, codename, file_name): + build = get_object_or_404(Build, file_name=file_name, device__codename=codename) + response = HttpResponse() + response["X-Accel-Redirect"] = f"/media/{codename}/{file_name}" + + if build.is_archived: + limit_speed = config.SHIPPER_DOWNLOADS_ARCHIVE_THROTTLE * 1000 + response["X-Accel-Limit-Rate"] = str(limit_speed) + + return response From 0ebe0c017594f40f33a72d186fcd93be49e3f92e Mon Sep 17 00:00:00 2001 From: Eric Park Date: Wed, 11 Oct 2023 15:43:12 -0400 Subject: [PATCH 4/7] style(server): remove unnecessary import --- server/downloads/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/downloads/views.py b/server/downloads/views.py index 5bf25826..f94527b0 100644 --- a/server/downloads/views.py +++ b/server/downloads/views.py @@ -1,7 +1,7 @@ from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.urls import reverse -from django.views.generic import DetailView, ListView, TemplateView +from django.views.generic import DetailView, TemplateView from django.shortcuts import render from core.models import Build, Device From 237711bac9bdee228757be804d31462f6557ddf4 Mon Sep 17 00:00:00 2001 From: Eric Park Date: Wed, 11 Oct 2023 15:47:12 -0400 Subject: [PATCH 5/7] fix(docker): add internal directive to dev nginx config --- docker/dev/nginx/nginx.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/dev/nginx/nginx.conf b/docker/dev/nginx/nginx.conf index 42613aeb..de847f7c 100644 --- a/docker/dev/nginx/nginx.conf +++ b/docker/dev/nginx/nginx.conf @@ -72,6 +72,7 @@ server { limit_req zone=media burst=3 nodelay; limit_conn addr 1; limit_rate 3m; + internal; alias /home/shipper/web/media/; } From f30382ebcf25cc644258cd0ac83a11420f106284 Mon Sep 17 00:00:00 2001 From: Eric Park Date: Wed, 11 Oct 2023 16:11:05 -0400 Subject: [PATCH 6/7] feat(server): show archived build warning to users --- server/downloads/templates/downloads_build.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/downloads/templates/downloads_build.html b/server/downloads/templates/downloads_build.html index 5c912c27..14c0913f 100644 --- a/server/downloads/templates/downloads_build.html +++ b/server/downloads/templates/downloads_build.html @@ -29,6 +29,14 @@

{% blocktranslate %}Downloads for {{ object }}{% endblocktranslate %}

{% include 'debug_warning.html' %} + + {% if object.is_archived == True %} + + {% endif %} + {% include 'donation_alert.html' %}

{% translate "Build information" %}

From 44fad79c0de33b6b25647c73488b1e6a9c345551 Mon Sep 17 00:00:00 2001 From: Eric Park Date: Wed, 11 Oct 2023 16:12:07 -0400 Subject: [PATCH 7/7] style(server): fix typo --- server/downloads/templates/downloads_build.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/downloads/templates/downloads_build.html b/server/downloads/templates/downloads_build.html index 14c0913f..5aaa2888 100644 --- a/server/downloads/templates/downloads_build.html +++ b/server/downloads/templates/downloads_build.html @@ -33,7 +33,7 @@

{% blocktranslate %}Downloads for {{ object }}{% endblocktranslate %}

{% if object.is_archived == True %} {% endif %}