Features: 1) Use uuid.UUID for decoding encoded UUIDs to ensure proper handling of byte data;

Fixes: 1) Remove deprecated `force_str` usage for decoding encoded UUIDs;

Extra: 1) Add missing `uuid` module import; 2) Minor code cleanup in `core/views.py`.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-08-13 19:45:41 +03:00
parent 5d9cd47e72
commit 5d8f528dfd

View file

@ -1,5 +1,6 @@
import mimetypes
import os
import uuid as uuid_module
import requests
from django.contrib.sitemaps.views import index as _sitemap_index_view
@ -8,7 +9,6 @@ from django.core.cache import cache
from django.core.exceptions import BadRequest
from django.http import FileResponse, Http404, JsonResponse
from django.shortcuts import redirect
from django.utils.encoding import force_str
from django.utils.http import urlsafe_base64_decode
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import cache_page
@ -468,7 +468,10 @@ def download_digital_asset_view(request, *args, **kwargs):
a JsonResponse with an error message if an error occurs during the process.
"""
try:
uuid = force_str(urlsafe_base64_decode(str(kwargs.get("encoded_uuid"))))
uuid_bytes = urlsafe_base64_decode(str(kwargs.get("encoded_uuid")))
uuid = str(uuid_module.UUID(bytes=uuid_bytes))
download = DigitalAssetDownload.objects.get(order_product__uuid=uuid)
if download.num_downloads >= 1: