forked from github/plane
Compare commits
3 Commits
preview
...
fix/file_u
Author | SHA1 | Date | |
---|---|---|---|
|
0fe3dfddc6 | ||
|
77b7d43042 | ||
|
619b392b37 |
@ -12,3 +12,14 @@ class FileAssetSerializer(BaseSerializer):
|
||||
"created_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
# Extract everything after the first slash in the asset field
|
||||
asset_id = instance.asset.name.split('/', 1)[-1]
|
||||
|
||||
# Include only the asset id in the serialized data
|
||||
representation['asset'] = asset_id
|
||||
|
||||
return representation
|
||||
|
@ -4,6 +4,7 @@ from django.urls import path
|
||||
from plane.api.views import (
|
||||
FileAssetEndpoint,
|
||||
UserAssetsEndpoint,
|
||||
AssetsEndpoint,
|
||||
)
|
||||
|
||||
|
||||
@ -18,6 +19,11 @@ urlpatterns = [
|
||||
FileAssetEndpoint.as_view(),
|
||||
name="file-assets",
|
||||
),
|
||||
path(
|
||||
"<str:slug>/<str:asset_key>/",
|
||||
AssetsEndpoint.as_view(),
|
||||
name="file-assets",
|
||||
),
|
||||
path(
|
||||
"users/file-assets/",
|
||||
UserAssetsEndpoint.as_view(),
|
||||
|
@ -67,7 +67,7 @@ from .cycle import (
|
||||
CycleFavoriteViewSet,
|
||||
TransferCycleIssueEndpoint,
|
||||
)
|
||||
from .asset import FileAssetEndpoint, UserAssetsEndpoint
|
||||
from .asset import FileAssetEndpoint, UserAssetsEndpoint, AssetsEndpoint
|
||||
from .issue import (
|
||||
IssueViewSet,
|
||||
IssueListEndpoint,
|
||||
|
@ -1,13 +1,14 @@
|
||||
# Third party imports
|
||||
from rest_framework import status
|
||||
from django.http import StreamingHttpResponse
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.parsers import MultiPartParser, FormParser
|
||||
from sentry_sdk import capture_exception
|
||||
from django.conf import settings
|
||||
# Module imports
|
||||
from .base import BaseAPIView
|
||||
from plane.db.models import FileAsset, Workspace
|
||||
from plane.api.serializers import FileAssetSerializer
|
||||
from plane.api.permissions.workspace import WorkspaceEntityPermission
|
||||
|
||||
|
||||
class FileAssetEndpoint(BaseAPIView):
|
||||
@ -73,3 +74,16 @@ class UserAssetsEndpoint(BaseAPIView):
|
||||
# Delete the file object
|
||||
file_asset.delete()
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
class AssetsEndpoint(BaseAPIView):
|
||||
|
||||
permission_classes = [WorkspaceEntityPermission]
|
||||
parser_classes = (MultiPartParser, FormParser)
|
||||
|
||||
def get(self, request, slug, asset_key):
|
||||
workspace = Workspace.objects.get(slug=slug)
|
||||
asset_key = str(workspace.id) + "/" + asset_key
|
||||
file_asset = FileAsset.objects.get(workspace_id=workspace.id, asset=asset_key)
|
||||
response = StreamingHttpResponse(file_asset.asset.open(mode='rb'), content_type='application/octet-stream')
|
||||
return response
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user