(
filepath: str,
background_tasks: BackgroundTasks,
datasource: DataSource = Depends(datasource_repo.get),
azure_client: AzureBlobClient = Depends(AzureBlobClient),
# access_allowed=Depends(check_access)
)
| 121 | response_class=StreamingResponse, |
| 122 | ) |
| 123 | async def get_meta_thumbnail( |
| 124 | filepath: str, |
| 125 | background_tasks: BackgroundTasks, |
| 126 | datasource: DataSource = Depends(datasource_repo.get), |
| 127 | azure_client: AzureBlobClient = Depends(AzureBlobClient), |
| 128 | # access_allowed=Depends(check_access) |
| 129 | ): |
| 130 | # access_allowed is always None because the API url is referenced directly in the UI HTML |
| 131 | # No authorization header is added to the request so the access_allowed is always None |
| 132 | if not datasource: |
| 133 | raise HTTPException(status_code=404, detail="Datasource not found") |
| 134 | |
| 135 | sas_token = datasource.sasToken.get_secret_value() if datasource.sasToken else None |
| 136 | if sas_token is not None: |
| 137 | azure_client.set_sas_token(decrypt(sas_token)) |
| 138 | |
| 139 | account_key = ( |
| 140 | datasource.accountKey.get_secret_value() if datasource.accountKey else None |
| 141 | ) |
| 142 | if account_key is not None: |
| 143 | azure_client.set_account_key(decrypt(account_key)) |
| 144 | |
| 145 | thumbnail_path = get_file_name(filepath, ApiType.THUMB) |
| 146 | content_type = get_content_type(ApiType.THUMB) |
| 147 | if not await azure_client.blob_exist(thumbnail_path): |
| 148 | metadata = await metadata_repo.get( |
| 149 | datasource.account, |
| 150 | datasource.container, |
| 151 | filepath, |
| 152 | ) |
| 153 | if not metadata: |
| 154 | raise HTTPException(status_code=404, detail="Metadata not found") |
| 155 | datatype = metadata.globalMetadata.core_datatype |
| 156 | image = await azure_client.get_new_thumbnail( |
| 157 | data_type=datatype, filepath=filepath |
| 158 | ) |
| 159 | # Upload the thumbnail in the background |
| 160 | background_tasks.add_task( |
| 161 | azure_client.upload_blob, filepath=thumbnail_path, data=image |
| 162 | ) |
| 163 | return Response(content=image, media_type=content_type) |
| 164 | content = await azure_client.get_blob_content(thumbnail_path) |
| 165 | return Response(content=content, media_type=content_type) |
| 166 | |
| 167 | |
| 168 | @router.get( |
nothing calls this directly
no test coverage detected