|
|
@ -9,7 +9,7 @@ from django.db import transaction
|
|
|
|
from django.db.models import Q
|
|
|
|
from django.db.models import Q
|
|
|
|
from django.db.models import QuerySet
|
|
|
|
from django.db.models import QuerySet
|
|
|
|
from fastapi import APIRouter, Depends, status, Query, Request
|
|
|
|
from fastapi import APIRouter, Depends, status, Query, Request
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
from django_etebase import models
|
|
|
|
from django_etebase import models
|
|
|
|
from django_etebase.models import Collection, AccessLevels, CollectionMember
|
|
|
|
from django_etebase.models import Collection, AccessLevels, CollectionMember
|
|
|
@ -37,7 +37,7 @@ class ListMulti(BaseModel):
|
|
|
|
collectionTypes: t.List[bytes]
|
|
|
|
collectionTypes: t.List[bytes]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionItemRevisionOut(BaseModel):
|
|
|
|
class CollectionItemRevision(BaseModel):
|
|
|
|
uid: str
|
|
|
|
uid: str
|
|
|
|
meta: bytes
|
|
|
|
meta: bytes
|
|
|
|
deleted: bool
|
|
|
|
deleted: bool
|
|
|
@ -48,8 +48,8 @@ class CollectionItemRevisionOut(BaseModel):
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def from_orm_context(
|
|
|
|
def from_orm_context(
|
|
|
|
cls: t.Type["CollectionItemRevisionOut"], obj: models.CollectionItemRevision, context: Context
|
|
|
|
cls: t.Type["CollectionItemRevision"], obj: models.CollectionItemRevision, context: Context
|
|
|
|
) -> "CollectionItemRevisionOut":
|
|
|
|
) -> "CollectionItemRevision":
|
|
|
|
chunk_obj = obj.chunks_relation.get().chunk
|
|
|
|
chunk_obj = obj.chunks_relation.get().chunk
|
|
|
|
if context.prefetch == "auto":
|
|
|
|
if context.prefetch == "auto":
|
|
|
|
with open(chunk_obj.chunkFile.path, "rb") as f:
|
|
|
|
with open(chunk_obj.chunkFile.path, "rb") as f:
|
|
|
@ -59,13 +59,14 @@ class CollectionItemRevisionOut(BaseModel):
|
|
|
|
return cls(uid=obj.uid, meta=obj.meta, deleted=obj.deleted, chunks=[chunks])
|
|
|
|
return cls(uid=obj.uid, meta=obj.meta, deleted=obj.deleted, chunks=[chunks])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionItemOut(BaseModel):
|
|
|
|
class CollectionItemCommon(BaseModel):
|
|
|
|
uid: str
|
|
|
|
uid: str
|
|
|
|
version: int
|
|
|
|
version: int
|
|
|
|
encryptionKey: t.Optional[bytes]
|
|
|
|
encryptionKey: t.Optional[bytes]
|
|
|
|
etag: t.Optional[str]
|
|
|
|
content: CollectionItemRevision
|
|
|
|
content: CollectionItemRevisionOut
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionItemOut(CollectionItemCommon):
|
|
|
|
class Config:
|
|
|
|
class Config:
|
|
|
|
orm_mode = True
|
|
|
|
orm_mode = True
|
|
|
|
|
|
|
|
|
|
|
@ -82,9 +83,16 @@ class CollectionItemOut(BaseModel):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionOut(BaseModel):
|
|
|
|
class CollectionItemIn(CollectionItemCommon):
|
|
|
|
collectionKey: bytes
|
|
|
|
etag: t.Optional[str]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionCommon(BaseModel):
|
|
|
|
collectionType: bytes
|
|
|
|
collectionType: bytes
|
|
|
|
|
|
|
|
collectionKey: bytes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionOut(CollectionCommon):
|
|
|
|
accessLevel: AccessLevels
|
|
|
|
accessLevel: AccessLevels
|
|
|
|
stoken: str
|
|
|
|
stoken: str
|
|
|
|
item: CollectionItemOut
|
|
|
|
item: CollectionItemOut
|
|
|
@ -103,35 +111,23 @@ class CollectionOut(BaseModel):
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionIn(CollectionCommon):
|
|
|
|
|
|
|
|
item: CollectionItemIn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListResponse(BaseModel):
|
|
|
|
class ListResponse(BaseModel):
|
|
|
|
data: t.List[CollectionOut]
|
|
|
|
data: t.List[CollectionOut]
|
|
|
|
stoken: t.Optional[str]
|
|
|
|
stoken: t.Optional[str]
|
|
|
|
done: bool
|
|
|
|
done: bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ItemIn(BaseModel):
|
|
|
|
|
|
|
|
uid: str
|
|
|
|
|
|
|
|
version: int
|
|
|
|
|
|
|
|
etag: t.Optional[str]
|
|
|
|
|
|
|
|
content: CollectionItemRevisionOut
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionIn(BaseModel):
|
|
|
|
|
|
|
|
collectionType: bytes
|
|
|
|
|
|
|
|
collectionKey: bytes
|
|
|
|
|
|
|
|
item: ItemIn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ItemDepIn(BaseModel):
|
|
|
|
class ItemDepIn(BaseModel):
|
|
|
|
etag: str
|
|
|
|
etag: str
|
|
|
|
uid: str
|
|
|
|
uid: str
|
|
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
|
|
|
orm_mode = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ItemBatchIn(BaseModel):
|
|
|
|
class ItemBatchIn(BaseModel):
|
|
|
|
items: t.List[ItemIn]
|
|
|
|
items: t.List[CollectionItemIn]
|
|
|
|
deps: t.Optional[ItemDepIn]
|
|
|
|
deps: t.Optional[ItemDepIn]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -262,7 +258,6 @@ def item_bulk_common(data: ItemBatchIn, user: User, stoken: str, uid: str, valid
|
|
|
|
raise ValidationError("stale_stoken", "Stoken is too old", status_code=status.HTTP_409_CONFLICT)
|
|
|
|
raise ValidationError("stale_stoken", "Stoken is too old", status_code=status.HTTP_409_CONFLICT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def item_create():
|
|
|
|
def item_create():
|
|
|
|
pass #
|
|
|
|
pass #
|
|
|
|
|
|
|
|
|
|
|
|