From 74c7a1927b2c50f66ef1279bcae5ed3617f5cbff Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 17 Mar 2024 13:42:01 +0800 Subject: [PATCH] fix cookiecloud --- app/api/endpoints/system.py | 1 + app/api/servcookie.py | 6 ++++-- app/helper/cookiecloud.py | 7 +++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/api/endpoints/system.py b/app/api/endpoints/system.py index a3248a1c..09b031cf 100644 --- a/app/api/endpoints/system.py +++ b/app/api/endpoints/system.py @@ -307,6 +307,7 @@ def reload_module(_: schemas.TokenPayload = Depends(verify_token)): 重新加载模块 """ ModuleManager().reload() + Scheduler().init() return schemas.Response(success=True) diff --git a/app/api/servcookie.py b/app/api/servcookie.py index c781111f..ffae4147 100644 --- a/app/api/servcookie.py +++ b/app/api/servcookie.py @@ -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"]) diff --git a/app/helper/cookiecloud.py b/app/helper/cookiecloud.py index 9a7d2acb..4fbabd81 100644 --- a/app/helper/cookiecloud.py +++ b/app/helper/cookiecloud.py @@ -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