Sync Bambuddy thumbnails to InvenTree parts

This commit is contained in:
2026-04-15 14:21:20 +03:00
parent 123100150b
commit beaa210466
6 changed files with 74 additions and 1 deletions

View File

@@ -21,7 +21,6 @@ class InvenTreeClient:
headers={
"Authorization": f"Token {settings.inventree_token}",
"Accept": "application/json",
"Content-Type": "application/json",
},
timeout=settings.http_timeout_seconds,
trust_env=False,
@@ -36,6 +35,9 @@ class InvenTreeClient:
async def get_stock_location(self) -> dict[str, Any]:
return await self._request("GET", f"/stock/location/{self.settings.inventree_stock_location_id}/")
async def get_part(self, part_id: int) -> dict[str, Any]:
return await self._request("GET", f"/part/{part_id}/")
async def find_part_by_ipn(self, ipn: str) -> dict[str, Any] | None:
for params in ({"IPN": ipn, "limit": 100}, {"search": ipn, "limit": 100}):
data = await self._request("GET", "/part/", params=params)
@@ -79,6 +81,16 @@ class InvenTreeClient:
}
return await self._request("POST", "/stock/", json=payload)
async def upload_part_image(self, *, part_id: int, content: bytes, filename: str, content_type: str) -> dict[str, Any]:
response = await self.client.patch(
f"/part/{part_id}/",
files={"image": (filename, content, content_type)},
)
if response.status_code >= 400:
body = response.text[:1000]
raise ExternalApiError(f"InvenTree PATCH /part/{part_id}/ image failed: HTTP {response.status_code}: {body}")
return response.json()
async def upsert_part_parameter(
self,
*,