|
19 | 19 | from datetime import datetime
|
20 | 20 |
|
21 | 21 | from apify_client.clients import KeyValueStoreClientAsync
|
22 |
| - |
23 |
| - from apify import Configuration |
| 22 | + from crawlee.configuration import Configuration |
24 | 23 |
|
25 | 24 | logger = getLogger(__name__)
|
26 | 25 |
|
@@ -70,8 +69,13 @@ async def open(
|
70 | 69 | name: str | None,
|
71 | 70 | configuration: Configuration,
|
72 | 71 | ) -> ApifyKeyValueStoreClient:
|
73 |
| - token = configuration.token |
74 |
| - api_url = configuration.api_base_url |
| 72 | + token = getattr(configuration, 'token', None) |
| 73 | + if not token: |
| 74 | + raise ValueError(f'Apify storage client requires a valid token in Configuration (token={token}).') |
| 75 | + |
| 76 | + api_url = getattr(configuration, 'api_base_url', None) |
| 77 | + if not api_url: |
| 78 | + raise ValueError(f'Apify storage client requires a valid API URL in Configuration (api_url={api_url}).') |
75 | 79 |
|
76 | 80 | # Otherwise, create a new one.
|
77 | 81 | apify_client_async = ApifyClientAsync(
|
@@ -101,7 +105,8 @@ async def open(
|
101 | 105 |
|
102 | 106 | @override
|
103 | 107 | async def purge(self) -> None:
|
104 |
| - # TODO: better |
| 108 | + # TODO: better? |
| 109 | + # https://github.com/apify/apify-sdk-python/issues/469 |
105 | 110 | async with self._lock:
|
106 | 111 | await self._api_client.delete()
|
107 | 112 |
|
@@ -147,7 +152,13 @@ async def iterate_keys(
|
147 | 152 | list_key_page = KeyValueStoreListKeysPage.model_validate(response)
|
148 | 153 |
|
149 | 154 | for item in list_key_page.items:
|
150 |
| - yield item |
| 155 | + # Convert KeyValueStoreKeyInfo to KeyValueStoreRecordMetadata |
| 156 | + record_metadata = KeyValueStoreRecordMetadata( |
| 157 | + key=item.key, |
| 158 | + size=item.size, |
| 159 | + content_type='application/octet-stream', # Content type not available from list_keys |
| 160 | + ) |
| 161 | + yield record_metadata |
151 | 162 | count += 1
|
152 | 163 |
|
153 | 164 | # If we've reached the limit, stop yielding
|
|
0 commit comments