Skip to content

Commit

Permalink
Splitting out blob metdata from file
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-widmann committed May 14, 2024
1 parent a29362d commit fd53b5b
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions guillotina_gcloudstorage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from guillotina.utils import get_authenticated_user_id
from guillotina.utils import get_current_request
from guillotina.utils import to_str
from guillotina.interfaces.files import ICloudBlob
from guillotina.files.field import BlobMetadata
from guillotina_gcloudstorage.interfaces import IGCloudBlobStore
from guillotina_gcloudstorage.interfaces import IGCloudFile
from guillotina_gcloudstorage.interfaces import IGCloudFileField
Expand Down Expand Up @@ -105,16 +105,10 @@ def dictfile_converter(value, field):
return GCloudFile(**value)


@implementer(IGCloudFile, ICloudBlob)
@implementer(IGCloudFile)
class GCloudFile(BaseCloudFile):
"""File stored in a GCloud, with a filename."""

def __init__(self, key: str, bucket: str, size: int, createdTime: Optional[datetime]):
self.key = key
self.bucket = bucket
self.size = size
self.createdTime = createdTime


def _is_uploaded_file(file):
return file is not None and isinstance(file, GCloudFile) and file.uri is not None
Expand Down Expand Up @@ -621,13 +615,13 @@ async def generate_download_signed_url(
return blob.generate_signed_url(**request_args)


async def get_blobs(self, page_token: Optional[str] = None, prefix=None, max_keys=1000) -> Tuple[List[ICloudBlob], str]:
async def get_blobs(self, page_token: Optional[str] = None, prefix=None, max_keys=1000) -> Tuple[List[BlobMetadata], str]:
"""
Get a page of items from the bucket
"""
page = await self.iterate_bucket_page(page_token, prefix)
blobs = [
GCloudFile(
BlobMetadata(
name = item.get("name"),
bucket = item.get("bucket"),
createdTime = item.get("timeCreated"),
Expand All @@ -636,7 +630,7 @@ async def get_blobs(self, page_token: Optional[str] = None, prefix=None, max_key
for item
in page.get("items", [])
]
next_page_token = page.get("nextPageToken")
next_page_token = page.get("nextPageToken", None)

return blobs, next_page_token

Expand Down

0 comments on commit fd53b5b

Please sign in to comment.