fix: asset key validation

This commit is contained in:
Bavisetti Narayan 2023-08-22 18:12:39 +05:30
parent 68b438ab1a
commit 660e181627

View File

@ -18,10 +18,22 @@ class FileAssetEndpoint(BaseAPIView):
""" """
def get(self, request, workspace_id, asset_key): def get(self, request, workspace_id, asset_key):
asset_key = str(workspace_id) + "/" + asset_key try:
files = FileAsset.objects.filter(asset=asset_key) asset_key = str(workspace_id) + "/" + asset_key
serializer = FileAssetSerializer(files, context={"request": request}, many=True) files = FileAsset.objects.filter(asset=asset_key)
return Response(serializer.data) serializer = FileAssetSerializer(files, context={"request": request}, many=True)
if files.exists():
serializer = FileAssetSerializer(files, context={"request": request}, many=True)
return Response({"data": serializer.data, "status": True}, status=status.HTTP_200_OK)
else:
return Response({"error": "Asset key does not exist", "status": False}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def post(self, request, slug): def post(self, request, slug):
try: try: