Skip to content

Commit

Permalink
fix(server): allow x86_64 devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswpark committed Nov 28, 2023
1 parent 9429c3f commit 2885464
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
5 changes: 3 additions & 2 deletions server/api/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion server/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
name="v1_updater_los",
),
path(
"v1/updater/los/x86/<slug:x86_type>/<slug:variant>/",
"v1/updater/los/<slug:codename>/<slug:x86_type>/<slug:variant>/",
V1UpdaterLOSX86.as_view(),
name="v1_updater_los_x86",
),
Expand Down
21 changes: 17 additions & 4 deletions server/api/views/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down
1 change: 1 addition & 0 deletions server/config/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
X86_DEVICE_CODENAMES = ["x86", "x86_64"]

0 comments on commit 2885464

Please sign in to comment.