fix cookiecloud

This commit is contained in:
jxxghp 2024-03-17 13:42:01 +08:00
parent cbd704373c
commit 74c7a1927b
3 changed files with 8 additions and 6 deletions

View File

@ -307,6 +307,7 @@ def reload_module(_: schemas.TokenPayload = Depends(verify_token)):
重新加载模块
"""
ModuleManager().reload()
Scheduler().init()
return schemas.Response(success=True)

View File

@ -15,7 +15,6 @@ from app.utils.common import decrypt
class GzipRequest(Request):
_body: bytes = b""
async def body(self) -> bytes:
if not hasattr(self, "_body"):
@ -122,7 +121,7 @@ def get_decrypted_cookie_data(uuid: str, password: str,
async def get_cookie(
uuid: Annotated[str, Path(min_length=5, pattern="^[a-zA-Z0-9]+$")]):
"""
下载加密数据
GET 下载加密数据
"""
return load_encrypt_data(uuid)
@ -131,5 +130,8 @@ async def get_cookie(
async def post_cookie(
uuid: Annotated[str, Path(min_length=5, pattern="^[a-zA-Z0-9]+$")],
request: schemas.CookiePassword):
"""
POST 下载加密数据
"""
data = load_encrypt_data(uuid)
return get_decrypted_cookie_data(uuid, request.password, data["encrypted"])

View File

@ -1,5 +1,4 @@
import json
import os
from hashlib import md5
from typing import Any, Dict, Tuple, Optional
@ -115,13 +114,13 @@ class CookieCloudHelper:
return (md5_generator.hexdigest()[:16]).encode('utf-8')
def _load_local_encrypt_data(self, uuid: str) -> Dict[str, Any]:
file_path = os.path.join(self._local_path, os.path.basename(uuid) + ".json")
file_path = self._local_path / f"{uuid}.json"
# 检查文件是否存在
if not os.path.exists(file_path):
if not file_path.exists():
return {}
# 读取文件
with open(file_path, encoding="utf-8", mode="r") as file:
read_content = file.read()
data = json.loads(read_content)
data = json.loads(read_content.encode("utf-8"))
return data