From b39f7951e292588092365964f7c2fc3f317c54d3 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 28 Dec 2020 10:18:35 +0200 Subject: [PATCH] chunk first-type. --- etebase_fastapi/collection.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/etebase_fastapi/collection.py b/etebase_fastapi/collection.py index fad49aa..20d79e0 100644 --- a/etebase_fastapi/collection.py +++ b/etebase_fastapi/collection.py @@ -515,3 +515,31 @@ def item_batch( collection_uid: str, data: ItemBatchIn, stoken: t.Optional[str] = None, user: User = Depends(get_authenticated_user) ): return item_bulk_common(data, user, stoken, collection_uid, validate_etag=False) + + +# Chunks + + +@item_router.put("/item/{item_uid}/chunk/{chunk_uid}/", dependencies=[Depends(has_write_access)], status_code=status.HTTP_201_CREATED) +def chunk_update( + limit: int = 50, + iterator: t.Optional[str] = None, + prefetch: Prefetch = PrefetchQuery, + user: User = Depends(get_authenticated_user), + collection: models.Collection = Depends(get_collection), +): + # IGNORED FOR NOW: col_it = get_object_or_404(col.items, uid=collection_item_uid) + + data = { + "uid": chunk_uid, + "chunkFile": request.data["file"], + } + + serializer = self.get_serializer_class()(data=data) + serializer.is_valid(raise_exception=True) + try: + serializer.save(collection=col) + except IntegrityError: + return Response( + {"code": "chunk_exists", "detail": "Chunk already exists."}, status=status.HTTP_409_CONFLICT + )