Skip to content

Commit 1c379e3

Browse files
authored
[Storage] Remove filename parameter (#262)
The name of the file uploaded through IPFS and storage endpoints is useless because we only rely on hashes.
1 parent fc1eb03 commit 1c379e3

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

src/aleph/services/ipfs/storage.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import concurrent
33
import json
44
import logging
5-
from typing import Optional
5+
from typing import IO, Optional
66

77
import aiohttp
88
import aioipfs
@@ -106,13 +106,13 @@ async def pin_add(hash: str, timeout: int = 2, tries: int = 1):
106106
return result
107107

108108

109-
async def add_file(fileobject, filename):
109+
async def add_file(fileobject: IO):
110110
config = get_config()
111111

112112
async with aiohttp.ClientSession() as session:
113113
url = "%s/api/v0/add" % (await get_base_url(config))
114114
data = aiohttp.FormData()
115-
data.add_field("path", fileobject, filename=filename)
115+
data.add_field("path", fileobject)
116116

117117
resp = await session.post(url, data=data)
118118
return await resp.json()

src/aleph/storage.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,10 @@ async def add_json(value: Any, engine: ItemType = ItemType.IPFS) -> str:
259259
return chash
260260

261261

262-
async def add_file(
263-
fileobject: IO, filename: Optional[str] = None, engine: ItemType = ItemType.IPFS
264-
) -> str:
262+
async def add_file(fileobject: IO, engine: ItemType = ItemType.IPFS) -> str:
265263

266264
if engine == ItemType.IPFS:
267-
output = await ipfs_add_file(fileobject, filename)
265+
output = await ipfs_add_file(fileobject)
268266
file_hash = output["Hash"]
269267
fileobject.seek(0)
270268
file_content = fileobject.read()

src/aleph/web/controllers/ipfs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async def ipfs_add_file(request):
77
# No need to pin it here anymore.
88
# TODO: find a way to specify linked ipfs hashes in posts/aggr.
99
post = await request.post()
10-
output = await add_file(post["file"].file, post["file"].filename)
10+
output = await add_file(post["file"].file)
1111

1212
output = {
1313
"status": "success",

src/aleph/web/controllers/storage.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ async def storage_add_file(request):
3232
# No need to pin it here anymore.
3333
# TODO: find a way to specify linked ipfs hashes in posts/aggr.
3434
post = await request.post()
35-
file_hash = await add_file(
36-
post["file"].file, filename=post["file"].filename, engine=ItemType.Storage
37-
)
35+
file_hash = await add_file(post["file"].file, engine=ItemType.Storage)
3836

3937
output = {"status": "success", "hash": file_hash}
4038
return web.json_response(output)

0 commit comments

Comments
 (0)