|
54 | 54 | from .dsm_factory import BaseDataManager |
55 | 55 | from .exceptions.errors import ( |
56 | 56 | FileAccessRightError, |
| 57 | + FileFilterInvalidError, |
57 | 58 | FileMetaDataNotFoundError, |
58 | 59 | LinkAlreadyExistsError, |
59 | 60 | ProjectAccessRightError, |
@@ -146,8 +147,51 @@ async def list_files_paginated( |
146 | 147 | offset: NonNegativeInt, |
147 | 148 | ) -> tuple[list[FileMetaData], TotalNumber]: |
148 | 149 | """returns a page of the file meta data a user has access to""" |
149 | | - get_s3_client(self.app).list_objects_paginated() |
150 | | - return [], 0 |
| 150 | + |
| 151 | + # if we have a file_filter, that means that we have at least a partial project ID |
| 152 | + # TODO: what about api/{uuid} or anything else? this should be handled at some point |
| 153 | + try: |
| 154 | + project_id = ProjectID(file_filter.parts[0]) if file_filter else None |
| 155 | + except ValueError as exc: |
| 156 | + raise FileFilterInvalidError( |
| 157 | + user_id=user_id, file_filter=file_filter |
| 158 | + ) from exc |
| 159 | + |
| 160 | + async with self.engine.connect() as conn: |
| 161 | + if project_id: |
| 162 | + project_access_rights = await get_project_access_rights( |
| 163 | + conn=conn, user_id=user_id, project_id=project_id |
| 164 | + ) |
| 165 | + if not project_access_rights.read: |
| 166 | + raise ProjectAccessRightError( |
| 167 | + access_right="read", project_id=project_id |
| 168 | + ) |
| 169 | + accessible_projects_ids = [project_id] |
| 170 | + else: |
| 171 | + accessible_projects_ids = await get_readable_project_ids(conn, user_id) |
| 172 | + |
| 173 | + file_and_directory_meta_data = await file_meta_data.list_direct_children( |
| 174 | + conn, |
| 175 | + filter_by_user_id=user_id, |
| 176 | + file_id_prefix=None, |
| 177 | + is_directory=None, |
| 178 | + partial_file_id=f"{file_filter}" if file_filter else None, |
| 179 | + sha256_checksum=None, |
| 180 | + limit=limit, |
| 181 | + offset=offset, |
| 182 | + ) |
| 183 | + |
| 184 | + list_s3_objects = await get_s3_client(self.app).list_objects( |
| 185 | + bucket=self.simcore_bucket_name, |
| 186 | + prefix=file_filter, |
| 187 | + start_after=None, |
| 188 | + limit=limit, |
| 189 | + ) |
| 190 | + # TODO: computing the total can be expensive, do we want that? |
| 191 | + total = limit + 1 |
| 192 | + if len(list_s3_objects) < limit: |
| 193 | + total = len(list_s3_objects) |
| 194 | + return [], total |
151 | 195 |
|
152 | 196 | async def list_files( # noqa C901 |
153 | 197 | self, |
|
0 commit comments