diff --git a/src/lighthouseweb3/__init__.py b/src/lighthouseweb3/__init__.py index 8cf1d94..9571e2d 100644 --- a/src/lighthouseweb3/__init__.py +++ b/src/lighthouseweb3/__init__.py @@ -69,8 +69,7 @@ def getDealStatus(cid: str): except Exception as e: raise e - @staticmethod - def getUploads(publicKey: str, pageNo: int = 1): + def getUploads(self, lastKey: int = None): """ Get uploads from the Lighthouse. @@ -79,7 +78,7 @@ def getUploads(publicKey: str, pageNo: int = 1): :return: List[t.DealData], list of deal data """ try: - return getUploads.get_uploads(publicKey, pageNo) + return getUploads.get_uploads(self.token, lastKey) except Exception as e: raise e diff --git a/src/lighthouseweb3/functions/get_uploads.py b/src/lighthouseweb3/functions/get_uploads.py index d2c8a6b..dcc15da 100644 --- a/src/lighthouseweb3/functions/get_uploads.py +++ b/src/lighthouseweb3/functions/get_uploads.py @@ -11,10 +11,13 @@ def bytes_to_size(bytes_size): return f"{round(bytes_size, 2)} {units[index]}" -def get_uploads(publicKey: str, pageNo: int = 1) : +def get_uploads(token: str, lastKey: int = None) : + headers = { + "Authorization": f"Bearer {token}", + } try: - url = f"{Config.lighthouse_api}/api/user/files_uploaded?publicKey={publicKey}&pageNo={pageNo}" - response = requests.get(url) + url = f"{Config.lighthouse_api}/api/user/files_uploaded?lastKey={lastKey}" + response = requests.get(url, headers=headers) response.raise_for_status() return response.json() except requests.HTTPError as error: diff --git a/tests/test_deal_status.py b/tests/test_deal_status.py index 7d8bedc..bb9b3ae 100644 --- a/tests/test_deal_status.py +++ b/tests/test_deal_status.py @@ -15,7 +15,7 @@ def test_deal_status(self): "QmT9shXpKcn4HRbJhXJ1ZywzwjEo2QWbxAx4SVgW4eYKjG") self.assertIsInstance(res, list, "data is a list") self.assertIsInstance(res[0].get( - "dealId"), int, "dealId is Int") + "DealID"), int, "DealID is Int") def test_deal_status_init(self): """test deal_status function""" @@ -25,4 +25,4 @@ def test_deal_status_init(self): "QmT9shXpKcn4HRbJhXJ1ZywzwjEo2QWbxAx4SVgW4eYKjG") self.assertIsInstance(res, list, "data is a list") self.assertIsInstance(res[0].get( - "dealId"), int, "dealId is Int") + "DealID"), int, "DealID is Int") diff --git a/tests/test_get_uploads.py b/tests/test_get_uploads.py index 82131a8..a0f3880 100644 --- a/tests/test_get_uploads.py +++ b/tests/test_get_uploads.py @@ -7,18 +7,13 @@ from .setup import parse_env -class TestDealStatus(unittest.TestCase): +class TestGetUploads(unittest.TestCase): def test_get_upload(self): - """test static test_get_upload function""" - res = Lighthouse.getUploads( - "0xB23809427cFc9B3346AEC5Bb70E7e574696cAF80") - self.assertIsInstance(res.get("fileList"), list, "data is a list") - - def test_get_upload_init(self): """test get_upload function""" parse_env() l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN")) - res = Lighthouse.getUploads( - "0xB23809427cFc9B3346AEC5Bb70E7e574696cAF80") + res = l.getUploads() self.assertIsInstance(res.get("fileList"), list, "data is a list") + +