This commit is contained in:
jxxghp
2025-07-31 08:11:27 +08:00
parent d382eab355
commit 67229fd032
3 changed files with 18 additions and 16 deletions
+6 -6
View File
@@ -2,7 +2,7 @@ import gzip
import json import json
from typing import Annotated, Callable, Any, Dict, Optional from typing import Annotated, Callable, Any, Dict, Optional
import aiofiles from aiopath import AsyncPath
from fastapi import APIRouter, Depends, HTTPException, Path, Request, Response from fastapi import APIRouter, Depends, HTTPException, Path, Request, Response
from fastapi.responses import PlainTextResponse from fastapi.responses import PlainTextResponse
from fastapi.routing import APIRoute from fastapi.routing import APIRoute
@@ -65,11 +65,11 @@ async def update_cookie(req: schemas.CookieData):
""" """
上传Cookie数据 上传Cookie数据
""" """
file_path = settings.COOKIE_PATH / f"{req.uuid}.json" file_path = AsyncPath(settings.COOKIE_PATH) / f"{req.uuid}.json"
content = json.dumps({"encrypted": req.encrypted}) content = json.dumps({"encrypted": req.encrypted})
async with aiofiles.open(file_path, encoding="utf-8", mode="w") as file: async with file_path.open(encoding="utf-8", mode="w") as file:
await file.write(content) await file.write(content)
async with aiofiles.open(file_path, encoding="utf-8", mode="r") as file: async with file_path.open(encoding="utf-8", mode="r") as file:
read_content = await file.read() read_content = await file.read()
if read_content == content: if read_content == content:
return {"action": "done"} return {"action": "done"}
@@ -81,14 +81,14 @@ async def load_encrypt_data(uuid: str) -> Dict[str, Any]:
""" """
加载本地加密原始数据 加载本地加密原始数据
""" """
file_path = settings.COOKIE_PATH / f"{uuid}.json" file_path = AsyncPath(settings.COOKIE_PATH) / f"{uuid}.json"
# 检查文件是否存在 # 检查文件是否存在
if not file_path.exists(): if not file_path.exists():
raise HTTPException(status_code=404, detail="Item not found") raise HTTPException(status_code=404, detail="Item not found")
# 读取文件 # 读取文件
async with aiofiles.open(file_path, encoding="utf-8", mode="r") as file: async with file_path.open(encoding="utf-8", mode="r") as file:
read_content = await file.read() read_content = await file.read()
data = json.loads(read_content.encode("utf-8")) data = json.loads(read_content.encode("utf-8"))
return data return data
+1 -1
View File
@@ -17,7 +17,7 @@ def create_app() -> FastAPI:
# 配置 CORS 中间件 # 配置 CORS 中间件
_app.add_middleware( _app.add_middleware(
CORSMiddleware, CORSMiddleware, # noqa
allow_origins=settings.ALLOWED_HOSTS, allow_origins=settings.ALLOWED_HOSTS,
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], allow_methods=["*"],
+11 -9
View File
@@ -1,12 +1,5 @@
import sys import sys
from app.command import CommandChain
from app.core.cache import close_cache
from app.core.config import settings
from app.core.module import ModuleManager
from app.log import logger
from app.utils.system import SystemUtils
# SitesHelper涉及资源包拉取,提前引入并容错提示 # SitesHelper涉及资源包拉取,提前引入并容错提示
try: try:
from app.helper.sites import SitesHelper # noqa from app.helper.sites import SitesHelper # noqa
@@ -16,16 +9,23 @@ except ImportError as e:
print(error_message, file=sys.stderr) print(error_message, file=sys.stderr)
sys.exit(1) sys.exit(1)
from app.utils.system import SystemUtils
from app.log import logger
from app.core.config import settings
from app.core.cache import close_cache
from app.core.module import ModuleManager
from app.core.event import EventManager from app.core.event import EventManager
from app.helper.thread import ThreadHelper from app.helper.thread import ThreadHelper
from app.helper.display import DisplayHelper from app.helper.display import DisplayHelper
from app.helper.doh import DohHelper from app.helper.doh import DohHelper
from app.helper.resource import ResourceHelper from app.helper.resource import ResourceHelper
from app.helper.message import MessageHelper from app.helper.message import MessageHelper
from app.schemas import Notification, NotificationType from app.helper.subscribe import SubscribeHelper
from app.schemas.types import SystemConfigKey
from app.db import close_database from app.db import close_database
from app.db.systemconfig_oper import SystemConfigOper from app.db.systemconfig_oper import SystemConfigOper
from app.command import CommandChain
from app.schemas import Notification, NotificationType
from app.schemas.types import SystemConfigKey
def start_frontend(): def start_frontend():
@@ -145,6 +145,8 @@ def init_modules():
ModuleManager() ModuleManager()
# 启动事件消费 # 启动事件消费
EventManager().start() EventManager().start()
# 初始化订阅分享
SubscribeHelper()
# 启动前端服务 # 启动前端服务
start_frontend() start_frontend()
# 检查认证状态 # 检查认证状态