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

Function get_datasource_image

api/handlers/datasources.py:58–91  ·  view source on GitHub ↗
(
    account: str,
    container: str,
    datasources_collection: AgnosticCollection = Depends(datasource_repo.collection),
    access_allowed=Depends(check_access),
)

Source from the content-addressed store, hash-verified

56 "/api/datasources/{account}/{container}/image", response_class=StreamingResponse
57)
58async def get_datasource_image(
59 account: str,
60 container: str,
61 datasources_collection: AgnosticCollection = Depends(datasource_repo.collection),
62 access_allowed=Depends(check_access),
63):
64 if access_allowed is None:
65 raise HTTPException(status_code=403, detail="No Access")
66
67 # Create the imageURL with sasToken
68 datasource = await datasources_collection.find_one(
69 {
70 "account": account,
71 "container": container,
72 }
73 )
74 if not datasource:
75 raise HTTPException(status_code=404, detail="Datasource not found")
76
77 if not datasource["sasToken"]:
78 datasource["sasToken"] = "" # set to empty str if null
79
80 imageURL = add_URL_sasToken(
81 account, container, datasource["sasToken"], "", ApiType.IMAGE
82 )
83
84 async with httpx.AsyncClient() as client:
85 response = await client.get(imageURL.get_secret_value())
86 if response.status_code != 200:
87 raise HTTPException(status_code=404, detail="Image not found")
88
89 return StreamingResponse(
90 response.iter_bytes(), media_type=response.headers["Content-Type"]
91 )
92
93
94@router.get(

Callers

nothing calls this directly

Calls 2

add_URL_sasTokenFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected