1
0
mirror of https://github.com/etesync/server synced 2024-12-01 13:08:10 +00:00

implement chunk_download.

This commit is contained in:
Tom Hacohen 2020-12-28 18:25:06 +02:00
parent 53b22602b2
commit c7f09d3fef

View File

@ -7,6 +7,7 @@ from django.core.files.base import ContentFile
from django.db import transaction, IntegrityError from django.db import transaction, IntegrityError
from django.db.models import Q, QuerySet from django.db.models import Q, QuerySet
from fastapi import APIRouter, Depends, status, Request from fastapi import APIRouter, Depends, status, Request
from fastapi.responses import FileResponse
from django_etebase import models from django_etebase import models
from .authentication import get_authenticated_user from .authentication import get_authenticated_user
@ -568,3 +569,17 @@ async def chunk_update(
await chunk_save(chunk_uid, collection, content_file) await chunk_save(chunk_uid, collection, content_file)
except IntegrityError: except IntegrityError:
raise HttpError("chunk_exists", "Chunk already exists.", status_code=status.HTTP_409_CONFLICT) raise HttpError("chunk_exists", "Chunk already exists.", status_code=status.HTTP_409_CONFLICT)
@item_router.get(
"/item/{item_uid}/chunk/{chunk_uid}/download/",
dependencies=PERMISSIONS_READ,
)
def chunk_download(
chunk_uid: str,
collection: models.Collection = Depends(get_collection),
):
chunk = get_object_or_404(collection.chunks, uid=chunk_uid)
filename = chunk.chunkFile.path
return FileResponse(filename, media_type="application/octet-stream")