Thanks to visit codestin.com
Credit goes to github.com

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
10 changes: 0 additions & 10 deletions src/aleph/services/ipfs/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,6 @@ async def pin_add(self, cid: str, timeout: int = 30, tries: int = 1):
else:
break

async def add_file(self, file_content: bytes) -> Dict[str, str]:
"""
Add a file to IPFS using bytes as data.

This is a backward-compatible wrapper around add_bytes().
Uses the pinning client for write operations.
"""
hash = await self.add_bytes(file_content)
return {"Hash": hash}

async def sub(self, topic: str):
ipfs_client = self.ipfs_client

Expand Down
3 changes: 1 addition & 2 deletions src/aleph/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ async def add_file(
self, session: DbSession, file_content: bytes, engine: ItemType = ItemType.ipfs
) -> str:
if engine == ItemType.ipfs:
output = await self.ipfs_service.add_file(file_content)
file_hash = output["Hash"]
file_hash = await self.ipfs_service.add_bytes(file_content)

elif engine == ItemType.storage:
file_hash = sha256(file_content).hexdigest()
Expand Down
10 changes: 5 additions & 5 deletions src/aleph/web/controllers/ipfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ async def ipfs_add_file(request: web.Request):
file_content: bytes
if isinstance(file_field, bytes):
file_content = file_field
filename = "file"
elif isinstance(file_field, str):
file_content = file_field.encode()
filename = "file"
elif isinstance(file_field, FileField):
filename = file_field.filename
if file_field.content_type != "application/octet-stream":
raise web.HTTPUnprocessableEntity(
reason="Invalid content-type for 'file' field. Must be 'application/octet-stream'."
Expand All @@ -46,10 +49,7 @@ async def ipfs_add_file(request: web.Request):
reason="Invalid type for 'file' field. Must be bytes, str or FileField."
)

ipfs_add_response = await ipfs_service.add_file(file_content)

cid = ipfs_add_response["Hash"]
name = ipfs_add_response["Name"]
cid = await ipfs_service.add_bytes(file_content)

# IPFS add returns the cumulative size and not the real file size.
# We need the real file size here.
Expand All @@ -71,7 +71,7 @@ async def ipfs_add_file(request: web.Request):
output = {
"status": "success",
"hash": cid,
"name": name,
"name": filename,
"size": size,
}
return web.json_response(output)
Loading