Skip to content

Commit

Permalink
makes API endpoint with or without account slug depending on URL pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
smirolo committed Feb 28, 2024
1 parent 8e755c0 commit 0c5c01c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pages/api/assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, Djaodjin Inc.
# Copyright (c) 2024, Djaodjin Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -36,7 +36,8 @@
from rest_framework.response import Response as HttpResponse

from .. import settings
from ..compat import force_str, gettext_lazy as _, reverse, urljoin, urlparse
from ..compat import (NoReverseMatch, force_str, gettext_lazy as _, reverse,
urljoin, urlparse)
from ..mixins import AccountMixin
from ..serializers import AssetSerializer

Expand Down Expand Up @@ -172,7 +173,7 @@ def process_upload(request, account=None, location=None, is_public_asset=None,
if prefix.startswith(media_prefix):
prefix = prefix[len(media_prefix) + 1:]
storage_key_name = "%s%s%s" % (prefix,
hashlib.sha256(uploaded_file.read()).hexdigest(), ext)
hashlib.sha256(uploaded_file.read()).hexdigest(), ext)

dst_key_name = "%s/%s" % (media_prefix, storage_key_name)
LOGGER.info("S3 bucket %s: copy %s to %s",
Expand Down Expand Up @@ -228,8 +229,12 @@ def process_upload(request, account=None, location=None, is_public_asset=None,
path = urlparse(location).path.lstrip(URL_PATH_SEP)
if path.startswith(media_prefix):
path = path[len(media_prefix):].lstrip(URL_PATH_SEP)
location = request.build_absolute_uri(
reverse('pages_api_asset', args=(path,)))
try:
location = request.build_absolute_uri(
reverse('pages_api_asset', args=(account, path,)))
except NoReverseMatch:
location = request.build_absolute_uri(
reverse('pages_api_asset', args=(path,)))

return ({
'location': location,
Expand Down

0 comments on commit 0c5c01c

Please sign in to comment.