Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/comfy_low/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ def post_assets(
tags: list[str] | None = None,
idempotency_key: str | None = None,
file_size: int | None = None,
expires_in: int | None = None,
timeout: Any = _UNSET,
) -> Asset:
"""POST /api/v2/assets — streaming multipart upload."""
Expand All @@ -574,8 +573,6 @@ def post_assets(
# One part per tag — repeating the field name is the multipart/form
# convention for a list, and a dict would silently drop all but one.
fields.extend(("tags", t) for t in tags)
if expires_in is not None:
fields.append(("expires_in", str(expires_in)))
boundary = _new_boundary()
body, length = _multipart.build_multipart(
boundary,
Expand All @@ -600,7 +597,6 @@ def asset_from_hash(
*,
file_path: str | None = None,
tags: list[str] | None = None,
expires_in: int | None = None,
timeout: Any = _UNSET,
) -> Asset:
"""POST /api/v2/assets/from-hash — dedup mint over existing bytes."""
Expand All @@ -609,8 +605,6 @@ def asset_from_hash(
payload["file_path"] = file_path
if tags is not None:
payload["tags"] = tags
if expires_in is not None:
payload["expires_in"] = expires_in
resp = self.raw_request("POST", "/assets/from-hash", json=payload, timeout=timeout)
data = self._p.parse_or_raise(resp, (200, 201))
return Asset.model_validate(data)
Expand Down Expand Up @@ -923,7 +917,6 @@ async def post_assets(
tags: list[str] | None = None,
idempotency_key: str | None = None,
file_size: int | None = None,
expires_in: int | None = None,
timeout: Any = _UNSET,
) -> Asset:
if file_size is None:
Expand All @@ -937,8 +930,6 @@ async def post_assets(
if tags:
# One part per tag — see the sync ``post_assets`` for why a dict is wrong.
fields.extend(("tags", t) for t in tags)
if expires_in is not None:
fields.append(("expires_in", str(expires_in)))
boundary = _new_boundary()
body, length = _multipart.build_multipart(
boundary,
Expand Down Expand Up @@ -973,16 +964,13 @@ async def asset_from_hash(
*,
file_path: str | None = None,
tags: list[str] | None = None,
expires_in: int | None = None,
timeout: Any = _UNSET,
) -> Asset:
payload: dict[str, Any] = {"hash": hash}
if file_path is not None:
payload["file_path"] = file_path
if tags is not None:
payload["tags"] = tags
if expires_in is not None:
payload["expires_in"] = expires_in
resp = await self.raw_request("POST", "/assets/from-hash", json=payload, timeout=timeout)
data = self._p.parse_or_raise(resp, (200, 201))
return Asset.model_validate(data)
Expand Down
23 changes: 7 additions & 16 deletions src/comfy_sdk/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class _Source:
file_path: str
hasher: Hasher
opener: Opener
expires_in: int | None = None


def _guess_content_type(name: str | None) -> str:
Expand All @@ -61,7 +60,6 @@ def __init__(self, source: _Source) -> None:
self._file_path = source.file_path
self._hasher = source.hasher
self._opener = source.opener
self._expires_in = source.expires_in
self._hash: str | None = None
self._id: str | None = None
self._created_new: bool | None = None
Expand Down Expand Up @@ -129,9 +127,7 @@ def commit(self) -> str:
digest = self.hash
with translating():
if self._low.head_asset_by_hash(digest):
asset = self._low.asset_from_hash(
digest, file_path=self._file_path, expires_in=self._expires_in
)
asset = self._low.asset_from_hash(digest, file_path=self._file_path)
else:
fh, size = self._opener()
try:
Expand All @@ -142,7 +138,6 @@ def commit(self) -> str:
expected_hash=digest,
idempotency_key=self._idempotency_key,
file_size=size,
expires_in=self._expires_in,
)
finally:
fh.close()
Expand Down Expand Up @@ -178,9 +173,7 @@ async def commit(self) -> str:
digest = self.hash
with translating():
if await self._low.head_asset_by_hash(digest):
asset = await self._low.asset_from_hash(
digest, file_path=self._file_path, expires_in=self._expires_in
)
asset = await self._low.asset_from_hash(digest, file_path=self._file_path)
else:
fh, size = self._opener()
try:
Expand All @@ -191,7 +184,6 @@ async def commit(self) -> str:
expected_hash=digest,
idempotency_key=self._idempotency_key,
file_size=size,
expires_in=self._expires_in,
)
finally:
fh.close()
Expand All @@ -216,15 +208,14 @@ async def as_reference(self) -> dict[str, object]:
# ---- source builders (shared, sans-IO except explicit reads) ------------


def _file_source(path: str | PathLike[str], *, expires_in: int | None = None) -> _Source:
def _file_source(path: str | PathLike[str]) -> _Source:
p = str(path)
name = basename(p)
return _Source(
content_type=_guess_content_type(name),
file_path=name,
hasher=lambda: _hashing.hash_file(p),
opener=lambda: (open(p, "rb"), getsize(p)),
expires_in=expires_in,
)


Expand All @@ -244,8 +235,8 @@ class AssetFactory:
def __init__(self, low: ComfyLow) -> None:
self._low = low

def from_file(self, path: str | PathLike[str], *, expires_in: int | None = None) -> Asset:
return Asset(self._low, _file_source(path, expires_in=expires_in))
def from_file(self, path: str | PathLike[str]) -> Asset:
return Asset(self._low, _file_source(path))

def from_bytes(
self,
Expand Down Expand Up @@ -297,8 +288,8 @@ class AsyncAssetFactory:
def __init__(self, low: AsyncComfyLow) -> None:
self._low = low

def from_file(self, path: str | PathLike[str], *, expires_in: int | None = None) -> AsyncAsset:
return AsyncAsset(self._low, _file_source(path, expires_in=expires_in))
def from_file(self, path: str | PathLike[str]) -> AsyncAsset:
return AsyncAsset(self._low, _file_source(path))

def from_bytes(
self,
Expand Down
Loading