MCPcopy Create free account
hub / github.com/IQEngine/IQEngine / get_meta_thumbnail

Function get_meta_thumbnail

api/handlers/metadata.py:123–165  ·  view source on GitHub ↗
(
    filepath: str,
    background_tasks: BackgroundTasks,
    datasource: DataSource = Depends(datasource_repo.get),
    azure_client: AzureBlobClient = Depends(AzureBlobClient),
    # access_allowed=Depends(check_access)
)

Source from the content-addressed store, hash-verified

121 response_class=StreamingResponse,
122)
123async 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(

Callers

nothing calls this directly

Calls 9

decryptFunction · 0.90
get_file_nameFunction · 0.90
get_content_typeFunction · 0.90
set_sas_tokenMethod · 0.80
set_account_keyMethod · 0.80
blob_existMethod · 0.80
get_new_thumbnailMethod · 0.80
get_blob_contentMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected