Skip to content

Commit 3928984

Browse files
committed
Added: getUpload and DealStatus
1 parent c103e0a commit 3928984

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

src/lighthouseweb3/__init__.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
22

33
import os
4-
from .functions import upload as d
5-
from .functions import types as t
4+
from typing import List
5+
from .functions import upload as d, types as t, deal_status, get_uploads as getUploads
66

77

88
class Lighthouse:
@@ -15,10 +15,39 @@ def __init__(self, token: str = ""):
1515

1616
def upload(self, source: str) -> t.Upload:
1717
"""
18-
Upload a file or directory to the lighthouse network
19-
@params {source}: str, path to file or directory
18+
Upload a file or directory to the Lighthouse.
19+
20+
:param source: str, path to file or directory
21+
:return: t.Upload, the upload result
2022
"""
2123
try:
2224
return d.upload(source, self.token)
2325
except Exception as e:
2426
raise e
27+
28+
@staticmethod
29+
def getDealStatus(cid: str) -> List[t.DealData]:
30+
"""
31+
Get deal status from the Lighthouse.
32+
33+
:param cid: str, content identifier
34+
:return: List[t.DealData], list of deal data
35+
"""
36+
try:
37+
return deal_status.get_deal_status(cid)
38+
except Exception as e:
39+
raise e
40+
41+
@staticmethod
42+
def getUploads(publicKey: str, pageNo: int = 1) -> List[t.DealData]:
43+
"""
44+
Get uploads from the Lighthouse.
45+
46+
:param publicKey: str, public key
47+
:param pageNo: int, page number (default: 1)
48+
:return: List[t.DealData], list of deal data
49+
"""
50+
try:
51+
return getUploads.get_uploads(publicKey, pageNo)
52+
except Exception as e:
53+
raise e

src/lighthouseweb3/functions/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ class Config:
77
lighthouse_api = "http://13.234.35.183:5050" # "https://api.lighthouse.storage"
88
lighthouse_node = "https://node.lighthouse.storage"
99
lighthouse_bls_node = "https://encryption.lighthouse.storage"
10+
lighthouse_api_v2 = 'https://api.lighthouse.storage'

src/lighthouseweb3/functions/types.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from typing import List, Dict, Tuple, NewType, TypedDict
34
from dataclasses import dataclass
4-
from typing import Dict, NewType, List, Tuple, TypedDict
55

66

77
@dataclass
@@ -17,3 +17,39 @@ class FileDict(TypedDict):
1717
files: List[str]
1818
is_dir: bool
1919
path: str
20+
21+
22+
class DealData(TypedDict):
23+
"""typings for deal Status"""
24+
chainDealID: str
25+
endEpoch: str
26+
publishCID: str
27+
storageProvider: str
28+
dealStatus: str
29+
bundleId: str
30+
dealUUID: str
31+
startEpoch: str
32+
providerCollateral: str
33+
lastUpdate: int
34+
dealId: int
35+
miner: str
36+
content: int
37+
38+
39+
class FileObject(TypedDict):
40+
publicKey: str
41+
fileName: str
42+
mimeType: str
43+
txHash: str
44+
status: str
45+
createdAt: int
46+
fileSizeInBytes: str
47+
cid: str
48+
id: str
49+
lastUpdate: int
50+
encryption: bool
51+
52+
53+
class UploadsResponseType(TypedDict):
54+
fileList: List[FileObject]
55+
totalFiles: int

0 commit comments

Comments
 (0)