同步更新:重构路由、服务模块,更新前端构建
This commit is contained in:
@@ -15,6 +15,7 @@ import atexit
|
||||
import weakref
|
||||
from typing import Optional, Callable
|
||||
from dataclasses import dataclass
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
from app_config import get_config
|
||||
|
||||
# 设置浏览器安装路径(优先使用环境变量,否则使用默认路径)
|
||||
@@ -173,17 +174,15 @@ class PlaywrightAutomation:
|
||||
self.browser_manager.log(message, self.account_id)
|
||||
|
||||
|
||||
# Cookies存储目录
|
||||
COOKIES_DIR = '/app/data/cookies'
|
||||
|
||||
def get_cookies_path(self, username: str) -> str:
|
||||
"""获取cookies文件路径"""
|
||||
import os
|
||||
os.makedirs(self.COOKIES_DIR, exist_ok=True)
|
||||
cookies_dir = getattr(config, "COOKIES_DIR", "/app/data/cookies")
|
||||
os.makedirs(cookies_dir, exist_ok=True)
|
||||
# 安全修复:使用SHA256代替MD5作为文件名哈希
|
||||
import hashlib
|
||||
filename = hashlib.sha256(username.encode()).hexdigest()[:32] + '.json'
|
||||
return os.path.join(self.COOKIES_DIR, filename)
|
||||
return os.path.join(cookies_dir, filename)
|
||||
|
||||
def save_cookies(self, username: str):
|
||||
"""保存当前会话的cookies"""
|
||||
@@ -279,12 +278,27 @@ class PlaywrightAutomation:
|
||||
def check_login_state(self) -> bool:
|
||||
"""检查当前是否处于登录状态"""
|
||||
try:
|
||||
index_url = getattr(config, "ZSGL_INDEX_URL", None)
|
||||
if not index_url:
|
||||
login_url = getattr(config, "ZSGL_LOGIN_URL", "https://postoa.aidunsoft.com/admin/login.aspx")
|
||||
index_filename = getattr(config, "ZSGL_INDEX_URL_PATTERN", "index.aspx")
|
||||
parsed = urlsplit(login_url)
|
||||
if parsed.scheme and parsed.netloc:
|
||||
path = parsed.path or "/"
|
||||
if path.endswith("/"):
|
||||
path = path + index_filename
|
||||
else:
|
||||
path = path.rsplit("/", 1)[0] + "/" + index_filename
|
||||
index_url = urlunsplit((parsed.scheme, parsed.netloc, path, "", ""))
|
||||
else:
|
||||
index_url = "https://postoa.aidunsoft.com/admin/index.aspx"
|
||||
|
||||
# 访问首页检查是否跳转到登录页
|
||||
self.page.goto('https://postoa.aidunsoft.com/admin/index.aspx', timeout=15000)
|
||||
self.page.goto(index_url, timeout=15000)
|
||||
self.page.wait_for_load_state('networkidle', timeout=10000)
|
||||
current_url = self.page.url
|
||||
# 如果还在index页面,说明登录态有效
|
||||
if 'index.aspx' in current_url:
|
||||
if getattr(config, "ZSGL_INDEX_URL_PATTERN", "index.aspx") in current_url:
|
||||
return True
|
||||
return False
|
||||
except (TimeoutError, Exception) as e:
|
||||
|
||||
Reference in New Issue
Block a user