Skip to content

Commit b0d63e4

Browse files
committed
Feature: get file info api added and tested successfully
1 parent 678e49e commit b0d63e4

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/lighthouseweb3/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
import os
44
import io
5-
from .functions import upload as d,deal_status, get_uploads as getUploads, download as _download
5+
from .functions import (
6+
upload as d,
7+
deal_status,
8+
get_uploads as getUploads,
9+
download as _download,
10+
get_file_info as getFileInfo
11+
)
612

713

814
class Lighthouse:
@@ -96,6 +102,19 @@ def download(cid: str):
96102
return _download.get_file(cid)
97103
except Exception as e:
98104
raise e
105+
106+
@staticmethod
107+
def getFileInfo(cid: str):
108+
"""
109+
Retrieves information about a file using its CID (Content Identifier).
110+
:param cid: str, Content Identifier for the data to be downloaded
111+
returns: dict, A dictionary containing file information.
112+
"""
113+
114+
try:
115+
return getFileInfo.get_file_info(cid)
116+
except Exception as e:
117+
raise e
99118

100119
def getTagged(self, tag: str):
101120
"""
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from .config import Config
2+
import requests as req
3+
4+
def get_file_info(cid: str):
5+
url = f"{Config.lighthouse_api}/api/lighthouse/file_info?cid={cid}"
6+
try:
7+
response = req.get(url)
8+
except Exception as e:
9+
raise Exception("Failed to get file metadata")
10+
11+
return response.json()

tests/test_get_file_info.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import unittest
4+
from src.lighthouseweb3 import Lighthouse
5+
from .setup import parse_env
6+
7+
8+
class TestGetFileInfo(unittest.TestCase):
9+
10+
def test_get_file_info(self):
11+
"""test get_file_info function"""
12+
parse_env()
13+
l = Lighthouse(os.environ.get("LIGHTHOUSE_TOKEN"))
14+
res = l.getFileInfo("Qmd5MBBScDUV3Ly8qahXtZFqyRRfYSmUwEcxpYcV4hzKfW")
15+
self.assertIsInstance(res, dict, "data is a dict")
16+
self.assertEqual(res.get("cid"),"Qmd5MBBScDUV3Ly8qahXtZFqyRRfYSmUwEcxpYcV4hzKfW", "cid is matching")

0 commit comments

Comments
 (0)