Update.
This commit is contained in:
parent
8d740be5fb
commit
e228a2e59c
@ -9,3 +9,4 @@ pytest
|
|||||||
pytest-aiohttp
|
pytest-aiohttp
|
||||||
aiohttp-test-utils
|
aiohttp-test-utils
|
||||||
pytest-mock
|
pytest-mock
|
||||||
|
pillow
|
||||||
|
|||||||
@ -12,8 +12,11 @@ class ConfigService:
|
|||||||
def _load_config(self):
|
def _load_config(self):
|
||||||
config_from_file = {}
|
config_from_file = {}
|
||||||
if self._config_path.exists():
|
if self._config_path.exists():
|
||||||
with open(self._config_path, "r") as f:
|
try:
|
||||||
config_from_file = json.load(f)
|
with open(self._config_path, "r") as f:
|
||||||
|
config_from_file = json.load(f)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
config_from_file = {}
|
||||||
|
|
||||||
# Override with environment variables
|
# Override with environment variables
|
||||||
config_from_env = {
|
config_from_env = {
|
||||||
|
|||||||
@ -14,10 +14,13 @@ class FileService:
|
|||||||
async def _load_users_data(self):
|
async def _load_users_data(self):
|
||||||
"""Loads user data from the JSON file."""
|
"""Loads user data from the JSON file."""
|
||||||
if not self.users_data_path.exists():
|
if not self.users_data_path.exists():
|
||||||
return {}
|
return []
|
||||||
async with aiofiles.open(self.users_data_path, mode="r") as f:
|
async with aiofiles.open(self.users_data_path, mode="r") as f:
|
||||||
content = await f.read()
|
content = await f.read()
|
||||||
return json.loads(content) if content else {}
|
try:
|
||||||
|
return json.loads(content) if content else []
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
return []
|
||||||
|
|
||||||
async def _save_users_data(self, data):
|
async def _save_users_data(self, data):
|
||||||
"""Saves user data to the JSON file."""
|
"""Saves user data to the JSON file."""
|
||||||
@ -89,7 +92,7 @@ class FileService:
|
|||||||
async def generate_share_link(self, user_email: str, item_path: str) -> str | None:
|
async def generate_share_link(self, user_email: str, item_path: str) -> str | None:
|
||||||
"""Generates a shareable link for a file or folder."""
|
"""Generates a shareable link for a file or folder."""
|
||||||
users_data = await self._load_users_data()
|
users_data = await self._load_users_data()
|
||||||
user = users_data.get(user_email)
|
user = next((u for u in users_data if u.get("email") == user_email), None)
|
||||||
if not user:
|
if not user:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -112,7 +115,7 @@ class FileService:
|
|||||||
async def get_shared_item(self, share_id: str) -> dict | None:
|
async def get_shared_item(self, share_id: str) -> dict | None:
|
||||||
"""Retrieves information about a shared item."""
|
"""Retrieves information about a shared item."""
|
||||||
users_data = await self._load_users_data()
|
users_data = await self._load_users_data()
|
||||||
for user_email, user_info in users_data.items():
|
for user_info in users_data:
|
||||||
if "shared_items" in user_info and share_id in user_info["shared_items"]:
|
if "shared_items" in user_info and share_id in user_info["shared_items"]:
|
||||||
shared_item = user_info["shared_items"][share_id]
|
shared_item = user_info["shared_items"][share_id]
|
||||||
expiry_time = datetime.datetime.fromisoformat(shared_item["expires_at"])
|
expiry_time = datetime.datetime.fromisoformat(shared_item["expires_at"])
|
||||||
|
|||||||
@ -14,8 +14,11 @@ class UserService:
|
|||||||
def _load_users(self) -> List[Dict[str, Any]]:
|
def _load_users(self) -> List[Dict[str, Any]]:
|
||||||
if not self._users_path.exists():
|
if not self._users_path.exists():
|
||||||
return []
|
return []
|
||||||
with open(self._users_path, "r") as f:
|
try:
|
||||||
return json.load(f)
|
with open(self._users_path, "r") as f:
|
||||||
|
return json.load(f)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
return []
|
||||||
|
|
||||||
def _save_users(self):
|
def _save_users(self):
|
||||||
with open(self._users_path, "w") as f:
|
with open(self._users_path, "w") as f:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user