This commit is contained in:
j3d1 2026-08-16 23:52:58 +02:00
parent 3b494dfa37
commit 0f51f6e33f
14 changed files with 534 additions and 356 deletions

View file

@ -53,10 +53,10 @@ def post_item_file(request, item_id):
def get_staged_files(request, workflow_id):
try:
workflow = WorkflowInstance.objects.get(id=workflow_id, owner=request.user)
# Staged files are private working state the client already holds in full (name, size,
# mime_type, base64 data) from the moment it read them off disk/camera - the only thing
# it can't already know is whether/under what hash the upload was persisted, so that's
# all this returns, unlike the fuller FileSerializer representation item_files uses.
# Hash alone identifies a staged file (client and server hash content the same way, and
# bytes are fetchable from a hash-derived storage path) - useful mainly for discovering
# what another session/device already staged on this workflow, unlike the fuller
# FileSerializer representation item_files uses.
return Response(list(workflow.staged_files.values_list('hash', flat=True)))
except WorkflowInstance.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
@ -95,6 +95,7 @@ def delete_item_file(request, item_id, file_id, format=None): # /item_files/
item.files.remove(file_id)
if file.connected_items.count() == 0 and file.profile_picture_users.count() == 0 \
and file.staged_by_workflows.count() == 0:
file.file.delete(save=False)
file.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
except InventoryItem.DoesNotExist:
@ -123,6 +124,7 @@ def delete_staged_file(request, workflow_id, file_hash, format=None): # /staged
workflow.staged_files.remove(file)
if file.connected_items.count() == 0 and file.profile_picture_users.count() == 0 \
and file.staged_by_workflows.count() == 0:
file.file.delete(save=False)
file.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
except WorkflowInstance.DoesNotExist:

View file

@ -126,6 +126,7 @@ class WorkflowInstanceViewSet(viewsets.ModelViewSet):
for file in File.objects.filter(id__in=staged_file_ids):
if file.connected_items.count() == 0 and file.profile_picture_users.count() == 0 \
and file.staged_by_workflows.count() == 0:
file.file.delete(save=False)
file.delete()

View file

@ -203,9 +203,11 @@ class InventoryItemSerializer(serializers.ModelSerializer):
class WorkflowInstanceSerializer(serializers.ModelSerializer):
owner = serializers.StringRelatedField(read_only=True)
# The client already holds the full file (name, size, mime_type, base64 data) for anything it
# staged itself - hash is the only thing it can't already know, so that's all this exposes,
# unlike InventoryItemSerializer.files which needs the fuller FileSerializer representation.
# Hash is enough to identify a staged file (the client computes the same SHA-256 the backend
# does, and can fetch bytes from a hash-derived storage path) - for anything staged by *this*
# session there's nothing more to say, and for a file staged elsewhere (another device/tab),
# hash is what lets this session recognize and fetch it. Unlike InventoryItemSerializer.files,
# no fuller FileSerializer representation is needed here.
staged_files = serializers.SerializerMethodField()
class Meta: