diff --git a/server/api/handler.py b/server/api/handler.py index 824cf542..a3bc6b74 100644 --- a/server/api/handler.py +++ b/server/api/handler.py @@ -4,6 +4,7 @@ from django.conf import settings from constance import config +from config.constants import X86_DEVICE_CODENAMES from core.exceptions import UploadException from core.models import Build, Variant, X86Type from core.tasks import generate_checksum, mirror_build @@ -41,7 +42,7 @@ def handle_chunked_build(device, chunked_file): ) # If x86, check for x86 type - if filename_parts["codename"] == "x86": + if filename_parts["codename"] in X86_DEVICE_CODENAMES: x86_type_codenames = [x.codename for x in X86Type.objects.all()] if filename_parts["x86_type"] not in x86_type_codenames: raise UploadException( @@ -95,7 +96,7 @@ def handle_chunked_build(device, chunked_file): zip_file="{}/{}".format(device.codename, chunked_file.filename), enabled=True, ) - if filename_parts["codename"] == "x86": + if filename_parts["codename"] in X86_DEVICE_CODENAMES: build.x86_type = X86Type.objects.get(codename=filename_parts["x86_type"]) build.save() diff --git a/server/api/urls.py b/server/api/urls.py index 5e816fac..25474c0c 100644 --- a/server/api/urls.py +++ b/server/api/urls.py @@ -145,7 +145,7 @@ name="v1_updater_los", ), path( - "v1/updater/los/x86///", + "v1/updater/los////", V1UpdaterLOSX86.as_view(), name="v1_updater_los_x86", ), diff --git a/server/api/views/updater.py b/server/api/views/updater.py index 7f0ddc81..126114e8 100644 --- a/server/api/views/updater.py +++ b/server/api/views/updater.py @@ -5,10 +5,11 @@ from django.shortcuts import get_object_or_404 from rest_framework.permissions import AllowAny from rest_framework.response import Response -from rest_framework.status import HTTP_200_OK, HTTP_404_NOT_FOUND +from rest_framework.status import HTTP_200_OK, HTTP_404_NOT_FOUND, HTTP_400_BAD_REQUEST from rest_framework.views import APIView from api.views.utils import get_distributed_download_url +from config.constants import X86_DEVICE_CODENAMES from core.models import Device @@ -21,6 +22,12 @@ class V1UpdaterLOS(APIView): # noinspection PyMethodMayBeStatic def get(self, request, codename, variant): + if codename in X86_DEVICE_CODENAMES: + return Response( + {"message": "This endpoint is for arm devices only."}, + status=HTTP_400_BAD_REQUEST, + ) + try: device = get_object_or_404(Device, codename=codename) except Http404: @@ -48,12 +55,18 @@ class V1UpdaterLOSX86(APIView): permission_classes = [AllowAny] # noinspection PyMethodMayBeStatic - def get(self, request, x86_type, variant): + def get(self, request, codename, x86_type, variant): + if codename not in X86_DEVICE_CODENAMES: + return Response( + {"message": "This endpoint is for x86_64 devices only."}, + status=HTTP_400_BAD_REQUEST, + ) + try: - device = get_object_or_404(Device, codename="x86") + device = get_object_or_404(Device, codename=codename) except Http404: return Response( - {"message": "The x86 device has not been set up yet."}, + {"message": "The specified device does not exist!"}, status=HTTP_404_NOT_FOUND, ) diff --git a/server/config/constants.py b/server/config/constants.py new file mode 100644 index 00000000..98d3c30d --- /dev/null +++ b/server/config/constants.py @@ -0,0 +1 @@ +X86_DEVICE_CODENAMES = ["x86", "x86_64"]