Skip to content

Commit 3313ec0

Browse files
committed
renamed: Deploy to Upload
1 parent 6fc2add commit 3313ec0

File tree

7 files changed

+49
-91
lines changed

7 files changed

+49
-91
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lh = Lighthouse(token="your_token")
2727
```python
2828
from lighthouseweb3 import Lighthouse
2929
lh = Lighthouse()
30-
response = lh.deploy("path/to/file")
30+
response = lh.upload("path/to/file")
3131
print(response) # prints a dict containing the cid of the file
3232
```
3333

@@ -36,7 +36,7 @@ print(response) # prints a dict containing the cid of the file
3636
```python
3737
from lighthouseweb3 import Lighthouse
3838
lh = Lighthouse("my-lightouse-token")
39-
response = lh.deploy("path/to/directory")
39+
response = lh.upload("path/to/directory")
4040
print(response) # prints a dict containing the root cid of the directory
4141
```
4242

@@ -45,11 +45,11 @@ print(response) # prints a dict containing the root cid of the directory
4545
The tests are written with inheritance from the unittest module. To run the tests, run the following command:
4646

4747
```
48-
pip install requirements.txt && python -m unittest discover
48+
pip install -r requirements.txt && python -m unittest discover
4949
```
5050

5151
or using nose2
5252

5353
```
54-
pip install requirements.txt && python -m nose2
54+
pip install -r requirements.txt && python -m nose2
5555
```

src/lighthouseweb3/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
import os
4-
from .functions import deploy as d
4+
from .functions import upload as d
55
from .functions import types as t
66

77

@@ -13,12 +13,12 @@ def __init__(self, token: str = ""):
1313
"No token provided: Please provide a token or set the LIGHTHOUSE_TOKEN environment variable"
1414
)
1515

16-
def deploy(self, source: str) -> t.Deploy:
16+
def upload(self, source: str) -> t.Upload:
1717
"""
18-
Deploy a file or directory to the lighthouse network
18+
Upload a file or directory to the lighthouse network
1919
@params {source}: str, path to file or directory
2020
"""
2121
try:
22-
return d.deploy(source, self.token)
22+
return d.upload(source, self.token)
2323
except Exception as e:
2424
raise e

src/lighthouseweb3/functions/axios.py

+25
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,28 @@ def post_files(
5959
except Exception as e:
6060
utils.close_files_after_upload(files)
6161
raise e
62+
63+
def post_blob(
64+
self, file: BufferedReader, headers: Dict[str, str] = None, **kwargs
65+
) -> dict | Exception:
66+
try:
67+
self.parse_url_query(kwargs.get("query", None))
68+
files = [(
69+
"file",
70+
(
71+
utils.extract_file_name(file.name),
72+
file.read(),
73+
"application/octet-stream",
74+
),
75+
),]
76+
r = req.post(self.url, headers=headers, files=files)
77+
r.raise_for_status()
78+
file.close()
79+
try:
80+
return r.json()
81+
except Exception:
82+
temp = r.text.split("\n")
83+
return json.loads(temp[len(temp) - 2])
84+
except Exception as e:
85+
file.close()
86+
raise e

src/lighthouseweb3/functions/deploy.py

-43
This file was deleted.

src/lighthouseweb3/functions/types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
@dataclass
8-
class Deploy(TypedDict):
9-
"""typings for deploy function"""
8+
class Upload(TypedDict):
9+
"""typings for upload function"""
1010

1111
data: dict | str
1212

src/lighthouseweb3/functions/utils.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
#!/usr/bin/env python3
22

3-
from io import BufferedReader
3+
from io import BufferedReader, BytesIO
44
import os
55
from typing import List, Tuple
66
from . import types as t
77

8+
9+
class NamedBufferedReader:
10+
def __init__(self, buffer, name:str):
11+
self.reader = BufferedReader(buffer)
12+
self.name = name
13+
14+
def read(self, *args, **kwargs):
15+
return self.reader.read(*args, **kwargs)
16+
17+
def close(self):
18+
self.reader.close()
819
# walk path and return list of file paths
20+
21+
922
def walk_dir_tree(path: str) -> Tuple[List[str], str]:
1023
file_list = []
1124
roots = []

tests/test_deploy.py

-37
This file was deleted.

0 commit comments

Comments
 (0)