Compare commits
77 Commits
89f3fd9759
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fae21329d7 | |||
| f46f325518 | |||
| 156d3a97b2 | |||
|
|
f90d840dfe | ||
|
|
dfc93bce2e | ||
| 10be464265 | |||
| e65485cb1e | |||
| 42609651bd | |||
|
|
072fbcbe18 | ||
|
|
3702026f9a | ||
|
|
00597fb3b7 | ||
|
|
42e88f4924 | ||
|
|
56b3ca4e59 | ||
|
|
92d4e2ba58 | ||
|
|
67340f75be | ||
|
|
803fe436d3 | ||
|
|
7e9a772104 | ||
| 722dccdc78 | |||
| 606cad43dc | |||
| 6313631b09 | |||
| 09188b8765 | |||
| b2b0dfd500 | |||
| 2ff9e18842 | |||
| 1bd49f804c | |||
| f8bbe3da0d | |||
| 1b85f34a0f | |||
| f04c5c1c8f | |||
|
|
b1484e9c03 | ||
|
|
7f5e9d5244 | ||
|
|
0ca6dfe5a7 | ||
|
|
15fe2093c2 | ||
| 30b6e3144b | |||
| da71b0ac5e | |||
| 3c6799ce53 | |||
| a3060e4cd9 | |||
| be9ec5e9a2 | |||
| b0fe325154 | |||
| 13544867aa | |||
| 5fd13fa152 | |||
| a36fa3370b | |||
| 2ec0c7cb58 | |||
| 3841358bc2 | |||
| 6bd00021b8 | |||
| f2652af8fb | |||
| 950af0efda | |||
| 45cbdc51b4 | |||
| 703a62b6ad | |||
| ad847888f8 | |||
| 8c150dcb7c | |||
| ec90404194 | |||
| 6af8f46129 | |||
| 19f083df7b | |||
| a04cbfa55f | |||
| b78bc7935f | |||
| d8897f893a | |||
| 95d7cbc825 | |||
| 6b416dc5f1 | |||
| 28e86b1147 | |||
| 1e216ea356 | |||
| 3bae759afc | |||
| 5137addacc | |||
| 4c492122dd | |||
| 82acc3470f | |||
| 2e44afde30 | |||
| 28f4e807a9 | |||
| 3b04f04a31 | |||
| ea1c7e8a00 | |||
| d269a99d3c | |||
| 7c3d0a0947 | |||
| 7cf39f80bc | |||
| d108f3b51d | |||
| 41ead4bead | |||
| 2d98ab66a3 | |||
| 70e09c83a8 | |||
| 01ffaf96a3 | |||
| 1b20478a08 | |||
| 3d9dba272e |
181
.gitignore
vendored
181
.gitignore
vendored
@@ -1,75 +1,148 @@
|
|||||||
# 浏览器二进制文件
|
# Python
|
||||||
playwright/
|
|
||||||
ms-playwright/
|
|
||||||
|
|
||||||
# 数据库文件(敏感数据)
|
|
||||||
data/*.db
|
|
||||||
data/*.db-shm
|
|
||||||
data/*.db-wal
|
|
||||||
data/*.backup*
|
|
||||||
data/secret_key.txt
|
|
||||||
data/update/
|
|
||||||
|
|
||||||
# Cookies(敏感用户凭据)
|
|
||||||
data/cookies/
|
|
||||||
|
|
||||||
# 日志文件
|
|
||||||
logs/
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# 截图文件
|
|
||||||
截图/
|
|
||||||
|
|
||||||
# Python缓存
|
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*.class
|
*$py.class
|
||||||
*.so
|
*.so
|
||||||
.Python
|
.Python
|
||||||
.pytest_cache/
|
build/
|
||||||
.ruff_cache/
|
develop-eggs/
|
||||||
.mypy_cache/
|
dist/
|
||||||
.coverage
|
downloads/
|
||||||
coverage.xml
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
htmlcov/
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Test and tool directories
|
||||||
|
tests/
|
||||||
|
tools/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
ENV/
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
# 环境变量文件(包含敏感信息)
|
# Spyder project settings
|
||||||
.env
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
# Docker volumes
|
# Rope project settings
|
||||||
volumes/
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Project specific
|
||||||
|
data/
|
||||||
|
logs/
|
||||||
|
screenshots/
|
||||||
|
截图/
|
||||||
|
ruff_cache/
|
||||||
|
*.png
|
||||||
|
*.jpg
|
||||||
|
*.jpeg
|
||||||
|
*.gif
|
||||||
|
*.bmp
|
||||||
|
*.ico
|
||||||
|
*.pdf
|
||||||
|
qr_code_*.png
|
||||||
|
|
||||||
|
# Development files
|
||||||
|
test_*.py
|
||||||
|
start_*.bat
|
||||||
|
temp_*.py
|
||||||
|
kdocs_*test*.py
|
||||||
|
simple_test.py
|
||||||
|
tools/
|
||||||
|
*.sh
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
# 系统文件
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# 临时文件
|
# Temporary files
|
||||||
*.tmp
|
*.tmp
|
||||||
*.bak
|
*.temp
|
||||||
*.backup
|
|
||||||
|
|
||||||
# 部署脚本(含服务器信息)
|
|
||||||
deploy_*.sh
|
|
||||||
verify_*.sh
|
|
||||||
deploy.sh
|
|
||||||
|
|
||||||
# 内部文档
|
|
||||||
docs/
|
|
||||||
|
|
||||||
# 前端依赖(体积大,不应入库)
|
|
||||||
node_modules/
|
|
||||||
app-frontend/node_modules/
|
|
||||||
admin-frontend/node_modules/
|
|
||||||
|
|
||||||
# Local data
|
|
||||||
data/
|
|
||||||
docker-compose.yml.bak.*
|
|
||||||
|
|||||||
13
Dockerfile
13
Dockerfile
@@ -1,14 +1,18 @@
|
|||||||
# 使用国内镜像源加速
|
# 使用国内镜像源加速
|
||||||
FROM mcr.microsoft.com/playwright/python:v1.40.0-jammy
|
FROM python:3.10-slim-bullseye
|
||||||
|
|
||||||
# 设置工作目录
|
# 设置工作目录
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 设置环境变量
|
# 设置环境变量
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
|
||||||
ENV TZ=Asia/Shanghai
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
|
# 安装 wkhtmltopdf(包含 wkhtmltoimage)与中文字体
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends wkhtmltopdf curl fonts-noto-cjk && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# 配置 pip 使用国内镜像源
|
# 配置 pip 使用国内镜像源
|
||||||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && pip config set install.trusted-host mirrors.aliyun.com
|
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && pip config set install.trusted-host mirrors.aliyun.com
|
||||||
|
|
||||||
@@ -18,14 +22,15 @@ COPY requirements.txt .
|
|||||||
# 安装Python依赖
|
# 安装Python依赖
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# 安装 Playwright 浏览器依赖与 Chromium
|
||||||
|
RUN python -m playwright install --with-deps chromium
|
||||||
|
|
||||||
# 复制应用程序文件
|
# 复制应用程序文件
|
||||||
COPY app.py .
|
COPY app.py .
|
||||||
COPY database.py .
|
COPY database.py .
|
||||||
COPY db_pool.py .
|
COPY db_pool.py .
|
||||||
COPY playwright_automation.py .
|
|
||||||
COPY api_browser.py .
|
COPY api_browser.py .
|
||||||
COPY browser_pool_worker.py .
|
COPY browser_pool_worker.py .
|
||||||
COPY browser_installer.py .
|
|
||||||
COPY password_utils.py .
|
COPY password_utils.py .
|
||||||
COPY crypto_utils.py .
|
COPY crypto_utils.py .
|
||||||
COPY task_checkpoint.py .
|
COPY task_checkpoint.py .
|
||||||
|
|||||||
181
FINAL_CLEANUP_REPORT.md
Normal file
181
FINAL_CLEANUP_REPORT.md
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
# 最终仓库清理完成报告
|
||||||
|
|
||||||
|
## 🎯 用户反馈
|
||||||
|
|
||||||
|
用户指出:"TESTING_GUIDE.md 这类的md文件 应该也不需要了吧 一般就是要个redeme吧"
|
||||||
|
|
||||||
|
这个反馈非常准确!我们进行了最终的清理。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ 最终清理结果
|
||||||
|
|
||||||
|
### 删除的非必要文档(7个文件,-1,797行)
|
||||||
|
|
||||||
|
| 文件名 | 删除原因 |
|
||||||
|
|--------|----------|
|
||||||
|
| `BUG_REPORT.md` | 开发过程文档,对用户无用 |
|
||||||
|
| `CLEANUP_SUMMARY.md` | 开发者内部记录 |
|
||||||
|
| `DATABASE_UPGRADE_COMPATIBILITY.md` | 临时技术文档 |
|
||||||
|
| `GIT_PUSH_SUCCESS.md` | 开发者内部报告 |
|
||||||
|
| `LINUX_DEPLOYMENT_ANALYSIS.md` | 临时分析文档 |
|
||||||
|
| `PERFORMANCE_ANALYSIS_REPORT.md` | 临时性能报告 |
|
||||||
|
| `SCREENSHOT_FIX_SUCCESS.md` | 过时的问题解决记录 |
|
||||||
|
|
||||||
|
### 保留的核心文档
|
||||||
|
|
||||||
|
| 文件 | 保留原因 |
|
||||||
|
|------|----------|
|
||||||
|
| `README.md` | 项目主要文档,包含完整使用说明 |
|
||||||
|
| `admin-frontend/README.md` | 管理前端文档 |
|
||||||
|
| `app-frontend/README.md` | 用户前端文档 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 清理效果对比
|
||||||
|
|
||||||
|
### 清理前
|
||||||
|
- 📁 **文档文件**: 15个.md文件(包含大量开发文档)
|
||||||
|
- 📁 **测试文件**: 25个开发测试文件
|
||||||
|
- 📁 **临时文件**: 各种临时脚本和图片
|
||||||
|
- 📁 **总文件**: 过度臃肿,仓库混乱
|
||||||
|
|
||||||
|
### 清理后
|
||||||
|
- 📁 **文档文件**: 3个README.md文件(专业简洁)
|
||||||
|
- 📁 **核心代码**: 纯生产环境代码
|
||||||
|
- 📁 **配置文件**: Docker、依赖、部署配置
|
||||||
|
- 📁 **总文件**: 精简专业,生产就绪
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛡️ 保护机制
|
||||||
|
|
||||||
|
### 更新.gitignore
|
||||||
|
```gitignore
|
||||||
|
# ... 其他忽略规则 ...
|
||||||
|
|
||||||
|
# Development files
|
||||||
|
test_*.py
|
||||||
|
start_*.bat
|
||||||
|
temp_*.py
|
||||||
|
kdocs_*test*.py
|
||||||
|
simple_test.py
|
||||||
|
tools/
|
||||||
|
*.sh
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
*.md
|
||||||
|
!README.md
|
||||||
|
```
|
||||||
|
|
||||||
|
### 规则说明
|
||||||
|
- ✅ **允许**: 根目录的README.md
|
||||||
|
- ❌ **禁止**: 根目录的其他.md文件
|
||||||
|
- ✅ **允许**: 子目录的README.md
|
||||||
|
- ❌ **禁止**: 所有测试和临时文件
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 最终状态
|
||||||
|
|
||||||
|
### ✅ 仓库现在包含
|
||||||
|
|
||||||
|
#### 核心应用文件
|
||||||
|
- `app.py` - Flask应用主文件
|
||||||
|
- `database.py` - 数据库操作
|
||||||
|
- `api_browser.py` - API浏览器
|
||||||
|
- `browser_pool_worker.py` - 截图线程池
|
||||||
|
- `services/` - 业务逻辑
|
||||||
|
- `routes/` - API路由
|
||||||
|
- `db/` - 数据库相关
|
||||||
|
|
||||||
|
#### 配置文件
|
||||||
|
- `Dockerfile` - Docker构建配置
|
||||||
|
- `docker-compose.yml` - 编排文件
|
||||||
|
- `requirements.txt` - Python依赖
|
||||||
|
- `pyproject.toml` - 项目配置
|
||||||
|
- `.env.example` - 环境变量模板
|
||||||
|
|
||||||
|
#### 文档
|
||||||
|
- `README.md` - 唯一的主要文档
|
||||||
|
|
||||||
|
### ❌ 仓库不再包含
|
||||||
|
|
||||||
|
- ❌ 测试文件(test_*.py等)
|
||||||
|
- ❌ 启动脚本(start_*.bat等)
|
||||||
|
- ❌ 临时文件(temp_*.py等)
|
||||||
|
- ❌ 开发文档(各种-*.md文件)
|
||||||
|
- ❌ 运行时文件(截图、日志等)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📈 质量提升
|
||||||
|
|
||||||
|
| 指标 | 清理前 | 清理后 | 改善程度 |
|
||||||
|
|------|--------|--------|----------|
|
||||||
|
| **文档数量** | 15个.md | 3个README | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **专业度** | 开发版感觉 | 生产级质量 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **可维护性** | 混乱复杂 | 简洁清晰 | ⭐⭐⭐⭐⭐ |
|
||||||
|
| **部署友好性** | 需手动清理 | 开箱即用 | ⭐⭐⭐⭐⭐ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💡 经验教训
|
||||||
|
|
||||||
|
### ✅ 正确的做法
|
||||||
|
1. **README.md为王** - 只需要一个主要的README文档
|
||||||
|
2. **保护.gitignore** - 从一开始就设置好忽略规则
|
||||||
|
3. **分离开发/生产** - 明确区分开发文件和生产代码
|
||||||
|
4. **定期清理** - 保持仓库健康
|
||||||
|
|
||||||
|
### ❌ 避免的错误
|
||||||
|
1. **推送开发文档** - 这些文档应该放在Wiki或内部文档中
|
||||||
|
2. **混合测试代码** - 测试文件应该单独管理
|
||||||
|
3. **推送临时文件** - 运行时生成的文件不应该版本控制
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎉 最终状态
|
||||||
|
|
||||||
|
### 仓库地址
|
||||||
|
`https://git.workyai.cn/237899745/zsglpt`
|
||||||
|
|
||||||
|
### 最新提交
|
||||||
|
`00597fb` - 删除本地文档文件的最终提交
|
||||||
|
|
||||||
|
### 状态
|
||||||
|
✅ **生产环境就绪**
|
||||||
|
✅ **专业简洁**
|
||||||
|
✅ **易于维护**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 给用户的建议
|
||||||
|
|
||||||
|
### ✅ 现在可以安全使用
|
||||||
|
```bash
|
||||||
|
git clone https://git.workyai.cn/237899745/zsglpt.git
|
||||||
|
cd zsglpt
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### ✅ 部署特点
|
||||||
|
- 🚀 **一键部署** - Docker + docker-compose
|
||||||
|
- 📚 **文档完整** - README.md包含所有必要信息
|
||||||
|
- 🔧 **配置简单** - 环境变量模板
|
||||||
|
- 🛡️ **安全可靠** - 纯生产代码
|
||||||
|
|
||||||
|
### ✅ 维护友好
|
||||||
|
- 📖 **文档清晰** - 只有必要的README
|
||||||
|
- 🧹 **仓库整洁** - 无临时文件
|
||||||
|
- 🔄 **版本管理** - 清晰的提交历史
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**感谢你的提醒!仓库现在非常专业和简洁!**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*报告生成时间: 2026-01-16*
|
||||||
|
*清理操作: 用户指导完成*
|
||||||
|
*最终状态: 生产环境就绪*
|
||||||
213
README.md
213
README.md
@@ -1,30 +1,49 @@
|
|||||||
# 知识管理平台自动化工具 - Docker部署版
|
# 知识管理平台自动化工具 - Docker部署版
|
||||||
|
|
||||||
这是一个基于 Docker 的知识管理平台自动化工具,支持多用户、定时任务、代理IP、VIP管理等功能。
|
这是一个基于 Docker 的知识管理平台自动化工具,支持多用户、定时任务、代理IP、VIP管理、金山文档集成等功能。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 项目简介
|
## 项目简介
|
||||||
|
|
||||||
本项目是一个 **Docker 容器化应用**,使用 Flask + Playwright + SQLite 构建,提供:
|
本项目是一个 **Docker 容器化应用**,使用 Flask + Vue 3 + Requests + wkhtmltoimage + SQLite 构建,提供:
|
||||||
|
|
||||||
- 多用户注册登录系统
|
### 核心功能
|
||||||
- 浏览器自动化任务
|
- 多用户注册登录系统(支持邮箱绑定与验证)
|
||||||
- 定时任务调度
|
- 自动化浏览任务(纯 HTTP API 模拟,速度快)
|
||||||
- 截图管理
|
- 智能截图系统(wkhtmltoimage,支持线程池)
|
||||||
- VIP用户管理
|
- 用户自定义定时任务(支持随机延迟)
|
||||||
- 代理IP支持
|
- VIP 用户管理(账号数量限制、优先队列)
|
||||||
- 后台管理系统
|
|
||||||
|
### 集成功能
|
||||||
|
- **金山文档集成** - 自动上传截图到在线表格,支持姓名搜索匹配
|
||||||
|
- **邮件通知** - 任务完成通知、密码重置、邮箱验证
|
||||||
|
- **代理IP支持** - 动态代理API集成
|
||||||
|
|
||||||
|
### 安全功能
|
||||||
|
- 威胁检测引擎(JNDI/SQL注入/XSS/命令注入检测)
|
||||||
|
- IP/用户风险评分系统
|
||||||
|
- 自动黑名单机制
|
||||||
|
- 登录设备指纹追踪
|
||||||
|
|
||||||
|
### 管理功能
|
||||||
|
- 现代化 Vue 3 SPA 后台管理界面
|
||||||
|
- 公告系统(支持图片)
|
||||||
|
- Bug 反馈系统
|
||||||
|
- 任务日志与统计
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 技术栈
|
## 技术栈
|
||||||
|
|
||||||
- **后端**: Python 3.8+, Flask
|
- **后端**: Python 3.11+, Flask, Flask-SocketIO
|
||||||
- **数据库**: SQLite
|
- **前端**: Vue 3 + Vite + Element Plus (SPA)
|
||||||
- **自动化**: Playwright (Chromium)
|
- **数据库**: SQLite + 连接池
|
||||||
|
- **自动化**: Requests + BeautifulSoup (浏览)
|
||||||
|
- **截图**: wkhtmltoimage
|
||||||
|
- **金山文档**: Playwright (表格操作/上传)
|
||||||
- **容器化**: Docker + Docker Compose
|
- **容器化**: Docker + Docker Compose
|
||||||
- **前端**: HTML + JavaScript + Socket.IO
|
- **实时通信**: Socket.IO (WebSocket)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -34,32 +53,46 @@
|
|||||||
zsglpt/
|
zsglpt/
|
||||||
├── app.py # 启动/装配入口
|
├── app.py # 启动/装配入口
|
||||||
├── routes/ # 路由层(Blueprint)
|
├── routes/ # 路由层(Blueprint)
|
||||||
|
│ ├── api_*.py # API 路由
|
||||||
|
│ ├── admin_api/ # 管理后台 API
|
||||||
|
│ └── pages.py # 页面路由
|
||||||
├── services/ # 业务服务层
|
├── services/ # 业务服务层
|
||||||
|
│ ├── tasks.py # 任务调度器
|
||||||
|
│ ├── screenshots.py # 截图服务
|
||||||
|
│ ├── kdocs_uploader.py # 金山文档上传服务
|
||||||
|
│ └── schedule_*.py # 定时任务相关
|
||||||
|
├── security/ # 安全防护模块
|
||||||
|
│ ├── threat_detector.py # 威胁检测引擎
|
||||||
|
│ ├── risk_scorer.py # 风险评分
|
||||||
|
│ ├── blacklist.py # 黑名单管理
|
||||||
|
│ └── middleware.py # 安全中间件
|
||||||
├── realtime/ # SocketIO 事件与推送
|
├── realtime/ # SocketIO 事件与推送
|
||||||
├── database.py # 数据库稳定门面(对外 API)
|
├── database.py # 数据库稳定门面(对外 API)
|
||||||
├── db/ # DB 分域实现 + schema/migrations
|
├── db/ # DB 分域实现 + schema/migrations
|
||||||
├── db_pool.py # 数据库连接池
|
├── db_pool.py # 数据库连接池
|
||||||
├── playwright_automation.py # Playwright 自动化
|
|
||||||
├── api_browser.py # Requests 自动化(主浏览流程)
|
├── api_browser.py # Requests 自动化(主浏览流程)
|
||||||
├── browser_pool_worker.py # 截图 WorkerPool(浏览器复用)
|
├── browser_pool_worker.py # wkhtmltoimage 截图线程池
|
||||||
├── browser_installer.py # 浏览器安装检查
|
|
||||||
├── app_config.py # 配置管理
|
├── app_config.py # 配置管理
|
||||||
├── app_logger.py # 日志系统
|
├── app_logger.py # 日志系统
|
||||||
├── app_security.py # 安全模块
|
├── app_security.py # 安全工具函数
|
||||||
├── password_utils.py # 密码工具
|
├── password_utils.py # 密码哈希工具
|
||||||
├── crypto_utils.py # 加解密工具
|
├── crypto_utils.py # 加解密工具
|
||||||
├── email_service.py # 邮件服务
|
├── email_service.py # 邮件服务(SMTP)
|
||||||
├── requirements.txt # Python依赖
|
├── requirements.txt # Python依赖
|
||||||
├── requirements-dev.txt # 开发依赖(不进生产镜像)
|
├── requirements-dev.txt # 开发依赖(不进生产镜像)
|
||||||
├── pyproject.toml # ruff/black/pytest 配置
|
├── pyproject.toml # ruff/pytest 配置
|
||||||
├── Dockerfile # Docker镜像构建文件
|
├── Dockerfile # Docker镜像构建文件
|
||||||
├── docker-compose.yml # Docker编排文件
|
├── docker-compose.yml # Docker编排文件
|
||||||
├── templates/ # HTML模板(含 SPA fallback)
|
├── templates/ # HTML模板(SPA 入口)
|
||||||
├── app-frontend/ # 用户端前端源码(可选保留)
|
│ ├── app.html # 用户端 SPA 入口
|
||||||
├── admin-frontend/ # 后台前端源码(可选保留)
|
│ ├── admin.html # 管理端 SPA 入口
|
||||||
└── static/ # 前端构建产物(运行时使用)
|
│ └── email/ # 邮件模板
|
||||||
├── app/ # 用户端 SPA
|
├── app-frontend/ # 用户端 Vue 源码
|
||||||
└── admin/ # 后台 SPA
|
├── admin-frontend/ # 管理端 Vue 源码
|
||||||
|
├── static/ # 前端构建产物
|
||||||
|
│ ├── app/ # 用户端 SPA 资源
|
||||||
|
│ └── admin/ # 管理端 SPA 资源
|
||||||
|
└── tests/ # 测试用例
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -92,6 +125,42 @@ ssh -i /path/to/key root@your-server-ip
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 3. 配置加密密钥(重要!)
|
||||||
|
|
||||||
|
系统使用 Fernet 对称加密保护用户账号密码。**首次部署或迁移时必须正确配置加密密钥!**
|
||||||
|
|
||||||
|
#### 方式一:使用 .env 文件(推荐)
|
||||||
|
|
||||||
|
在项目根目录创建 `.env` 文件:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /www/wwwroot/zsgpt2
|
||||||
|
|
||||||
|
# 生成随机密钥
|
||||||
|
python3 -c "from cryptography.fernet import Fernet; print(f'ENCRYPTION_KEY_RAW={Fernet.generate_key().decode()}')" > .env
|
||||||
|
|
||||||
|
# 设置权限(仅 root 可读)
|
||||||
|
chmod 600 .env
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 方式二:已有密钥迁移
|
||||||
|
|
||||||
|
如果从其他服务器迁移,需要复制原有的密钥:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 从旧服务器复制 .env 文件
|
||||||
|
scp root@old-server:/www/wwwroot/zsgpt2/.env /www/wwwroot/zsgpt2/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### ⚠️ 重要警告
|
||||||
|
|
||||||
|
- **密钥丢失 = 所有加密密码无法解密**,必须重新录入所有账号密码
|
||||||
|
- `.env` 文件已在 `.gitignore` 中,不会被提交到 Git
|
||||||
|
- 建议将密钥备份到安全的地方(如密码管理器)
|
||||||
|
- 系统启动时会检测密钥,如果密钥丢失但存在加密数据,将拒绝启动并报错
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 快速部署
|
## 快速部署
|
||||||
|
|
||||||
### 步骤1: 上传项目文件
|
### 步骤1: 上传项目文件
|
||||||
@@ -122,8 +191,8 @@ cd /www/wwwroot/zsgpt2
|
|||||||
### 步骤4: 创建必要的目录
|
### 步骤4: 创建必要的目录
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
mkdir -p data logs 截图 playwright
|
mkdir -p data logs 截图
|
||||||
chmod 777 data logs 截图 playwright
|
chmod 777 data logs 截图
|
||||||
```
|
```
|
||||||
|
|
||||||
### 步骤5: 构建并启动Docker容器
|
### 步骤5: 构建并启动Docker容器
|
||||||
@@ -447,19 +516,19 @@ docker-compose down
|
|||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5. 浏览器下载失败
|
### 5. 截图工具未安装
|
||||||
|
|
||||||
**问题**: Playwright浏览器下载失败
|
**问题**: wkhtmltoimage 命令不存在
|
||||||
|
|
||||||
**解决方案**:
|
**解决方案**:
|
||||||
```bash
|
```bash
|
||||||
# 进入容器手动安装
|
# 进入容器手动安装
|
||||||
docker exec -it knowledge-automation-multiuser bash
|
docker exec -it knowledge-automation-multiuser bash
|
||||||
playwright install chromium
|
apt-get update
|
||||||
|
apt-get install -y wkhtmltopdf
|
||||||
|
|
||||||
# 或使用国内镜像
|
# 验证安装
|
||||||
export PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright/
|
wkhtmltoimage --version
|
||||||
playwright install chromium
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -629,9 +698,23 @@ docker logs knowledge-automation-multiuser | grep "数据库"
|
|||||||
|
|
||||||
| 变量名 | 说明 | 默认值 |
|
| 变量名 | 说明 | 默认值 |
|
||||||
|--------|------|--------|
|
|--------|------|--------|
|
||||||
|
| ENCRYPTION_KEY_RAW | 加密密钥(Fernet格式,优先级最高) | 从 .env 文件读取 |
|
||||||
|
| ENCRYPTION_KEY | 加密密钥(会通过PBKDF2派生) | - |
|
||||||
| TZ | 时区 | Asia/Shanghai |
|
| TZ | 时区 | Asia/Shanghai |
|
||||||
| PYTHONUNBUFFERED | Python输出缓冲 | 1 |
|
| PYTHONUNBUFFERED | Python输出缓冲 | 1 |
|
||||||
| PLAYWRIGHT_BROWSERS_PATH | 浏览器路径 | /ms-playwright |
|
| WKHTMLTOIMAGE_PATH | wkhtmltoimage 可执行文件路径 | 自动探测 |
|
||||||
|
| WKHTMLTOIMAGE_JS_DELAY_MS | JS 等待时间(毫秒) | 3000 |
|
||||||
|
| WKHTMLTOIMAGE_WIDTH | 截图宽度 | 1920 |
|
||||||
|
| WKHTMLTOIMAGE_HEIGHT | 截图高度(视口高度) | 1080 |
|
||||||
|
| WKHTMLTOIMAGE_FULL_PAGE | 是否输出全页截图(忽略视口高度/裁剪) | 0 |
|
||||||
|
| WKHTMLTOIMAGE_ZOOM | 渲染缩放比例 | 1.0 |
|
||||||
|
| WKHTMLTOIMAGE_CROP_WIDTH | 裁剪宽度(0 表示不裁剪) | 默认跟随截图宽度 |
|
||||||
|
| WKHTMLTOIMAGE_CROP_HEIGHT | 裁剪高度(0 表示不裁剪) | 默认跟随截图高度 |
|
||||||
|
| WKHTMLTOIMAGE_CROP_X | 裁剪起点 X | 0 |
|
||||||
|
| WKHTMLTOIMAGE_CROP_Y | 裁剪起点 Y | 0 |
|
||||||
|
| WKHTMLTOIMAGE_QUALITY | JPG截图质量 | 95 |
|
||||||
|
| WKHTMLTOIMAGE_TIMEOUT_SECONDS | 截图超时时间(秒) | 60 |
|
||||||
|
| WKHTMLTOIMAGE_USER_AGENT | 截图使用的 UA | Chrome 120 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -641,13 +724,13 @@ docker logs knowledge-automation-multiuser | grep "数据库"
|
|||||||
|
|
||||||
- **项目名称**: 知识管理平台自动化工具
|
- **项目名称**: 知识管理平台自动化工具
|
||||||
- **版本**: Docker 多用户版
|
- **版本**: Docker 多用户版
|
||||||
- **技术栈**: Python + Flask + Playwright + SQLite + Docker
|
- **技术栈**: Python + Flask + Requests + wkhtmltopdf + SQLite + Docker
|
||||||
|
|
||||||
### 常用文档链接
|
### 常用文档链接
|
||||||
|
|
||||||
- [Docker 官方文档](https://docs.docker.com/)
|
- [Docker 官方文档](https://docs.docker.com/)
|
||||||
- [Flask 官方文档](https://flask.palletsprojects.com/)
|
- [Flask 官方文档](https://flask.palletsprojects.com/)
|
||||||
- [Playwright 官方文档](https://playwright.dev/python/)
|
- [wkhtmltopdf 官方文档](https://wkhtmltopdf.org/)
|
||||||
|
|
||||||
### 故障排查
|
### 故障排查
|
||||||
|
|
||||||
@@ -666,9 +749,9 @@ docker logs knowledge-automation-multiuser | grep "数据库"
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**文档版本**: v1.0
|
**文档版本**: v2.0
|
||||||
**更新日期**: 2025-10-29
|
**更新日期**: 2026-01-08
|
||||||
**适用版本**: Docker多用户版
|
**适用版本**: Docker多用户版 + Vue SPA
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -683,8 +766,8 @@ ssh root@your-ip
|
|||||||
|
|
||||||
# 3. 进入目录并创建必要目录
|
# 3. 进入目录并创建必要目录
|
||||||
cd /www/wwwroot/zsgpt2
|
cd /www/wwwroot/zsgpt2
|
||||||
mkdir -p data logs 截图 playwright
|
mkdir -p data logs 截图
|
||||||
chmod 777 data logs 截图 playwright
|
chmod 777 data logs 截图
|
||||||
|
|
||||||
# 4. 启动容器
|
# 4. 启动容器
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
@@ -699,3 +782,49 @@ docker logs -f knowledge-automation-multiuser
|
|||||||
```
|
```
|
||||||
|
|
||||||
完成!🎉
|
完成!🎉
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 更新日志
|
||||||
|
|
||||||
|
### v2.0 (2026-01-08)
|
||||||
|
|
||||||
|
#### 新功能
|
||||||
|
- **金山文档集成**: 自动上传截图到金山文档表格
|
||||||
|
- 支持姓名搜索匹配单元格
|
||||||
|
- 支持配置有效行范围
|
||||||
|
- 支持覆盖已有图片
|
||||||
|
- 离线状态监控与邮件通知
|
||||||
|
- **Vue 3 SPA 前端**: 用户端和管理端全面升级为现代化单页应用
|
||||||
|
- Element Plus UI 组件库
|
||||||
|
- 实时任务状态更新
|
||||||
|
- 响应式设计
|
||||||
|
- **用户自定义定时任务**: 用户可创建自己的定时任务
|
||||||
|
- 支持多时间段配置
|
||||||
|
- 支持随机延迟
|
||||||
|
- 支持选择指定账号
|
||||||
|
- **安全防护系统**:
|
||||||
|
- 威胁检测引擎(JNDI/SQL注入/XSS/命令注入)
|
||||||
|
- IP/用户风险评分
|
||||||
|
- 自动黑名单机制
|
||||||
|
- **邮件通知系统**:
|
||||||
|
- 任务完成通知
|
||||||
|
- 密码重置邮件
|
||||||
|
- 邮箱验证
|
||||||
|
- **公告系统**: 支持图片的系统公告
|
||||||
|
- **Bug反馈系统**: 用户可提交问题反馈
|
||||||
|
|
||||||
|
#### 优化
|
||||||
|
- **截图线程池**: wkhtmltoimage 截图支持多线程并发
|
||||||
|
- 线程池管理,按需启动
|
||||||
|
- 空闲自动释放资源
|
||||||
|
- **二次登录机制**: 刷新"上次登录时间"显示
|
||||||
|
- **API 预热**: 启动时预热连接,减少首次请求延迟
|
||||||
|
- **数据库连接池**: 提高并发性能
|
||||||
|
|
||||||
|
### v1.0 (2025-10-29)
|
||||||
|
- 初始版本
|
||||||
|
- 多用户系统
|
||||||
|
- 基础自动化任务
|
||||||
|
- 定时任务调度
|
||||||
|
- 代理IP支持
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ export async function createAnnouncement(payload) {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function uploadAnnouncementImage(file) {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('file', file)
|
||||||
|
const { data } = await api.post('/announcements/upload_image', formData)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
export async function activateAnnouncement(id) {
|
export async function activateAnnouncement(id) {
|
||||||
const { data } = await api.post(`/announcements/${id}/activate`)
|
const { data } = await api.post(`/announcements/${id}/activate`)
|
||||||
return data
|
return data
|
||||||
@@ -24,4 +31,3 @@ export async function deleteAnnouncement(id) {
|
|||||||
const { data } = await api.delete(`/announcements/${id}`)
|
const { data } = await api.delete(`/announcements/${id}`)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
admin-frontend/src/api/browser_pool.js
Normal file
7
admin-frontend/src/api/browser_pool.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { api } from './client'
|
||||||
|
|
||||||
|
export async function fetchBrowserPoolStats() {
|
||||||
|
const { data } = await api.get('/browser_pool/stats')
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
17
admin-frontend/src/api/kdocs.js
Normal file
17
admin-frontend/src/api/kdocs.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { api } from './client'
|
||||||
|
|
||||||
|
export async function fetchKdocsStatus(params = {}) {
|
||||||
|
const { data } = await api.get('/kdocs/status', { params })
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchKdocsQr(payload = {}) {
|
||||||
|
const body = { force: true, ...payload }
|
||||||
|
const { data } = await api.post('/kdocs/qr', body)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function clearKdocsLogin() {
|
||||||
|
const { data } = await api.post('/kdocs/clear-login', {})
|
||||||
|
return data
|
||||||
|
}
|
||||||
@@ -46,6 +46,11 @@ export async function getIpRisk(ip) {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function clearIpRisk(ip) {
|
||||||
|
const { data } = await api.post('/admin/security/ip-risk/clear', { ip })
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
export async function getUserRisk(userId) {
|
export async function getUserRisk(userId) {
|
||||||
const safeUserId = encodeURIComponent(String(userId || '').trim())
|
const safeUserId = encodeURIComponent(String(userId || '').trim())
|
||||||
const { data } = await api.get(`/admin/security/user-risk/${safeUserId}`)
|
const { data } = await api.get(`/admin/security/user-risk/${safeUserId}`)
|
||||||
@@ -56,4 +61,3 @@ export async function cleanup() {
|
|||||||
const { data } = await api.post('/admin/security/cleanup', {})
|
const { data } = await api.post('/admin/security/cleanup', {})
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
import { api } from './client'
|
|
||||||
|
|
||||||
export async function fetchUpdateStatus() {
|
|
||||||
const { data } = await api.get('/update/status')
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function fetchUpdateResult() {
|
|
||||||
const { data } = await api.get('/update/result')
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function fetchUpdateLog(params = {}) {
|
|
||||||
const { data } = await api.get('/update/log', { params })
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function requestUpdateCheck() {
|
|
||||||
const { data } = await api.post('/update/check', {})
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function requestUpdateRun(payload = {}) {
|
|
||||||
const { data } = await api.post('/update/run', payload)
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref } from 'vue'
|
import { h, onMounted, ref } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
|
import { Plus } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
activateAnnouncement,
|
activateAnnouncement,
|
||||||
@@ -8,10 +9,14 @@ import {
|
|||||||
deactivateAnnouncement,
|
deactivateAnnouncement,
|
||||||
deleteAnnouncement,
|
deleteAnnouncement,
|
||||||
fetchAnnouncements,
|
fetchAnnouncements,
|
||||||
|
uploadAnnouncementImage,
|
||||||
} from '../api/announcements'
|
} from '../api/announcements'
|
||||||
|
|
||||||
const formTitle = ref('')
|
const formTitle = ref('')
|
||||||
const formContent = ref('')
|
const formContent = ref('')
|
||||||
|
const formImageUrl = ref('')
|
||||||
|
const imageInputRef = ref(null)
|
||||||
|
const uploading = ref(false)
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const list = ref([])
|
const list = ref([])
|
||||||
@@ -30,18 +35,56 @@ async function load() {
|
|||||||
function clearForm() {
|
function clearForm() {
|
||||||
formTitle.value = ''
|
formTitle.value = ''
|
||||||
formContent.value = ''
|
formContent.value = ''
|
||||||
|
formImageUrl.value = ''
|
||||||
|
if (imageInputRef.value) imageInputRef.value.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function openImagePicker() {
|
||||||
|
imageInputRef.value?.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearImage() {
|
||||||
|
formImageUrl.value = ''
|
||||||
|
if (imageInputRef.value) imageInputRef.value.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onImageFileChange(event) {
|
||||||
|
const file = event.target?.files?.[0]
|
||||||
|
if (!file) return
|
||||||
|
if (file.type && !file.type.startsWith('image/')) {
|
||||||
|
ElMessage.error('请选择图片文件')
|
||||||
|
event.target.value = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uploading.value = true
|
||||||
|
try {
|
||||||
|
const res = await uploadAnnouncementImage(file)
|
||||||
|
if (!res?.success || !res?.url) {
|
||||||
|
ElMessage.error(res?.error || '上传失败')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
formImageUrl.value = res.url
|
||||||
|
ElMessage.success('上传成功')
|
||||||
|
} catch {
|
||||||
|
// handled by interceptor
|
||||||
|
} finally {
|
||||||
|
uploading.value = false
|
||||||
|
event.target.value = ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit(isActive) {
|
async function submit(isActive) {
|
||||||
const title = formTitle.value.trim()
|
const title = formTitle.value.trim()
|
||||||
const content = formContent.value.trim()
|
const content = formContent.value.trim()
|
||||||
|
const image_url = formImageUrl.value.trim()
|
||||||
if (!title || !content) {
|
if (!title || !content) {
|
||||||
ElMessage.error('标题和内容不能为空')
|
ElMessage.error('标题和内容不能为空')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await createAnnouncement({ title, content, is_active: Boolean(isActive) })
|
const res = await createAnnouncement({ title, content, image_url, is_active: Boolean(isActive) })
|
||||||
if (!res?.success) {
|
if (!res?.success) {
|
||||||
ElMessage.error(res?.error || '保存失败')
|
ElMessage.error(res?.error || '保存失败')
|
||||||
return
|
return
|
||||||
@@ -55,7 +98,17 @@ async function submit(isActive) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function view(row) {
|
async function view(row) {
|
||||||
await ElMessageBox.alert(row.content || '', row.title || '公告', {
|
const body = h('div', { class: 'announcement-view' }, [
|
||||||
|
row.content ? h('div', { class: 'announcement-view-text' }, row.content) : null,
|
||||||
|
row.image_url
|
||||||
|
? h('img', {
|
||||||
|
class: 'announcement-view-image',
|
||||||
|
src: row.image_url,
|
||||||
|
alt: '公告图片',
|
||||||
|
})
|
||||||
|
: null,
|
||||||
|
])
|
||||||
|
await ElMessageBox.alert(body, row.title || '公告', {
|
||||||
confirmButtonText: '关闭',
|
confirmButtonText: '关闭',
|
||||||
dangerouslyUseHTMLString: false,
|
dangerouslyUseHTMLString: false,
|
||||||
})
|
})
|
||||||
@@ -162,8 +215,26 @@ onMounted(load)
|
|||||||
show-word-limit
|
show-word-limit
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="公告图片">
|
||||||
|
<div class="image-upload-row">
|
||||||
|
<el-button :icon="Plus" :loading="uploading" @click="openImagePicker">上传图片</el-button>
|
||||||
|
<el-button v-if="formImageUrl" @click="clearImage">移除</el-button>
|
||||||
|
<span v-if="formImageUrl" class="image-url">{{ formImageUrl }}</span>
|
||||||
|
<input
|
||||||
|
ref="imageInputRef"
|
||||||
|
class="image-input"
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
@change="onImageFileChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
|
<div v-if="formImageUrl" class="image-preview">
|
||||||
|
<img :src="formImageUrl" alt="公告图片预览" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<el-button type="primary" @click="submit(true)">发布并启用</el-button>
|
<el-button type="primary" @click="submit(true)">发布并启用</el-button>
|
||||||
<el-button @click="submit(false)">保存但不启用</el-button>
|
<el-button @click="submit(false)">保存但不启用</el-button>
|
||||||
@@ -193,6 +264,12 @@ onMounted(load)
|
|||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column label="图片" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag v-if="row.image_url" type="success" effect="light">有图</el-tag>
|
||||||
|
<span v-else class="app-muted">-</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column prop="created_at" label="创建时间" width="180" />
|
<el-table-column prop="created_at" label="创建时间" width="180" />
|
||||||
<el-table-column label="操作" width="260" fixed="right">
|
<el-table-column label="操作" width="260" fixed="right">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
@@ -234,6 +311,57 @@ onMounted(load)
|
|||||||
color: var(--app-muted);
|
color: var(--app-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.image-preview {
|
||||||
|
margin: 6px 0 2px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-preview img {
|
||||||
|
max-width: 280px;
|
||||||
|
max-height: 160px;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid var(--app-border);
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-upload-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-url {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--app-muted);
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.announcement-view {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.announcement-view-text {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
line-height: 1.6;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.announcement-view-image {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 320px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid var(--app-border);
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
.table-wrap {
|
.table-wrap {
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
}
|
}
|
||||||
@@ -252,4 +380,3 @@ onMounted(load)
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, inject, onMounted, ref } from 'vue'
|
import { computed, inject, onMounted, onUnmounted, ref } from 'vue'
|
||||||
import {
|
import {
|
||||||
Calendar,
|
Calendar,
|
||||||
ChatLineSquare,
|
ChatLineSquare,
|
||||||
@@ -18,13 +18,14 @@ import {
|
|||||||
import { fetchFeedbackStats } from '../api/feedbacks'
|
import { fetchFeedbackStats } from '../api/feedbacks'
|
||||||
import { fetchEmailStats } from '../api/email'
|
import { fetchEmailStats } from '../api/email'
|
||||||
import { fetchDockerStats, fetchRunningTasks, fetchServerInfo, fetchTaskStats } from '../api/tasks'
|
import { fetchDockerStats, fetchRunningTasks, fetchServerInfo, fetchTaskStats } from '../api/tasks'
|
||||||
|
import { fetchBrowserPoolStats } from '../api/browser_pool'
|
||||||
import { fetchSystemConfig } from '../api/system'
|
import { fetchSystemConfig } from '../api/system'
|
||||||
import { fetchUpdateResult, fetchUpdateStatus } from '../api/update'
|
|
||||||
|
|
||||||
const refreshStats = inject('refreshStats', null)
|
const refreshStats = inject('refreshStats', null)
|
||||||
const adminStats = inject('adminStats', null)
|
const adminStats = inject('adminStats', null)
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const refreshing = ref(false)
|
||||||
const lastUpdatedAt = ref('')
|
const lastUpdatedAt = ref('')
|
||||||
|
|
||||||
const taskStats = ref(null)
|
const taskStats = ref(null)
|
||||||
@@ -33,10 +34,8 @@ const emailStats = ref(null)
|
|||||||
const feedbackStats = ref(null)
|
const feedbackStats = ref(null)
|
||||||
const serverInfo = ref(null)
|
const serverInfo = ref(null)
|
||||||
const dockerStats = ref(null)
|
const dockerStats = ref(null)
|
||||||
|
const browserPoolStats = ref(null)
|
||||||
const systemConfig = ref(null)
|
const systemConfig = ref(null)
|
||||||
const updateStatus = ref(null)
|
|
||||||
const updateStatusError = ref('')
|
|
||||||
const updateResult = ref(null)
|
|
||||||
const queueTab = ref('running')
|
const queueTab = ref('running')
|
||||||
|
|
||||||
function recordUpdatedAt() {
|
function recordUpdatedAt() {
|
||||||
@@ -63,12 +62,6 @@ function parsePercent(value) {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortCommit(value) {
|
|
||||||
const text = String(value ?? '').trim()
|
|
||||||
if (!text) return '-'
|
|
||||||
return text.length > 12 ? `${text.slice(0, 12)}…` : text
|
|
||||||
}
|
|
||||||
|
|
||||||
function sourceLabel(source) {
|
function sourceLabel(source) {
|
||||||
const raw = String(source ?? '').trim()
|
const raw = String(source ?? '').trim()
|
||||||
if (!raw) return '手动'
|
if (!raw) return '手动'
|
||||||
@@ -107,6 +100,40 @@ const queuingTaskList = computed(() => runningTasks.value?.queuing || [])
|
|||||||
const runningCount = computed(() => normalizeCount(runningTasks.value?.running_count))
|
const runningCount = computed(() => normalizeCount(runningTasks.value?.running_count))
|
||||||
const queuingCount = computed(() => normalizeCount(runningTasks.value?.queuing_count))
|
const queuingCount = computed(() => normalizeCount(runningTasks.value?.queuing_count))
|
||||||
|
|
||||||
|
const browserPoolWorkers = computed(() => {
|
||||||
|
const workers = browserPoolStats.value?.workers
|
||||||
|
if (!Array.isArray(workers)) return []
|
||||||
|
return [...workers].sort((a, b) => normalizeCount(a?.worker_id) - normalizeCount(b?.worker_id))
|
||||||
|
})
|
||||||
|
|
||||||
|
const browserPoolTotalWorkers = computed(() => normalizeCount(browserPoolStats.value?.total_workers))
|
||||||
|
const browserPoolActiveWorkers = computed(() => browserPoolWorkers.value.filter((w) => Boolean(w?.has_browser)).length)
|
||||||
|
const browserPoolIdleWorkers = computed(() => normalizeCount(browserPoolStats.value?.idle_workers))
|
||||||
|
const browserPoolQueueSize = computed(() => normalizeCount(browserPoolStats.value?.queue_size))
|
||||||
|
const browserPoolBusyWorkers = computed(() => normalizeCount(browserPoolStats.value?.active_workers))
|
||||||
|
|
||||||
|
function workerPoolStatusType(worker) {
|
||||||
|
if (!worker?.thread_alive) return 'danger'
|
||||||
|
if (worker?.has_browser) return 'success'
|
||||||
|
return 'info'
|
||||||
|
}
|
||||||
|
|
||||||
|
function workerPoolStatusLabel(worker) {
|
||||||
|
if (!worker?.thread_alive) return '异常'
|
||||||
|
if (worker?.has_browser) return '活跃'
|
||||||
|
return '空闲'
|
||||||
|
}
|
||||||
|
|
||||||
|
function workerRunTagType(worker) {
|
||||||
|
if (!worker?.thread_alive) return 'danger'
|
||||||
|
return worker?.idle ? 'info' : 'warning'
|
||||||
|
}
|
||||||
|
|
||||||
|
function workerRunLabel(worker) {
|
||||||
|
if (!worker?.thread_alive) return '停止'
|
||||||
|
return worker?.idle ? '空闲' : '忙碌'
|
||||||
|
}
|
||||||
|
|
||||||
const taskTodaySuccessRate = computed(() => {
|
const taskTodaySuccessRate = computed(() => {
|
||||||
const success = normalizeCount(taskToday.value.success_tasks)
|
const success = normalizeCount(taskToday.value.success_tasks)
|
||||||
const failed = normalizeCount(taskToday.value.failed_tasks)
|
const failed = normalizeCount(taskToday.value.failed_tasks)
|
||||||
@@ -155,12 +182,13 @@ const runningCountsLabel = computed(() => {
|
|||||||
return `运行中 ${runningCount} / 排队 ${queuingCount} / 并发上限 ${maxGlobal || maxConcurrentGlobal.value || '-'}`
|
return `运行中 ${runningCount} / 排队 ${queuingCount} / 并发上限 ${maxGlobal || maxConcurrentGlobal.value || '-'}`
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateAvailable = computed(() => Boolean(updateStatus.value?.update_available))
|
async function refreshAll(options = {}) {
|
||||||
const updateRunning = computed(() => updateResult.value?.status === 'running')
|
const showLoading = options.showLoading ?? true
|
||||||
|
if (refreshing.value) return
|
||||||
async function refreshAll() {
|
refreshing.value = true
|
||||||
if (loading.value) return
|
if (showLoading) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const [
|
const [
|
||||||
taskResult,
|
taskResult,
|
||||||
@@ -169,9 +197,8 @@ async function refreshAll() {
|
|||||||
feedbackResult,
|
feedbackResult,
|
||||||
serverResult,
|
serverResult,
|
||||||
dockerResult,
|
dockerResult,
|
||||||
|
browserPoolResult,
|
||||||
configResult,
|
configResult,
|
||||||
updateStatusResult,
|
|
||||||
updateResultResult,
|
|
||||||
] = await Promise.allSettled([
|
] = await Promise.allSettled([
|
||||||
fetchTaskStats(),
|
fetchTaskStats(),
|
||||||
fetchRunningTasks(),
|
fetchRunningTasks(),
|
||||||
@@ -179,9 +206,8 @@ async function refreshAll() {
|
|||||||
fetchFeedbackStats(),
|
fetchFeedbackStats(),
|
||||||
fetchServerInfo(),
|
fetchServerInfo(),
|
||||||
fetchDockerStats(),
|
fetchDockerStats(),
|
||||||
|
fetchBrowserPoolStats(),
|
||||||
fetchSystemConfig(),
|
fetchSystemConfig(),
|
||||||
fetchUpdateStatus(),
|
|
||||||
fetchUpdateResult(),
|
|
||||||
])
|
])
|
||||||
|
|
||||||
taskStats.value = taskResult.status === 'fulfilled' ? taskResult.value : null
|
taskStats.value = taskResult.status === 'fulfilled' ? taskResult.value : null
|
||||||
@@ -190,32 +216,36 @@ async function refreshAll() {
|
|||||||
feedbackStats.value = feedbackResult.status === 'fulfilled' ? feedbackResult.value : null
|
feedbackStats.value = feedbackResult.status === 'fulfilled' ? feedbackResult.value : null
|
||||||
serverInfo.value = serverResult.status === 'fulfilled' ? serverResult.value : null
|
serverInfo.value = serverResult.status === 'fulfilled' ? serverResult.value : null
|
||||||
dockerStats.value = dockerResult.status === 'fulfilled' ? dockerResult.value : null
|
dockerStats.value = dockerResult.status === 'fulfilled' ? dockerResult.value : null
|
||||||
|
browserPoolStats.value = browserPoolResult.status === 'fulfilled' ? browserPoolResult.value : null
|
||||||
systemConfig.value = configResult.status === 'fulfilled' ? configResult.value : null
|
systemConfig.value = configResult.status === 'fulfilled' ? configResult.value : null
|
||||||
|
|
||||||
if (updateStatusResult.status === 'fulfilled') {
|
|
||||||
const res = updateStatusResult.value
|
|
||||||
if (res?.ok) {
|
|
||||||
updateStatus.value = res.data || null
|
|
||||||
updateStatusError.value = ''
|
|
||||||
} else {
|
|
||||||
updateStatus.value = null
|
|
||||||
updateStatusError.value = res?.error || '未发现更新状态(Update-Agent 可能未运行)'
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
updateStatus.value = null
|
|
||||||
updateStatusError.value = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
updateResult.value = updateResultResult.status === 'fulfilled' && updateResultResult.value?.ok ? updateResultResult.value.data : null
|
|
||||||
|
|
||||||
await refreshStats?.()
|
await refreshStats?.()
|
||||||
recordUpdatedAt()
|
recordUpdatedAt()
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
refreshing.value = false
|
||||||
|
if (showLoading) {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(refreshAll)
|
let refreshTimer = null
|
||||||
|
|
||||||
|
function manualRefresh() {
|
||||||
|
return refreshAll({ showLoading: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
refreshAll({ showLoading: false })
|
||||||
|
refreshTimer = setInterval(() => refreshAll({ showLoading: false }), 1000)
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (refreshTimer) {
|
||||||
|
clearInterval(refreshTimer)
|
||||||
|
refreshTimer = null
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -225,10 +255,6 @@ onMounted(refreshAll)
|
|||||||
<div class="hero-title">
|
<div class="hero-title">
|
||||||
<div class="hero-title-row">
|
<div class="hero-title-row">
|
||||||
<h2>报表中心</h2>
|
<h2>报表中心</h2>
|
||||||
<el-tag v-if="updateStatusError" type="info" effect="dark">更新状态未知</el-tag>
|
|
||||||
<el-tag v-else-if="updateAvailable" type="warning" effect="dark">新版本可更新</el-tag>
|
|
||||||
<el-tag v-else type="success" effect="dark">已是最新</el-tag>
|
|
||||||
<el-tag v-if="updateRunning" type="warning" effect="plain">更新中</el-tag>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="hero-meta app-muted">
|
<div class="hero-meta app-muted">
|
||||||
<span v-if="lastUpdatedAt">更新时间:{{ lastUpdatedAt }}</span>
|
<span v-if="lastUpdatedAt">更新时间:{{ lastUpdatedAt }}</span>
|
||||||
@@ -238,7 +264,7 @@ onMounted(refreshAll)
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hero-actions">
|
<div class="hero-actions">
|
||||||
<el-button type="primary" plain :loading="loading" @click="refreshAll">刷新</el-button>
|
<el-button type="primary" plain :loading="loading" @click="manualRefresh">刷新</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -573,6 +599,67 @@ onMounted(refreshAll)
|
|||||||
<el-descriptions-item label="内存">{{ dockerStats?.memory_usage || '-' }}</el-descriptions-item>
|
<el-descriptions-item label="内存">{{ dockerStats?.memory_usage || '-' }}</el-descriptions-item>
|
||||||
<el-descriptions-item label="内存占比">{{ dockerStats?.memory_percent || '-' }}</el-descriptions-item>
|
<el-descriptions-item label="内存占比">{{ dockerStats?.memory_percent || '-' }}</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
|
||||||
|
<div class="divider"></div>
|
||||||
|
|
||||||
|
<div class="panel-head">
|
||||||
|
<div class="head-left">
|
||||||
|
<div class="head-text">
|
||||||
|
<div class="panel-title">截图线程池</div>
|
||||||
|
<div class="panel-sub app-muted">
|
||||||
|
活跃(有执行环境){{ browserPoolActiveWorkers }} · 忙碌 {{ browserPoolBusyWorkers }} · 队列 {{ browserPoolQueueSize }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<el-tag v-if="browserPoolStats?.server_time_cst" effect="light" type="info">{{ browserPoolStats.server_time_cst }}</el-tag>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tile-grid tile-grid--4">
|
||||||
|
<div class="tile">
|
||||||
|
<div class="tile-v">{{ browserPoolTotalWorkers }}</div>
|
||||||
|
<div class="tile-k app-muted">总 Worker</div>
|
||||||
|
</div>
|
||||||
|
<div class="tile">
|
||||||
|
<div class="tile-v ok">{{ browserPoolActiveWorkers }}</div>
|
||||||
|
<div class="tile-k app-muted">活跃(有执行环境)</div>
|
||||||
|
</div>
|
||||||
|
<div class="tile">
|
||||||
|
<div class="tile-v">{{ browserPoolIdleWorkers }}</div>
|
||||||
|
<div class="tile-k app-muted">空闲(无任务)</div>
|
||||||
|
</div>
|
||||||
|
<div class="tile">
|
||||||
|
<div class="tile-v warn">{{ browserPoolQueueSize }}</div>
|
||||||
|
<div class="tile-k app-muted">队列等待</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="divider"></div>
|
||||||
|
|
||||||
|
<div class="table-wrap">
|
||||||
|
<el-table :data="browserPoolWorkers" size="small" border>
|
||||||
|
<el-table-column prop="worker_id" label="Worker" width="90" />
|
||||||
|
<el-table-column label="状态" width="90">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag :type="workerPoolStatusType(row)" effect="light">{{ workerPoolStatusLabel(row) }}</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="执行" width="90">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag :type="workerRunTagType(row)" effect="light">{{ workerRunLabel(row) }}</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="任务" width="120">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span>{{ normalizeCount(row?.total_tasks) }}</span>
|
||||||
|
<span class="app-muted"> / </span>
|
||||||
|
<span :class="normalizeCount(row?.failed_tasks) ? 'err' : 'app-muted'">{{ normalizeCount(row?.failed_tasks) }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column prop="browser_use_count" label="复用" width="90" />
|
||||||
|
<el-table-column prop="last_active_at" label="最近活跃" min-width="160" />
|
||||||
|
<el-table-column prop="browser_created_at" label="环境创建" min-width="160" />
|
||||||
|
</el-table>
|
||||||
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
|
||||||
@@ -584,21 +671,12 @@ onMounted(refreshAll)
|
|||||||
<el-icon><Tools /></el-icon>
|
<el-icon><Tools /></el-icon>
|
||||||
</div>
|
</div>
|
||||||
<div class="head-text">
|
<div class="head-text">
|
||||||
<div class="panel-title">配置与更新</div>
|
<div class="panel-title">配置概览</div>
|
||||||
<div class="panel-sub app-muted">定时/代理/并发与版本</div>
|
<div class="panel-sub app-muted">定时 / 代理 / 并发</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<el-tag v-if="updateAvailable" effect="dark" type="warning">可更新</el-tag>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-alert
|
|
||||||
v-if="updateStatusError"
|
|
||||||
type="info"
|
|
||||||
:closable="false"
|
|
||||||
:title="updateStatusError"
|
|
||||||
style="margin-bottom: 12px"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="config-grid">
|
<div class="config-grid">
|
||||||
<div class="config-item">
|
<div class="config-item">
|
||||||
<div class="config-k app-muted">定时任务</div>
|
<div class="config-k app-muted">定时任务</div>
|
||||||
@@ -631,18 +709,6 @@ onMounted(refreshAll)
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="divider"></div>
|
|
||||||
|
|
||||||
<div class="sub-title">版本信息</div>
|
|
||||||
<el-descriptions border :column="1" size="small">
|
|
||||||
<el-descriptions-item label="本地版本(commit)">{{ shortCommit(updateStatus?.local_commit) }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="远端版本(commit)">{{ shortCommit(updateStatus?.remote_commit) }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="最近检查时间">{{ updateStatus?.checked_at || '-' }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item v-if="updateResult?.job_id" label="最近更新">
|
|
||||||
<span>job {{ updateResult.job_id }} / {{ updateResult?.status || '-' }}</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
@@ -947,6 +1013,10 @@ onMounted(refreshAll)
|
|||||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tile-grid--4 {
|
||||||
|
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
.tile {
|
.tile {
|
||||||
border: 1px solid rgba(17, 24, 39, 0.08);
|
border: 1px solid rgba(17, 24, 39, 0.08);
|
||||||
border-radius: 16px;
|
border-radius: 16px;
|
||||||
@@ -1118,6 +1188,10 @@ onMounted(refreshAll)
|
|||||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tile-grid--4 {
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
.resource-grid {
|
.resource-grid {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
banIp,
|
banIp,
|
||||||
banUser,
|
banUser,
|
||||||
cleanup,
|
cleanup,
|
||||||
|
clearIpRisk,
|
||||||
getBannedIps,
|
getBannedIps,
|
||||||
getBannedUsers,
|
getBannedUsers,
|
||||||
getDashboard,
|
getDashboard,
|
||||||
@@ -381,6 +382,35 @@ async function unbanFromRisk() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function clearIpRiskScore() {
|
||||||
|
if (riskResultKind.value !== 'ip') return
|
||||||
|
const ipText = String(riskResult.value?.ip || '').trim()
|
||||||
|
if (!ipText) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await ElMessageBox.confirm(
|
||||||
|
`确定清除 IP ${ipText} 的风险分吗?\n\n清除风险分不会删除威胁历史,也不会解除封禁。`,
|
||||||
|
'清除风险分',
|
||||||
|
{ confirmButtonText: '清除', cancelButtonText: '取消', type: 'warning' },
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (riskLoading.value) return
|
||||||
|
riskLoading.value = true
|
||||||
|
try {
|
||||||
|
await clearIpRisk(ipText)
|
||||||
|
ElMessage.success('IP风险分已清零')
|
||||||
|
} catch {
|
||||||
|
// handled by interceptor
|
||||||
|
} finally {
|
||||||
|
riskLoading.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
await queryIpRisk()
|
||||||
|
}
|
||||||
|
|
||||||
const cleanupLoading = ref(false)
|
const cleanupLoading = ref(false)
|
||||||
|
|
||||||
async function onCleanup() {
|
async function onCleanup() {
|
||||||
@@ -613,6 +643,15 @@ onMounted(async () => {
|
|||||||
<div class="toolbar">
|
<div class="toolbar">
|
||||||
<el-button v-if="!riskResult.is_banned" type="primary" plain @click="openBanFromRisk">封禁</el-button>
|
<el-button v-if="!riskResult.is_banned" type="primary" plain @click="openBanFromRisk">封禁</el-button>
|
||||||
<el-button v-else type="danger" plain @click="unbanFromRisk">解除封禁</el-button>
|
<el-button v-else type="danger" plain @click="unbanFromRisk">解除封禁</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="riskResultKind === 'ip'"
|
||||||
|
type="warning"
|
||||||
|
plain
|
||||||
|
:loading="riskLoading"
|
||||||
|
@click="clearIpRiskScore"
|
||||||
|
>
|
||||||
|
清除风险分
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,14 @@ const username = ref('')
|
|||||||
const password = ref('')
|
const password = ref('')
|
||||||
const submitting = ref(false)
|
const submitting = ref(false)
|
||||||
|
|
||||||
|
function validateStrongPassword(value) {
|
||||||
|
const text = String(value || '')
|
||||||
|
if (text.length < 8) return { ok: false, message: '密码长度至少8位' }
|
||||||
|
if (text.length > 128) return { ok: false, message: '密码长度不能超过128个字符' }
|
||||||
|
if (!/[a-zA-Z]/.test(text) || !/\d/.test(text)) return { ok: false, message: '密码必须包含字母和数字' }
|
||||||
|
return { ok: true, message: '' }
|
||||||
|
}
|
||||||
|
|
||||||
async function relogin() {
|
async function relogin() {
|
||||||
try {
|
try {
|
||||||
await logout()
|
await logout()
|
||||||
@@ -54,8 +62,9 @@ async function savePassword() {
|
|||||||
ElMessage.error('请输入新密码')
|
ElMessage.error('请输入新密码')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (value.length < 6) {
|
const check = validateStrongPassword(value)
|
||||||
ElMessage.error('密码至少6个字符')
|
if (!check.ok) {
|
||||||
|
ElMessage.error(check.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
|
|
||||||
import { fetchSystemConfig, updateSystemConfig, executeScheduleNow } from '../api/system'
|
import { fetchSystemConfig, updateSystemConfig, executeScheduleNow } from '../api/system'
|
||||||
|
import { fetchKdocsQr, fetchKdocsStatus, clearKdocsLogin } from '../api/kdocs'
|
||||||
import { fetchProxyConfig, testProxy, updateProxyConfig } from '../api/proxy'
|
import { fetchProxyConfig, testProxy, updateProxyConfig } from '../api/proxy'
|
||||||
import { fetchUpdateLog, fetchUpdateResult, fetchUpdateStatus, requestUpdateCheck, requestUpdateRun } from '../api/update'
|
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ const scheduleEnabled = ref(false)
|
|||||||
const scheduleTime = ref('02:00')
|
const scheduleTime = ref('02:00')
|
||||||
const scheduleBrowseType = ref('应读')
|
const scheduleBrowseType = ref('应读')
|
||||||
const scheduleWeekdays = ref(['1', '2', '3', '4', '5', '6', '7'])
|
const scheduleWeekdays = ref(['1', '2', '3', '4', '5', '6', '7'])
|
||||||
|
const scheduleScreenshotEnabled = ref(true)
|
||||||
|
|
||||||
// 代理
|
// 代理
|
||||||
const proxyEnabled = ref(false)
|
const proxyEnabled = ref(false)
|
||||||
@@ -29,16 +30,27 @@ const autoApproveEnabled = ref(false)
|
|||||||
const autoApproveHourlyLimit = ref(10)
|
const autoApproveHourlyLimit = ref(10)
|
||||||
const autoApproveVipDays = ref(7)
|
const autoApproveVipDays = ref(7)
|
||||||
|
|
||||||
// 自动更新
|
// 金山文档上传
|
||||||
const updateLoading = ref(false)
|
const kdocsEnabled = ref(false)
|
||||||
const updateActionLoading = ref(false)
|
const kdocsDocUrl = ref('')
|
||||||
const updateStatus = ref(null)
|
const kdocsDefaultUnit = ref('')
|
||||||
const updateStatusError = ref('')
|
const kdocsSheetName = ref('')
|
||||||
const updateResult = ref(null)
|
const kdocsSheetIndex = ref(0)
|
||||||
const updateLog = ref('')
|
const kdocsUnitColumn = ref('A')
|
||||||
const updateLogTruncated = ref(false)
|
const kdocsImageColumn = ref('D')
|
||||||
const updateBuildNoCache = ref(false)
|
const kdocsRowStart = ref(0)
|
||||||
let updatePollTimer = null
|
const kdocsRowEnd = ref(0)
|
||||||
|
const kdocsAdminNotifyEnabled = ref(false)
|
||||||
|
const kdocsAdminNotifyEmail = ref('')
|
||||||
|
const kdocsStatus = ref({})
|
||||||
|
const kdocsQrOpen = ref(false)
|
||||||
|
const kdocsQrImage = ref('')
|
||||||
|
const kdocsPolling = ref(false)
|
||||||
|
const kdocsStatusLoading = ref(false)
|
||||||
|
const kdocsQrLoading = ref(false)
|
||||||
|
const kdocsClearLoading = ref(false)
|
||||||
|
const kdocsActionHint = ref('')
|
||||||
|
let kdocsPollingTimer = null
|
||||||
|
|
||||||
const weekdaysOptions = [
|
const weekdaysOptions = [
|
||||||
{ label: '周一', value: '1' },
|
{ label: '周一', value: '1' },
|
||||||
@@ -65,69 +77,32 @@ const scheduleWeekdayDisplay = computed(() =>
|
|||||||
.map((d) => weekdayNames[Number(d)] || d)
|
.map((d) => weekdayNames[Number(d)] || d)
|
||||||
.join('、'),
|
.join('、'),
|
||||||
)
|
)
|
||||||
|
const kdocsActionBusy = computed(
|
||||||
|
() => kdocsStatusLoading.value || kdocsQrLoading.value || kdocsClearLoading.value,
|
||||||
|
)
|
||||||
|
|
||||||
function normalizeBrowseType(value) {
|
function normalizeBrowseType(value) {
|
||||||
if (String(value) === '注册前未读') return '注册前未读'
|
if (String(value) === '注册前未读') return '注册前未读'
|
||||||
return '应读'
|
return '应读'
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortCommit(value) {
|
function setKdocsHint(message) {
|
||||||
const text = String(value || '').trim()
|
if (!message) {
|
||||||
if (!text) return '-'
|
kdocsActionHint.value = ''
|
||||||
return text.length > 12 ? `${text.slice(0, 12)}…` : text
|
return
|
||||||
}
|
|
||||||
|
|
||||||
async function loadUpdateInfo({ withLog = true } = {}) {
|
|
||||||
updateLoading.value = true
|
|
||||||
updateStatusError.value = ''
|
|
||||||
try {
|
|
||||||
const [statusRes, resultRes] = await Promise.all([fetchUpdateStatus(), fetchUpdateResult()])
|
|
||||||
|
|
||||||
if (statusRes?.ok) {
|
|
||||||
updateStatus.value = statusRes.data || null
|
|
||||||
} else {
|
|
||||||
updateStatus.value = null
|
|
||||||
updateStatusError.value = statusRes?.error || '未发现更新状态(Update-Agent 可能未运行)'
|
|
||||||
}
|
|
||||||
|
|
||||||
updateResult.value = resultRes?.ok ? resultRes.data : null
|
|
||||||
|
|
||||||
const jobId = updateResult.value?.job_id
|
|
||||||
if (withLog && jobId) {
|
|
||||||
const logRes = await fetchUpdateLog({ job_id: jobId, max_bytes: 200000 })
|
|
||||||
updateLog.value = logRes?.log || ''
|
|
||||||
updateLogTruncated.value = !!logRes?.truncated
|
|
||||||
} else {
|
|
||||||
updateLog.value = ''
|
|
||||||
updateLogTruncated.value = false
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// handled by interceptor
|
|
||||||
} finally {
|
|
||||||
updateLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function startUpdatePolling() {
|
|
||||||
if (updatePollTimer) return
|
|
||||||
updatePollTimer = setInterval(async () => {
|
|
||||||
if (updateResult.value?.status === 'running') {
|
|
||||||
await loadUpdateInfo()
|
|
||||||
}
|
|
||||||
}, 5000)
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopUpdatePolling() {
|
|
||||||
if (updatePollTimer) {
|
|
||||||
clearInterval(updatePollTimer)
|
|
||||||
updatePollTimer = null
|
|
||||||
}
|
}
|
||||||
|
const time = new Date().toLocaleTimeString('zh-CN', { hour12: false })
|
||||||
|
kdocsActionHint.value = `${message} (${time})`
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadAll() {
|
async function loadAll() {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const [system, proxy] = await Promise.all([fetchSystemConfig(), fetchProxyConfig()])
|
const [system, proxy, kdocsInfo] = await Promise.all([
|
||||||
|
fetchSystemConfig(),
|
||||||
|
fetchProxyConfig(),
|
||||||
|
fetchKdocsStatus().catch(() => ({})),
|
||||||
|
])
|
||||||
|
|
||||||
maxConcurrentGlobal.value = system.max_concurrent_global ?? 2
|
maxConcurrentGlobal.value = system.max_concurrent_global ?? 2
|
||||||
maxConcurrentPerAccount.value = system.max_concurrent_per_account ?? 1
|
maxConcurrentPerAccount.value = system.max_concurrent_per_account ?? 1
|
||||||
@@ -142,6 +117,7 @@ async function loadAll() {
|
|||||||
.map((x) => x.trim())
|
.map((x) => x.trim())
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
scheduleWeekdays.value = weekdays.length ? weekdays : ['1', '2', '3', '4', '5', '6', '7']
|
scheduleWeekdays.value = weekdays.length ? weekdays : ['1', '2', '3', '4', '5', '6', '7']
|
||||||
|
scheduleScreenshotEnabled.value = (system.enable_screenshot ?? 1) === 1
|
||||||
|
|
||||||
autoApproveEnabled.value = (system.auto_approve_enabled ?? 0) === 1
|
autoApproveEnabled.value = (system.auto_approve_enabled ?? 0) === 1
|
||||||
autoApproveHourlyLimit.value = system.auto_approve_hourly_limit ?? 10
|
autoApproveHourlyLimit.value = system.auto_approve_hourly_limit ?? 10
|
||||||
@@ -151,8 +127,18 @@ async function loadAll() {
|
|||||||
proxyApiUrl.value = proxy.proxy_api_url || ''
|
proxyApiUrl.value = proxy.proxy_api_url || ''
|
||||||
proxyExpireMinutes.value = proxy.proxy_expire_minutes ?? 3
|
proxyExpireMinutes.value = proxy.proxy_expire_minutes ?? 3
|
||||||
|
|
||||||
await loadUpdateInfo({ withLog: false })
|
kdocsEnabled.value = (system.kdocs_enabled ?? 0) === 1
|
||||||
startUpdatePolling()
|
kdocsDocUrl.value = system.kdocs_doc_url || ''
|
||||||
|
kdocsDefaultUnit.value = system.kdocs_default_unit || ''
|
||||||
|
kdocsSheetName.value = system.kdocs_sheet_name || ''
|
||||||
|
kdocsSheetIndex.value = system.kdocs_sheet_index ?? 0
|
||||||
|
kdocsUnitColumn.value = (system.kdocs_unit_column || 'A').toUpperCase()
|
||||||
|
kdocsImageColumn.value = (system.kdocs_image_column || 'D').toUpperCase()
|
||||||
|
kdocsRowStart.value = system.kdocs_row_start ?? 0
|
||||||
|
kdocsRowEnd.value = system.kdocs_row_end ?? 0
|
||||||
|
kdocsAdminNotifyEnabled.value = (system.kdocs_admin_notify_enabled ?? 0) === 1
|
||||||
|
kdocsAdminNotifyEmail.value = system.kdocs_admin_notify_email || ''
|
||||||
|
kdocsStatus.value = kdocsInfo || {}
|
||||||
} catch {
|
} catch {
|
||||||
// handled by interceptor
|
// handled by interceptor
|
||||||
} finally {
|
} finally {
|
||||||
@@ -196,10 +182,12 @@ async function saveSchedule() {
|
|||||||
schedule_time: scheduleTime.value,
|
schedule_time: scheduleTime.value,
|
||||||
schedule_browse_type: scheduleBrowseType.value,
|
schedule_browse_type: scheduleBrowseType.value,
|
||||||
schedule_weekdays: (scheduleWeekdays.value || []).join(','),
|
schedule_weekdays: (scheduleWeekdays.value || []).join(','),
|
||||||
|
enable_screenshot: scheduleScreenshotEnabled.value ? 1 : 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const screenshotText = scheduleScreenshotEnabled.value ? '截图' : '不截图'
|
||||||
const message = scheduleEnabled.value
|
const message = scheduleEnabled.value
|
||||||
? `确定启用定时任务吗?\n\n执行时间: 每天 ${payload.schedule_time}\n执行日期: ${scheduleWeekdayDisplay.value}\n浏览类型: ${payload.schedule_browse_type}\n\n系统将自动执行所有账号的浏览任务(不包含截图)`
|
? `确定启用定时任务吗?\n\n执行时间: 每天 ${payload.schedule_time}\n执行日期: ${scheduleWeekdayDisplay.value}\n浏览类型: ${payload.schedule_browse_type}\n截图: ${screenshotText}\n\n系统将自动执行所有账号的浏览任务`
|
||||||
: '确定关闭定时任务吗?'
|
: '确定关闭定时任务吗?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -260,6 +248,133 @@ async function saveProxy() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function saveKdocsConfig() {
|
||||||
|
const payload = {
|
||||||
|
kdocs_enabled: kdocsEnabled.value ? 1 : 0,
|
||||||
|
kdocs_doc_url: kdocsDocUrl.value.trim(),
|
||||||
|
kdocs_default_unit: kdocsDefaultUnit.value.trim(),
|
||||||
|
kdocs_sheet_name: kdocsSheetName.value.trim(),
|
||||||
|
kdocs_sheet_index: Number(kdocsSheetIndex.value) || 0,
|
||||||
|
kdocs_unit_column: kdocsUnitColumn.value.trim().toUpperCase(),
|
||||||
|
kdocs_image_column: kdocsImageColumn.value.trim().toUpperCase(),
|
||||||
|
kdocs_row_start: Number(kdocsRowStart.value) || 0,
|
||||||
|
kdocs_row_end: Number(kdocsRowEnd.value) || 0,
|
||||||
|
kdocs_admin_notify_enabled: kdocsAdminNotifyEnabled.value ? 1 : 0,
|
||||||
|
kdocs_admin_notify_email: kdocsAdminNotifyEmail.value.trim(),
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await updateSystemConfig(payload)
|
||||||
|
ElMessage.success(res?.message || '表格配置已更新')
|
||||||
|
} catch {
|
||||||
|
// handled by interceptor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshKdocsStatus() {
|
||||||
|
if (kdocsStatusLoading.value) return
|
||||||
|
kdocsStatusLoading.value = true
|
||||||
|
setKdocsHint('正在刷新状态')
|
||||||
|
try {
|
||||||
|
kdocsStatus.value = await fetchKdocsStatus({ live: 1 })
|
||||||
|
setKdocsHint('状态已刷新')
|
||||||
|
} catch {
|
||||||
|
setKdocsHint('刷新失败,请稍后重试')
|
||||||
|
} finally {
|
||||||
|
kdocsStatusLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pollKdocsStatus() {
|
||||||
|
try {
|
||||||
|
const status = await fetchKdocsStatus({ live: 1 })
|
||||||
|
kdocsStatus.value = status
|
||||||
|
const loggedIn = status?.logged_in === true || status?.last_login_ok === true
|
||||||
|
if (loggedIn) {
|
||||||
|
ElMessage.success('扫码成功,已登录')
|
||||||
|
setKdocsHint('扫码成功,已登录')
|
||||||
|
kdocsQrOpen.value = false
|
||||||
|
stopKdocsPolling()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// handled by interceptor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startKdocsPolling() {
|
||||||
|
stopKdocsPolling()
|
||||||
|
kdocsPolling.value = true
|
||||||
|
setKdocsHint('扫码检测中')
|
||||||
|
pollKdocsStatus()
|
||||||
|
kdocsPollingTimer = setInterval(pollKdocsStatus, 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopKdocsPolling() {
|
||||||
|
if (kdocsPollingTimer) {
|
||||||
|
clearInterval(kdocsPollingTimer)
|
||||||
|
kdocsPollingTimer = null
|
||||||
|
}
|
||||||
|
kdocsPolling.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onFetchKdocsQr() {
|
||||||
|
if (kdocsQrLoading.value) return
|
||||||
|
kdocsQrLoading.value = true
|
||||||
|
setKdocsHint('正在获取二维码')
|
||||||
|
try {
|
||||||
|
kdocsQrImage.value = ''
|
||||||
|
const res = await fetchKdocsQr()
|
||||||
|
kdocsQrImage.value = res?.qr_image || ''
|
||||||
|
if (!kdocsQrImage.value) {
|
||||||
|
if (res?.logged_in) {
|
||||||
|
ElMessage.success('当前已登录,无需扫码')
|
||||||
|
setKdocsHint('当前已登录,无需扫码')
|
||||||
|
await refreshKdocsStatus()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ElMessage.warning('未获取到二维码')
|
||||||
|
setKdocsHint('未获取到二维码')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setKdocsHint('二维码已获取')
|
||||||
|
kdocsQrOpen.value = true
|
||||||
|
} catch {
|
||||||
|
setKdocsHint('获取二维码失败')
|
||||||
|
} finally {
|
||||||
|
kdocsQrLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onClearKdocsLogin() {
|
||||||
|
if (kdocsClearLoading.value) return
|
||||||
|
kdocsClearLoading.value = true
|
||||||
|
setKdocsHint('正在清除登录态')
|
||||||
|
try {
|
||||||
|
await clearKdocsLogin()
|
||||||
|
kdocsQrOpen.value = false
|
||||||
|
kdocsQrImage.value = ''
|
||||||
|
ElMessage.success('登录态已清除')
|
||||||
|
setKdocsHint('登录态已清除')
|
||||||
|
await refreshKdocsStatus()
|
||||||
|
} catch {
|
||||||
|
setKdocsHint('清除登录态失败')
|
||||||
|
} finally {
|
||||||
|
kdocsClearLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(kdocsQrOpen, (open) => {
|
||||||
|
if (open) {
|
||||||
|
startKdocsPolling()
|
||||||
|
} else {
|
||||||
|
stopKdocsPolling()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
stopKdocsPolling()
|
||||||
|
})
|
||||||
|
|
||||||
async function onTestProxy() {
|
async function onTestProxy() {
|
||||||
if (!proxyApiUrl.value.trim()) {
|
if (!proxyApiUrl.value.trim()) {
|
||||||
ElMessage.error('请先输入代理API地址')
|
ElMessage.error('请先输入代理API地址')
|
||||||
@@ -301,49 +416,7 @@ async function saveAutoApprove() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onCheckUpdate() {
|
|
||||||
updateActionLoading.value = true
|
|
||||||
try {
|
|
||||||
const res = await requestUpdateCheck()
|
|
||||||
ElMessage.success(res?.success ? '已触发检查更新' : '已提交检查请求')
|
|
||||||
setTimeout(() => loadUpdateInfo({ withLog: false }), 800)
|
|
||||||
} catch {
|
|
||||||
// handled by interceptor
|
|
||||||
} finally {
|
|
||||||
updateActionLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onRunUpdate() {
|
|
||||||
const status = updateStatus.value
|
|
||||||
const remote = status?.remote_commit ? shortCommit(status.remote_commit) : '-'
|
|
||||||
const buildFlags = updateBuildNoCache.value ? '\n\n构建选项: 强制重建(--no-cache)' : ''
|
|
||||||
|
|
||||||
try {
|
|
||||||
await ElMessageBox.confirm(
|
|
||||||
`确定开始“一键更新”吗?\n\n目标版本: ${remote}${buildFlags}\n\n更新将会重建并重启服务,页面可能短暂不可用;系统会先备份数据库。`,
|
|
||||||
'一键更新确认',
|
|
||||||
{ confirmButtonText: '开始更新', cancelButtonText: '取消', type: 'warning' },
|
|
||||||
)
|
|
||||||
} catch {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
updateActionLoading.value = true
|
|
||||||
try {
|
|
||||||
const res = await requestUpdateRun({ build_no_cache: updateBuildNoCache.value ? 1 : 0 })
|
|
||||||
ElMessage.success(res?.message || '已提交更新请求')
|
|
||||||
startUpdatePolling()
|
|
||||||
setTimeout(() => loadUpdateInfo(), 800)
|
|
||||||
} catch {
|
|
||||||
// handled by interceptor
|
|
||||||
} finally {
|
|
||||||
updateActionLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(loadAll)
|
onMounted(loadAll)
|
||||||
onBeforeUnmount(stopUpdatePolling)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -371,7 +444,7 @@ onBeforeUnmount(stopUpdatePolling)
|
|||||||
|
|
||||||
<el-form-item label="截图最大并发数">
|
<el-form-item label="截图最大并发数">
|
||||||
<el-input-number v-model="maxScreenshotConcurrent" :min="1" :max="50" />
|
<el-input-number v-model="maxScreenshotConcurrent" :min="1" :max="50" />
|
||||||
<div class="help">同时进行截图的最大数量(每个浏览器约占用 200MB 内存)。</div>
|
<div class="help">同时进行截图的最大数量(wkhtmltoimage 资源占用较低,可按需提高)。</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
@@ -384,6 +457,7 @@ onBeforeUnmount(stopUpdatePolling)
|
|||||||
<el-form label-width="130px">
|
<el-form label-width="130px">
|
||||||
<el-form-item label="启用定时任务">
|
<el-form-item label="启用定时任务">
|
||||||
<el-switch v-model="scheduleEnabled" />
|
<el-switch v-model="scheduleEnabled" />
|
||||||
|
<div class="help">开启后,系统会按计划自动执行浏览任务。</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item v-if="scheduleEnabled" label="执行时间">
|
<el-form-item v-if="scheduleEnabled" label="执行时间">
|
||||||
@@ -404,6 +478,11 @@ onBeforeUnmount(stopUpdatePolling)
|
|||||||
</el-checkbox>
|
</el-checkbox>
|
||||||
</el-checkbox-group>
|
</el-checkbox-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item v-if="scheduleEnabled" label="定时任务截图">
|
||||||
|
<el-switch v-model="scheduleScreenshotEnabled" />
|
||||||
|
<div class="help">开启后,定时任务执行时会生成截图。</div>
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
||||||
<div class="row-actions">
|
<div class="row-actions">
|
||||||
@@ -458,88 +537,104 @@ onBeforeUnmount(stopUpdatePolling)
|
|||||||
<el-button type="primary" @click="saveAutoApprove">保存注册设置</el-button>
|
<el-button type="primary" @click="saveAutoApprove">保存注册设置</el-button>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
<el-card shadow="never" :body-style="{ padding: '16px' }" class="card" v-loading="updateLoading">
|
<el-card shadow="never" :body-style="{ padding: '16px' }" class="card">
|
||||||
<h3 class="section-title">版本与更新</h3>
|
<h3 class="section-title">金山文档上传</h3>
|
||||||
|
|
||||||
<el-alert
|
<el-form label-width="130px">
|
||||||
v-if="updateStatus?.update_available"
|
<el-form-item label="启用上传">
|
||||||
type="warning"
|
<el-switch v-model="kdocsEnabled" />
|
||||||
:closable="false"
|
<div class="help">表格结构变化时可先关闭,避免错误上传。</div>
|
||||||
title="检测到新版本:可以在此页面点击“一键更新”升级并自动重启服务。"
|
</el-form-item>
|
||||||
style="margin-bottom: 10px"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<el-alert
|
<el-form-item label="文档链接">
|
||||||
v-if="updateStatusError"
|
<el-input v-model="kdocsDocUrl" placeholder="https://kdocs.cn/..." />
|
||||||
type="info"
|
</el-form-item>
|
||||||
:closable="false"
|
|
||||||
:title="updateStatusError"
|
|
||||||
style="margin-bottom: 10px"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<el-descriptions border :column="1" size="small" style="margin-bottom: 10px">
|
<el-form-item label="默认县区">
|
||||||
<el-descriptions-item label="本地版本(commit)">
|
<el-input v-model="kdocsDefaultUnit" placeholder="如:道县(用户可覆盖)" />
|
||||||
{{ shortCommit(updateStatus?.local_commit) }}
|
</el-form-item>
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="远端版本(commit)">
|
|
||||||
{{ shortCommit(updateStatus?.remote_commit) }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="是否有更新">
|
|
||||||
<el-tag v-if="updateStatus?.update_available" type="danger">有</el-tag>
|
|
||||||
<el-tag v-else type="success">无</el-tag>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="工作区修改">
|
|
||||||
<el-tag v-if="updateStatus?.dirty" type="warning">有未提交修改</el-tag>
|
|
||||||
<el-tag v-else type="info">干净</el-tag>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="最近检查时间">
|
|
||||||
{{ updateStatus?.checked_at || '-' }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item v-if="updateStatus?.error" label="检查错误">
|
|
||||||
{{ updateStatus?.error }}
|
|
||||||
</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
|
||||||
|
|
||||||
<div class="row-actions" style="align-items: center">
|
<el-form-item label="Sheet名称">
|
||||||
<el-checkbox v-model="updateBuildNoCache">强制重建(--no-cache)</el-checkbox>
|
<el-input v-model="kdocsSheetName" placeholder="留空使用第一个Sheet" />
|
||||||
<div class="help" style="margin-top: 0">依赖变更或构建异常时建议开启(更新会更慢)。</div>
|
</el-form-item>
|
||||||
</div>
|
|
||||||
|
<el-form-item label="Sheet序号">
|
||||||
|
<el-input-number v-model="kdocsSheetIndex" :min="0" :max="50" />
|
||||||
|
<div class="help">0 表示第一个Sheet。</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="县区列">
|
||||||
|
<el-input v-model="kdocsUnitColumn" placeholder="A" style="max-width: 120px" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="图片列">
|
||||||
|
<el-input v-model="kdocsImageColumn" placeholder="D" style="max-width: 120px" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="有效行范围">
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px;">
|
||||||
|
<el-input-number v-model="kdocsRowStart" :min="0" :max="10000" placeholder="起始行" style="width: 120px" />
|
||||||
|
<span>至</span>
|
||||||
|
<el-input-number v-model="kdocsRowEnd" :min="0" :max="10000" placeholder="结束行" style="width: 120px" />
|
||||||
|
</div>
|
||||||
|
<div class="help">限制上传的行范围(如 50-100),0 表示不限制。用于防止重名导致误传到其他县区。</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="管理员通知">
|
||||||
|
<el-switch v-model="kdocsAdminNotifyEnabled" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="通知邮箱">
|
||||||
|
<el-input v-model="kdocsAdminNotifyEmail" placeholder="admin@example.com" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
<div class="row-actions">
|
<div class="row-actions">
|
||||||
<el-button @click="loadUpdateInfo" :disabled="updateActionLoading">刷新更新信息</el-button>
|
<el-button type="primary" @click="saveKdocsConfig">保存表格配置</el-button>
|
||||||
<el-button @click="onCheckUpdate" :loading="updateActionLoading">检查更新</el-button>
|
<el-button
|
||||||
<el-button type="danger" @click="onRunUpdate" :loading="updateActionLoading" :disabled="!updateStatus?.update_available">
|
:loading="kdocsStatusLoading"
|
||||||
一键更新
|
:disabled="kdocsActionBusy && !kdocsStatusLoading"
|
||||||
|
@click="refreshKdocsStatus"
|
||||||
|
>
|
||||||
|
刷新状态
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="success"
|
||||||
|
plain
|
||||||
|
:loading="kdocsQrLoading"
|
||||||
|
:disabled="kdocsActionBusy && !kdocsQrLoading"
|
||||||
|
@click="onFetchKdocsQr"
|
||||||
|
>
|
||||||
|
获取二维码
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
type="danger"
|
||||||
|
plain
|
||||||
|
:loading="kdocsClearLoading"
|
||||||
|
:disabled="kdocsActionBusy && !kdocsClearLoading"
|
||||||
|
@click="onClearKdocsLogin"
|
||||||
|
>
|
||||||
|
清除登录
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-divider content-position="left">最近一次更新结果</el-divider>
|
<div class="help">
|
||||||
<el-descriptions v-if="updateResult" border :column="1" size="small" style="margin-bottom: 10px">
|
登录状态:
|
||||||
<el-descriptions-item label="job_id">{{ updateResult.job_id }}</el-descriptions-item>
|
<span v-if="kdocsStatus.last_login_ok === true">已登录</span>
|
||||||
<el-descriptions-item label="状态">
|
<span v-else-if="kdocsStatus.login_required">需要扫码</span>
|
||||||
<el-tag v-if="updateResult.status === 'running'" type="warning">运行中</el-tag>
|
<span v-else>未知</span>
|
||||||
<el-tag v-else-if="updateResult.status === 'success'" type="success">成功</el-tag>
|
· 待上传 {{ kdocsStatus.queue_size || 0 }}
|
||||||
<el-tag v-else type="danger">失败</el-tag>
|
<span v-if="kdocsStatus.last_error">· 最近错误:{{ kdocsStatus.last_error }}</span>
|
||||||
</el-descriptions-item>
|
</div>
|
||||||
<el-descriptions-item label="阶段">{{ updateResult.stage || '-' }}</el-descriptions-item>
|
<div v-if="kdocsActionHint" class="help">操作提示:{{ kdocsActionHint }}</div>
|
||||||
<el-descriptions-item label="开始时间">{{ updateResult.started_at || '-' }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="结束时间">{{ updateResult.finished_at || '-' }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="耗时(秒)">{{ updateResult.duration_seconds ?? '-' }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="更新前(commit)">{{ shortCommit(updateResult.from_commit) }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="更新后(commit)">{{ shortCommit(updateResult.to_commit) }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item label="健康检查">
|
|
||||||
<span v-if="updateResult.health_ok === true">通过({{ updateResult.health_message }})</span>
|
|
||||||
<span v-else-if="updateResult.health_ok === false">失败({{ updateResult.health_message }})</span>
|
|
||||||
<span v-else>-</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item v-if="updateResult.error" label="错误">{{ updateResult.error }}</el-descriptions-item>
|
|
||||||
</el-descriptions>
|
|
||||||
<div v-else class="help">暂无更新记录。</div>
|
|
||||||
|
|
||||||
<el-divider content-position="left">更新日志</el-divider>
|
|
||||||
<div class="help" v-if="updateLogTruncated">日志过长,仅展示末尾内容。</div>
|
|
||||||
<el-input v-model="updateLog" type="textarea" :rows="10" readonly placeholder="暂无日志" />
|
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
|
<el-dialog v-model="kdocsQrOpen" title="扫码登录" width="min(420px, 92vw)">
|
||||||
|
<div class="kdocs-qr">
|
||||||
|
<img v-if="kdocsQrImage" :src="`data:image/png;base64,${kdocsQrImage}`" alt="KDocs QR" />
|
||||||
|
<div class="help">请使用管理员微信扫码登录。</div>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -561,6 +656,22 @@ onBeforeUnmount(stopUpdatePolling)
|
|||||||
font-weight: 800;
|
font-weight: 800;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.kdocs-qr {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kdocs-qr img {
|
||||||
|
width: 260px;
|
||||||
|
max-width: 100%;
|
||||||
|
border: 1px solid var(--app-border);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 8px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
.help {
|
.help {
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|||||||
486
api_browser.py
486
api_browser.py
@@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
API 浏览器 - 用纯 HTTP 请求实现浏览功能
|
API 浏览器 - 用纯 HTTP 请求实现浏览功能
|
||||||
比 Playwright 快 30-60 倍
|
比传统浏览器自动化快 30-60 倍
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -15,14 +15,78 @@ import weakref
|
|||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from urllib.parse import urlsplit
|
from urllib.parse import urlsplit
|
||||||
|
import threading
|
||||||
|
|
||||||
from app_config import get_config
|
from app_config import get_config
|
||||||
|
|
||||||
import time as _time_module
|
import time as _time_module
|
||||||
|
|
||||||
_MODULE_START_TIME = _time_module.time()
|
_MODULE_START_TIME = _time_module.time()
|
||||||
_WARMUP_PERIOD_SECONDS = 60 # 启动后 60 秒内使用更长超时
|
_WARMUP_PERIOD_SECONDS = 60 # 启动后 60 秒内使用更长超时
|
||||||
_WARMUP_TIMEOUT_SECONDS = 15.0 # 预热期间的超时时间
|
_WARMUP_TIMEOUT_SECONDS = 15.0 # 预热期间的超时时间
|
||||||
|
|
||||||
|
|
||||||
|
# HTML解析缓存类
|
||||||
|
class HTMLParseCache:
|
||||||
|
"""HTML解析结果缓存"""
|
||||||
|
|
||||||
|
def __init__(self, ttl: int = 300, maxsize: int = 1000):
|
||||||
|
self.cache = {}
|
||||||
|
self.ttl = ttl
|
||||||
|
self.maxsize = maxsize
|
||||||
|
self._access_times = {}
|
||||||
|
self._lock = threading.RLock()
|
||||||
|
|
||||||
|
def _make_key(self, url: str, content_hash: str) -> str:
|
||||||
|
return f"{url}:{content_hash}"
|
||||||
|
|
||||||
|
def get(self, key: str) -> Optional[tuple]:
|
||||||
|
"""获取缓存,如果存在且未过期"""
|
||||||
|
with self._lock:
|
||||||
|
if key in self.cache:
|
||||||
|
value, timestamp = self.cache[key]
|
||||||
|
if time.time() - timestamp < self.ttl:
|
||||||
|
self._access_times[key] = time.time()
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
# 过期删除
|
||||||
|
del self.cache[key]
|
||||||
|
del self._access_times[key]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def set(self, key: str, value: tuple):
|
||||||
|
"""设置缓存"""
|
||||||
|
with self._lock:
|
||||||
|
# 如果缓存已满,删除最久未访问的项
|
||||||
|
if len(self.cache) >= self.maxsize:
|
||||||
|
if self._access_times:
|
||||||
|
# 使用简单的LRU策略,删除最久未访问的项
|
||||||
|
oldest_key = None
|
||||||
|
oldest_time = float("inf")
|
||||||
|
for key, access_time in self._access_times.items():
|
||||||
|
if access_time < oldest_time:
|
||||||
|
oldest_time = access_time
|
||||||
|
oldest_key = key
|
||||||
|
if oldest_key:
|
||||||
|
del self.cache[oldest_key]
|
||||||
|
del self._access_times[oldest_key]
|
||||||
|
|
||||||
|
self.cache[key] = (value, time.time())
|
||||||
|
self._access_times[key] = time.time()
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
"""清空缓存"""
|
||||||
|
with self._lock:
|
||||||
|
self.cache.clear()
|
||||||
|
self._access_times.clear()
|
||||||
|
|
||||||
|
def get_lru_key(self) -> Optional[str]:
|
||||||
|
"""获取最久未访问的键"""
|
||||||
|
if not self._access_times:
|
||||||
|
return None
|
||||||
|
return min(self._access_times.keys(), key=lambda k: self._access_times[k])
|
||||||
|
|
||||||
|
|
||||||
config = get_config()
|
config = get_config()
|
||||||
|
|
||||||
BASE_URL = getattr(config, "ZSGL_BASE_URL", "https://postoa.aidunsoft.com")
|
BASE_URL = getattr(config, "ZSGL_BASE_URL", "https://postoa.aidunsoft.com")
|
||||||
@@ -31,7 +95,9 @@ INDEX_URL_PATTERN = getattr(config, "ZSGL_INDEX_URL_PATTERN", "index.aspx")
|
|||||||
COOKIES_DIR = getattr(config, "COOKIES_DIR", "data/cookies")
|
COOKIES_DIR = getattr(config, "COOKIES_DIR", "data/cookies")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_API_REQUEST_TIMEOUT_SECONDS = float(os.environ.get("API_REQUEST_TIMEOUT_SECONDS") or os.environ.get("API_REQUEST_TIMEOUT") or "5")
|
_API_REQUEST_TIMEOUT_SECONDS = float(
|
||||||
|
os.environ.get("API_REQUEST_TIMEOUT_SECONDS") or os.environ.get("API_REQUEST_TIMEOUT") or "5"
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
_API_REQUEST_TIMEOUT_SECONDS = 5.0
|
_API_REQUEST_TIMEOUT_SECONDS = 5.0
|
||||||
_API_REQUEST_TIMEOUT_SECONDS = max(3.0, _API_REQUEST_TIMEOUT_SECONDS)
|
_API_REQUEST_TIMEOUT_SECONDS = max(3.0, _API_REQUEST_TIMEOUT_SECONDS)
|
||||||
@@ -44,6 +110,28 @@ except Exception:
|
|||||||
_API_DIAGNOSTIC_SLOW_MS = max(0, _API_DIAGNOSTIC_SLOW_MS)
|
_API_DIAGNOSTIC_SLOW_MS = max(0, _API_DIAGNOSTIC_SLOW_MS)
|
||||||
|
|
||||||
_cookie_domain_fallback = urlsplit(BASE_URL).hostname or "postoa.aidunsoft.com"
|
_cookie_domain_fallback = urlsplit(BASE_URL).hostname or "postoa.aidunsoft.com"
|
||||||
|
_COOKIE_JAR_MAX_AGE_SECONDS = 24 * 60 * 60
|
||||||
|
|
||||||
|
|
||||||
|
def get_cookie_jar_path(username: str) -> str:
|
||||||
|
"""获取截图用的 cookies 文件路径(Netscape Cookie 格式)"""
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
os.makedirs(COOKIES_DIR, exist_ok=True)
|
||||||
|
filename = hashlib.sha256(username.encode()).hexdigest()[:32] + ".cookies.txt"
|
||||||
|
return os.path.join(COOKIES_DIR, filename)
|
||||||
|
|
||||||
|
|
||||||
|
def is_cookie_jar_fresh(cookie_path: str, max_age_seconds: int = _COOKIE_JAR_MAX_AGE_SECONDS) -> bool:
|
||||||
|
"""判断 cookies 文件是否存在且未过期"""
|
||||||
|
if not cookie_path or not os.path.exists(cookie_path):
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
file_age = time.time() - os.path.getmtime(cookie_path)
|
||||||
|
return file_age <= max(0, int(max_age_seconds or 0))
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
_api_browser_instances: "weakref.WeakSet[APIBrowser]" = weakref.WeakSet()
|
_api_browser_instances: "weakref.WeakSet[APIBrowser]" = weakref.WeakSet()
|
||||||
|
|
||||||
@@ -63,6 +151,7 @@ atexit.register(_cleanup_api_browser_instances)
|
|||||||
@dataclass
|
@dataclass
|
||||||
class APIBrowseResult:
|
class APIBrowseResult:
|
||||||
"""API 浏览结果"""
|
"""API 浏览结果"""
|
||||||
|
|
||||||
success: bool
|
success: bool
|
||||||
total_items: int = 0
|
total_items: int = 0
|
||||||
total_attachments: int = 0
|
total_attachments: int = 0
|
||||||
@@ -74,90 +163,126 @@ class APIBrowser:
|
|||||||
|
|
||||||
def __init__(self, log_callback: Optional[Callable] = None, proxy_config: Optional[dict] = None):
|
def __init__(self, log_callback: Optional[Callable] = None, proxy_config: Optional[dict] = None):
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.headers.update({
|
self.session.headers.update(
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
{
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
||||||
})
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
||||||
|
}
|
||||||
|
)
|
||||||
self.logged_in = False
|
self.logged_in = False
|
||||||
self.log_callback = log_callback
|
self.log_callback = log_callback
|
||||||
self.stop_flag = False
|
self.stop_flag = False
|
||||||
self._closed = False # 防止重复关闭
|
self._closed = False # 防止重复关闭
|
||||||
self.last_total_records = 0
|
self.last_total_records = 0
|
||||||
|
|
||||||
|
# 初始化HTML解析缓存
|
||||||
|
self._parse_cache = HTMLParseCache(ttl=300, maxsize=500) # 5分钟缓存,最多500条记录
|
||||||
|
|
||||||
# 设置代理
|
# 设置代理
|
||||||
if proxy_config and proxy_config.get("server"):
|
if proxy_config and proxy_config.get("server"):
|
||||||
proxy_server = proxy_config["server"]
|
proxy_server = proxy_config["server"]
|
||||||
self.session.proxies = {
|
self.session.proxies = {"http": proxy_server, "https": proxy_server}
|
||||||
"http": proxy_server,
|
|
||||||
"https": proxy_server
|
|
||||||
}
|
|
||||||
self.proxy_server = proxy_server
|
self.proxy_server = proxy_server
|
||||||
else:
|
else:
|
||||||
self.proxy_server = None
|
self.proxy_server = None
|
||||||
|
|
||||||
_api_browser_instances.add(self)
|
_api_browser_instances.add(self)
|
||||||
|
|
||||||
|
def _calculate_adaptive_delay(self, iteration: int, consecutive_failures: int) -> float:
|
||||||
|
"""
|
||||||
|
智能延迟计算:文章处理延迟
|
||||||
|
根据迭代次数和连续失败次数动态调整延迟
|
||||||
|
"""
|
||||||
|
# 基础延迟,显著降低
|
||||||
|
base_delay = 0.03
|
||||||
|
|
||||||
|
# 如果有连续失败,增加延迟但有上限
|
||||||
|
if consecutive_failures > 0:
|
||||||
|
delay = base_delay * (1.5 ** min(consecutive_failures, 3))
|
||||||
|
return min(delay, 0.2) # 最多200ms
|
||||||
|
|
||||||
|
# 根据处理进度调整延迟,开始时较慢,后来可以更快
|
||||||
|
progress_factor = min(iteration / 100.0, 1.0) # 100个文章后达到最大优化
|
||||||
|
optimized_delay = base_delay * (1.2 - 0.4 * progress_factor) # 从120%逐渐降低到80%
|
||||||
|
return max(optimized_delay, 0.02) # 最少20ms
|
||||||
|
|
||||||
|
def _calculate_page_delay(self, current_page: int, new_articles_in_page: int) -> float:
|
||||||
|
"""
|
||||||
|
智能延迟计算:页面处理延迟
|
||||||
|
根据页面位置和新文章数量调整延迟
|
||||||
|
"""
|
||||||
|
base_delay = 0.08 # 基础延迟,降低50%
|
||||||
|
|
||||||
|
# 如果当前页有大量新文章,可以稍微增加延迟
|
||||||
|
if new_articles_in_page > 10:
|
||||||
|
return base_delay * 1.2
|
||||||
|
|
||||||
|
# 如果是新页面,降低延迟(内容可能需要加载)
|
||||||
|
if current_page <= 3:
|
||||||
|
return base_delay * 1.1
|
||||||
|
|
||||||
|
# 后续页面可以更快
|
||||||
|
return base_delay * 0.8
|
||||||
|
|
||||||
def log(self, message: str):
|
def log(self, message: str):
|
||||||
"""记录日志"""
|
"""记录日志"""
|
||||||
if self.log_callback:
|
if self.log_callback:
|
||||||
self.log_callback(message)
|
self.log_callback(message)
|
||||||
def save_cookies_for_playwright(self, username: str):
|
|
||||||
"""保存cookies供Playwright使用"""
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
os.makedirs(COOKIES_DIR, exist_ok=True)
|
def save_cookies_for_screenshot(self, username: str):
|
||||||
|
"""保存 cookies 供 wkhtmltoimage 使用(Netscape Cookie 格式)"""
|
||||||
# 安全修复:使用SHA256代替MD5作为文件名哈希
|
cookies_path = get_cookie_jar_path(username)
|
||||||
filename = hashlib.sha256(username.encode()).hexdigest()[:32] + '.json'
|
|
||||||
cookies_path = os.path.join(COOKIES_DIR, filename)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 获取requests session的cookies
|
lines = [
|
||||||
cookies_list = []
|
"# Netscape HTTP Cookie File",
|
||||||
|
"# This file was generated by zsglpt",
|
||||||
|
]
|
||||||
for cookie in self.session.cookies:
|
for cookie in self.session.cookies:
|
||||||
cookies_list.append({
|
domain = cookie.domain or _cookie_domain_fallback
|
||||||
'name': cookie.name,
|
include_subdomains = "TRUE" if domain.startswith(".") else "FALSE"
|
||||||
'value': cookie.value,
|
path = cookie.path or "/"
|
||||||
'domain': cookie.domain or _cookie_domain_fallback,
|
secure = "TRUE" if getattr(cookie, "secure", False) else "FALSE"
|
||||||
'path': cookie.path or '/',
|
expires = int(getattr(cookie, "expires", 0) or 0)
|
||||||
})
|
lines.append(
|
||||||
|
"\t".join(
|
||||||
# Playwright storage_state 格式
|
[
|
||||||
storage_state = {
|
domain,
|
||||||
'cookies': cookies_list,
|
include_subdomains,
|
||||||
'origins': []
|
path,
|
||||||
}
|
secure,
|
||||||
|
str(expires),
|
||||||
with open(cookies_path, 'w', encoding='utf-8') as f:
|
cookie.name,
|
||||||
json.dump(storage_state, f)
|
cookie.value,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(cookies_path, "w", encoding="utf-8") as f:
|
||||||
|
f.write("\n".join(lines) + "\n")
|
||||||
|
|
||||||
self.log(f"[API] Cookies已保存供截图使用")
|
self.log(f"[API] Cookies已保存供截图使用")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(f"[API] 保存cookies失败: {e}")
|
self.log(f"[API] 保存cookies失败: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _request_with_retry(self, method, url, max_retries=3, retry_delay=1, **kwargs):
|
def _request_with_retry(self, method, url, max_retries=3, retry_delay=1, **kwargs):
|
||||||
"""带重试机制的请求方法"""
|
"""带重试机制的请求方法"""
|
||||||
# 启动后 60 秒内使用更长超时(15秒),之后使用配置的超时
|
# 启动后 60 秒内使用更长超时(15秒),之后使用配置的超时
|
||||||
if (_time_module.time() - _MODULE_START_TIME) < _WARMUP_PERIOD_SECONDS:
|
if (_time_module.time() - _MODULE_START_TIME) < _WARMUP_PERIOD_SECONDS:
|
||||||
kwargs.setdefault('timeout', _WARMUP_TIMEOUT_SECONDS)
|
kwargs.setdefault("timeout", _WARMUP_TIMEOUT_SECONDS)
|
||||||
else:
|
else:
|
||||||
kwargs.setdefault('timeout', _API_REQUEST_TIMEOUT_SECONDS)
|
kwargs.setdefault("timeout", _API_REQUEST_TIMEOUT_SECONDS)
|
||||||
last_error = None
|
last_error = None
|
||||||
timeout_value = kwargs.get("timeout")
|
timeout_value = kwargs.get("timeout")
|
||||||
diag_enabled = _API_DIAGNOSTIC_LOG
|
diag_enabled = _API_DIAGNOSTIC_LOG
|
||||||
slow_ms = _API_DIAGNOSTIC_SLOW_MS
|
slow_ms = _API_DIAGNOSTIC_SLOW_MS
|
||||||
|
|
||||||
for attempt in range(1, max_retries + 1):
|
for attempt in range(1, max_retries + 1):
|
||||||
start_ts = _time_module.time()
|
start_ts = _time_module.time()
|
||||||
try:
|
try:
|
||||||
if method.lower() == 'get':
|
if method.lower() == "get":
|
||||||
resp = self.session.get(url, **kwargs)
|
resp = self.session.get(url, **kwargs)
|
||||||
else:
|
else:
|
||||||
resp = self.session.post(url, **kwargs)
|
resp = self.session.post(url, **kwargs)
|
||||||
@@ -178,19 +303,20 @@ class APIBrowser:
|
|||||||
if attempt < max_retries:
|
if attempt < max_retries:
|
||||||
self.log(f"[API] 请求超时,{retry_delay}秒后重试 ({attempt}/{max_retries})...")
|
self.log(f"[API] 请求超时,{retry_delay}秒后重试 ({attempt}/{max_retries})...")
|
||||||
import time
|
import time
|
||||||
|
|
||||||
time.sleep(retry_delay)
|
time.sleep(retry_delay)
|
||||||
else:
|
else:
|
||||||
self.log(f"[API] 请求失败,已重试{max_retries}次: {str(e)}")
|
self.log(f"[API] 请求失败,已重试{max_retries}次: {str(e)}")
|
||||||
|
|
||||||
raise last_error
|
raise last_error
|
||||||
|
|
||||||
def _get_aspnet_fields(self, soup):
|
def _get_aspnet_fields(self, soup):
|
||||||
"""获取 ASP.NET 隐藏字段"""
|
"""获取 ASP.NET 隐藏字段"""
|
||||||
fields = {}
|
fields = {}
|
||||||
for name in ['__VIEWSTATE', '__VIEWSTATEGENERATOR', '__EVENTVALIDATION']:
|
for name in ["__VIEWSTATE", "__VIEWSTATEGENERATOR", "__EVENTVALIDATION"]:
|
||||||
field = soup.find('input', {'name': name})
|
field = soup.find("input", {"name": name})
|
||||||
if field:
|
if field:
|
||||||
fields[name] = field.get('value', '')
|
fields[name] = field.get("value", "")
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
def get_real_name(self) -> Optional[str]:
|
def get_real_name(self) -> Optional[str]:
|
||||||
@@ -204,18 +330,18 @@ class APIBrowser:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
url = f"{BASE_URL}/admin/center.aspx"
|
url = f"{BASE_URL}/admin/center.aspx"
|
||||||
resp = self._request_with_retry('get', url)
|
resp = self._request_with_retry("get", url)
|
||||||
soup = BeautifulSoup(resp.text, 'html.parser')
|
soup = BeautifulSoup(resp.text, "html.parser")
|
||||||
|
|
||||||
# 查找包含"姓名:"的元素
|
# 查找包含"姓名:"的元素
|
||||||
# 页面格式: <li><p>姓名:喻勇祥(19174616018) 人力资源编码: ...</p></li>
|
# 页面格式: <li><p>姓名:喻勇祥(19174616018) 人力资源编码: ...</p></li>
|
||||||
nlist = soup.find('div', {'class': 'nlist-5'})
|
nlist = soup.find("div", {"class": "nlist-5"})
|
||||||
if nlist:
|
if nlist:
|
||||||
first_li = nlist.find('li')
|
first_li = nlist.find("li")
|
||||||
if first_li:
|
if first_li:
|
||||||
text = first_li.get_text()
|
text = first_li.get_text()
|
||||||
# 解析姓名:格式为 "姓名:XXX(手机号)"
|
# 解析姓名:格式为 "姓名:XXX(手机号)"
|
||||||
match = re.search(r'姓名[::]\s*([^\((]+)', text)
|
match = re.search(r"姓名[::]\s*([^\((]+)", text)
|
||||||
if match:
|
if match:
|
||||||
real_name = match.group(1).strip()
|
real_name = match.group(1).strip()
|
||||||
if real_name:
|
if real_name:
|
||||||
@@ -229,26 +355,26 @@ class APIBrowser:
|
|||||||
self.log(f"[API] 登录: {username}")
|
self.log(f"[API] 登录: {username}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = self._request_with_retry('get', LOGIN_URL)
|
resp = self._request_with_retry("get", LOGIN_URL)
|
||||||
|
|
||||||
soup = BeautifulSoup(resp.text, 'html.parser')
|
soup = BeautifulSoup(resp.text, "html.parser")
|
||||||
fields = self._get_aspnet_fields(soup)
|
fields = self._get_aspnet_fields(soup)
|
||||||
|
|
||||||
data = fields.copy()
|
data = fields.copy()
|
||||||
data['txtUserName'] = username
|
data["txtUserName"] = username
|
||||||
data['txtPassword'] = password
|
data["txtPassword"] = password
|
||||||
data['btnSubmit'] = '登 录'
|
data["btnSubmit"] = "登 录"
|
||||||
|
|
||||||
resp = self._request_with_retry(
|
resp = self._request_with_retry(
|
||||||
'post',
|
"post",
|
||||||
LOGIN_URL,
|
LOGIN_URL,
|
||||||
data=data,
|
data=data,
|
||||||
headers={
|
headers={
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
'Origin': BASE_URL,
|
"Origin": BASE_URL,
|
||||||
'Referer': LOGIN_URL,
|
"Referer": LOGIN_URL,
|
||||||
},
|
},
|
||||||
allow_redirects=True
|
allow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if INDEX_URL_PATTERN in resp.url:
|
if INDEX_URL_PATTERN in resp.url:
|
||||||
@@ -256,9 +382,9 @@ class APIBrowser:
|
|||||||
self.log(f"[API] 登录成功")
|
self.log(f"[API] 登录成功")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
soup = BeautifulSoup(resp.text, 'html.parser')
|
soup = BeautifulSoup(resp.text, "html.parser")
|
||||||
error = soup.find(id='lblMsg')
|
error = soup.find(id="lblMsg")
|
||||||
error_msg = error.get_text().strip() if error else '未知错误'
|
error_msg = error.get_text().strip() if error else "未知错误"
|
||||||
self.log(f"[API] 登录失败: {error_msg}")
|
self.log(f"[API] 登录失败: {error_msg}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -272,55 +398,57 @@ class APIBrowser:
|
|||||||
return [], 0, None
|
return [], 0, None
|
||||||
|
|
||||||
if base_url and page > 1:
|
if base_url and page > 1:
|
||||||
url = re.sub(r'page=\d+', f'page={page}', base_url)
|
url = re.sub(r"page=\d+", f"page={page}", base_url)
|
||||||
elif page > 1:
|
elif page > 1:
|
||||||
# 兼容兜底:若没有 next_url(极少数情况下页面不提供“下一页”链接),尝试直接拼 page 参数
|
# 兼容兜底:若没有 next_url(极少数情况下页面不提供“下一页”链接),尝试直接拼 page 参数
|
||||||
url = f"{BASE_URL}/admin/center.aspx?bz={bz}&page={page}"
|
url = f"{BASE_URL}/admin/center.aspx?bz={bz}&page={page}"
|
||||||
else:
|
else:
|
||||||
url = f"{BASE_URL}/admin/center.aspx?bz={bz}"
|
url = f"{BASE_URL}/admin/center.aspx?bz={bz}"
|
||||||
|
|
||||||
resp = self._request_with_retry('get', url)
|
resp = self._request_with_retry("get", url)
|
||||||
soup = BeautifulSoup(resp.text, 'html.parser')
|
soup = BeautifulSoup(resp.text, "html.parser")
|
||||||
articles = []
|
articles = []
|
||||||
|
|
||||||
ltable = soup.find('table', {'class': 'ltable'})
|
ltable = soup.find("table", {"class": "ltable"})
|
||||||
if ltable:
|
if ltable:
|
||||||
rows = ltable.find_all('tr')[1:]
|
rows = ltable.find_all("tr")[1:]
|
||||||
for row in rows:
|
for row in rows:
|
||||||
# 检查是否是"暂无记录"
|
# 检查是否是"暂无记录"
|
||||||
if '暂无记录' in row.get_text():
|
if "暂无记录" in row.get_text():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
link = row.find('a', href=True)
|
link = row.find("a", href=True)
|
||||||
if link:
|
if link:
|
||||||
href = link.get('href', '')
|
href = link.get("href", "")
|
||||||
title = link.get_text().strip()
|
title = link.get_text().strip()
|
||||||
|
|
||||||
match = re.search(r'id=(\d+)', href)
|
match = re.search(r"id=(\d+)", href)
|
||||||
article_id = match.group(1) if match else None
|
article_id = match.group(1) if match else None
|
||||||
|
|
||||||
articles.append({
|
articles.append(
|
||||||
'title': title,
|
{
|
||||||
'href': href,
|
"title": title,
|
||||||
'article_id': article_id,
|
"href": href,
|
||||||
})
|
"article_id": article_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
# 获取总页数
|
# 获取总页数
|
||||||
total_pages = 1
|
total_pages = 1
|
||||||
next_page_url = None
|
next_page_url = None
|
||||||
total_records = 0
|
total_records = 0
|
||||||
|
|
||||||
page_content = soup.find(id='PageContent')
|
page_content = soup.find(id="PageContent")
|
||||||
if page_content:
|
if page_content:
|
||||||
text = page_content.get_text()
|
text = page_content.get_text()
|
||||||
total_match = re.search(r'共(\d+)记录', text)
|
total_match = re.search(r"共(\d+)记录", text)
|
||||||
if total_match:
|
if total_match:
|
||||||
total_records = int(total_match.group(1))
|
total_records = int(total_match.group(1))
|
||||||
total_pages = (total_records + 9) // 10
|
total_pages = (total_records + 9) // 10
|
||||||
|
|
||||||
next_link = page_content.find('a', string=re.compile('下一页'))
|
next_link = page_content.find("a", string=re.compile("下一页"))
|
||||||
if next_link:
|
if next_link:
|
||||||
next_href = next_link.get('href', '')
|
next_href = next_link.get("href", "")
|
||||||
if next_href:
|
if next_href:
|
||||||
next_page_url = f"{BASE_URL}/admin/{next_href}"
|
next_page_url = f"{BASE_URL}/admin/{next_href}"
|
||||||
|
|
||||||
@@ -331,43 +459,83 @@ class APIBrowser:
|
|||||||
return articles, total_pages, next_page_url
|
return articles, total_pages, next_page_url
|
||||||
|
|
||||||
def get_article_attachments(self, article_href: str):
|
def get_article_attachments(self, article_href: str):
|
||||||
"""获取文章的附件列表"""
|
"""获取文章的附件列表和文章信息"""
|
||||||
if not article_href.startswith('http'):
|
if not article_href.startswith("http"):
|
||||||
url = f"{BASE_URL}/admin/{article_href}"
|
url = f"{BASE_URL}/admin/{article_href}"
|
||||||
else:
|
else:
|
||||||
url = article_href
|
url = article_href
|
||||||
|
|
||||||
resp = self._request_with_retry('get', url)
|
# 先检查缓存,避免不必要的请求
|
||||||
soup = BeautifulSoup(resp.text, 'html.parser')
|
# 使用URL作为缓存键(简化版本)
|
||||||
|
cache_key = f"attachments_{hash(url)}"
|
||||||
|
cached_result = self._parse_cache.get(cache_key)
|
||||||
|
if cached_result:
|
||||||
|
return cached_result
|
||||||
|
|
||||||
|
resp = self._request_with_retry("get", url)
|
||||||
|
soup = BeautifulSoup(resp.text, "html.parser")
|
||||||
|
|
||||||
attachments = []
|
attachments = []
|
||||||
|
article_info = {"channel_id": None, "article_id": None}
|
||||||
|
|
||||||
attach_list = soup.find('div', {'class': 'attach-list2'})
|
# 从 saveread 按钮获取 channel_id 和 article_id
|
||||||
|
for elem in soup.find_all(["button", "input"]):
|
||||||
|
onclick = elem.get("onclick", "")
|
||||||
|
match = re.search(r"saveread\((\d+),(\d+)\)", onclick)
|
||||||
|
if match:
|
||||||
|
article_info["channel_id"] = match.group(1)
|
||||||
|
article_info["article_id"] = match.group(2)
|
||||||
|
break
|
||||||
|
|
||||||
|
attach_list = soup.find("div", {"class": "attach-list2"})
|
||||||
if attach_list:
|
if attach_list:
|
||||||
items = attach_list.find_all('li')
|
items = attach_list.find_all("li")
|
||||||
for item in items:
|
for item in items:
|
||||||
download_links = item.find_all('a', onclick=re.compile(r'download\.ashx'))
|
download_links = item.find_all("a", onclick=re.compile(r"download2?\.ashx"))
|
||||||
for link in download_links:
|
for link in download_links:
|
||||||
onclick = link.get('onclick', '')
|
onclick = link.get("onclick", "")
|
||||||
id_match = re.search(r'id=(\d+)', onclick)
|
id_match = re.search(r"id=(\d+)", onclick)
|
||||||
channel_match = re.search(r'channel_id=(\d+)', onclick)
|
channel_match = re.search(r"channel_id=(\d+)", onclick)
|
||||||
if id_match:
|
if id_match:
|
||||||
attach_id = id_match.group(1)
|
attach_id = id_match.group(1)
|
||||||
channel_id = channel_match.group(1) if channel_match else '1'
|
channel_id = channel_match.group(1) if channel_match else "1"
|
||||||
h3 = item.find('h3')
|
h3 = item.find("h3")
|
||||||
filename = h3.get_text().strip() if h3 else f'附件{attach_id}'
|
filename = h3.get_text().strip() if h3 else f"附件{attach_id}"
|
||||||
attachments.append({
|
attachments.append({"id": attach_id, "channel_id": channel_id, "filename": filename})
|
||||||
'id': attach_id,
|
|
||||||
'channel_id': channel_id,
|
|
||||||
'filename': filename
|
|
||||||
})
|
|
||||||
break
|
break
|
||||||
|
|
||||||
return attachments
|
result = (attachments, article_info)
|
||||||
|
# 存入缓存
|
||||||
|
self._parse_cache.set(cache_key, result)
|
||||||
|
return result
|
||||||
|
|
||||||
def mark_read(self, attach_id: str, channel_id: str = '1') -> bool:
|
def mark_article_read(self, channel_id: str, article_id: str) -> bool:
|
||||||
"""通过访问下载链接标记已读"""
|
"""通过 saveread API 标记文章已读"""
|
||||||
download_url = f"{BASE_URL}/tools/download.ashx?site=main&id={attach_id}&channel_id={channel_id}"
|
if not channel_id or not article_id:
|
||||||
|
return False
|
||||||
|
|
||||||
|
import random
|
||||||
|
|
||||||
|
saveread_url = (
|
||||||
|
f"{BASE_URL}/tools/submit_ajax.ashx?action=saveread&time={random.random()}&fl={channel_id}&id={article_id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = self._request_with_retry("post", saveread_url)
|
||||||
|
# 检查响应是否成功
|
||||||
|
if resp.status_code == 200:
|
||||||
|
try:
|
||||||
|
data = resp.json()
|
||||||
|
return data.get("status") == 1
|
||||||
|
except:
|
||||||
|
return True # 如果不是 JSON 但状态码 200,也认为成功
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def mark_read(self, attach_id: str, channel_id: str = "1") -> bool:
|
||||||
|
"""通过访问预览通道标记附件已读"""
|
||||||
|
download_url = f"{BASE_URL}/tools/download2.ashx?site=main&id={attach_id}&channel_id={channel_id}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = self._request_with_retry("get", download_url, stream=True)
|
resp = self._request_with_retry("get", download_url, stream=True)
|
||||||
@@ -400,28 +568,26 @@ class APIBrowser:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
# 根据浏览类型确定 bz 参数
|
# 根据浏览类型确定 bz 参数
|
||||||
# 网页实际参数: 0=注册前未读, 2=应读(历史上曾存在 1=已读,但当前逻辑不再使用)
|
# 网站更新后参数: 0=应读, 1=已读(注册前未读需通过页面交互切换)
|
||||||
# 当前前端选项: 注册前未读、应读(默认应读)
|
# 当前前端选项: 注册前未读、应读(默认应读)
|
||||||
browse_type_text = str(browse_type or "")
|
browse_type_text = str(browse_type or "")
|
||||||
if '注册前' in browse_type_text:
|
if "注册前" in browse_type_text:
|
||||||
bz = 0 # 注册前未读
|
bz = 0 # 注册前未读(暂与应读相同,网站通过页面状态区分)
|
||||||
else:
|
else:
|
||||||
bz = 2 # 应读
|
bz = 0 # 应读
|
||||||
|
|
||||||
self.log(f"[API] 开始浏览 '{browse_type}' (bz={bz})...")
|
self.log(f"[API] 开始浏览 '{browse_type}' (bz={bz})...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
total_items = 0
|
total_items = 0
|
||||||
total_attachments = 0
|
total_attachments = 0
|
||||||
page = 1
|
|
||||||
base_url = None
|
|
||||||
skipped_items = 0
|
skipped_items = 0
|
||||||
consecutive_failures = 0
|
consecutive_failures = 0
|
||||||
max_consecutive_failures = 3
|
max_consecutive_failures = 3
|
||||||
|
|
||||||
# 获取第一页
|
# 获取第一页,了解总记录数
|
||||||
try:
|
try:
|
||||||
articles, total_pages, next_url = self.get_article_list_page(bz, page)
|
articles, total_pages, _ = self.get_article_list_page(bz, 1)
|
||||||
consecutive_failures = 0
|
consecutive_failures = 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result.error_message = str(e)
|
result.error_message = str(e)
|
||||||
@@ -433,14 +599,9 @@ class APIBrowser:
|
|||||||
result.success = True
|
result.success = True
|
||||||
return result
|
return result
|
||||||
|
|
||||||
self.log(f"[API] 共 {total_pages} 页,开始处理...")
|
|
||||||
|
|
||||||
if next_url:
|
|
||||||
base_url = next_url
|
|
||||||
elif total_pages > 1:
|
|
||||||
base_url = f"{BASE_URL}/admin/center.aspx?bz={bz}&page=2"
|
|
||||||
|
|
||||||
total_records = int(getattr(self, "last_total_records", 0) or 0)
|
total_records = int(getattr(self, "last_total_records", 0) or 0)
|
||||||
|
self.log(f"[API] 共 {total_records} 条记录,开始处理...")
|
||||||
|
|
||||||
last_report_ts = 0.0
|
last_report_ts = 0.0
|
||||||
|
|
||||||
def report_progress(force: bool = False):
|
def report_progress(force: bool = False):
|
||||||
@@ -458,31 +619,37 @@ class APIBrowser:
|
|||||||
|
|
||||||
report_progress(force=True)
|
report_progress(force=True)
|
||||||
|
|
||||||
# 处理所有页面
|
# 循环处理:遍历所有页面,跟踪已处理文章防止重复
|
||||||
while page <= total_pages:
|
max_iterations = total_records + 20 # 防止无限循环
|
||||||
|
iteration = 0
|
||||||
|
processed_hrefs = set() # 跟踪已处理的文章,防止重复处理
|
||||||
|
current_page = 1
|
||||||
|
|
||||||
|
while articles and iteration < max_iterations:
|
||||||
|
iteration += 1
|
||||||
|
|
||||||
if should_stop_callback and should_stop_callback():
|
if should_stop_callback and should_stop_callback():
|
||||||
self.log("[API] 收到停止信号")
|
self.log("[API] 收到停止信号")
|
||||||
break
|
break
|
||||||
|
|
||||||
# page==1 已取过,后续页在这里获取
|
new_articles_in_page = 0 # 本次迭代中新处理的文章数
|
||||||
if page > 1:
|
|
||||||
try:
|
|
||||||
articles, _, next_url = self.get_article_list_page(bz, page, base_url)
|
|
||||||
consecutive_failures = 0
|
|
||||||
if next_url:
|
|
||||||
base_url = next_url
|
|
||||||
except Exception as e:
|
|
||||||
self.log(f"[API] 获取第{page}页列表失败,终止本次浏览: {str(e)}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
for article in articles:
|
for article in articles:
|
||||||
if should_stop_callback and should_stop_callback():
|
if should_stop_callback and should_stop_callback():
|
||||||
break
|
break
|
||||||
|
|
||||||
title = article['title'][:30]
|
article_href = article["href"]
|
||||||
# 获取附件(文章详情页)
|
# 跳过已处理的文章
|
||||||
|
if article_href in processed_hrefs:
|
||||||
|
continue
|
||||||
|
|
||||||
|
processed_hrefs.add(article_href)
|
||||||
|
new_articles_in_page += 1
|
||||||
|
title = article["title"][:30]
|
||||||
|
|
||||||
|
# 获取附件和文章信息(文章详情页)
|
||||||
try:
|
try:
|
||||||
attachments = self.get_article_attachments(article['href'])
|
attachments, article_info = self.get_article_attachments(article_href)
|
||||||
consecutive_failures = 0
|
consecutive_failures = 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
skipped_items += 1
|
skipped_items += 1
|
||||||
@@ -497,21 +664,52 @@ class APIBrowser:
|
|||||||
total_items += 1
|
total_items += 1
|
||||||
report_progress()
|
report_progress()
|
||||||
|
|
||||||
|
# 标记文章已读(调用 saveread API)
|
||||||
|
article_marked = False
|
||||||
|
if article_info.get("channel_id") and article_info.get("article_id"):
|
||||||
|
article_marked = self.mark_article_read(article_info["channel_id"], article_info["article_id"])
|
||||||
|
|
||||||
|
# 处理附件(如果有)
|
||||||
if attachments:
|
if attachments:
|
||||||
for attach in attachments:
|
for attach in attachments:
|
||||||
if self.mark_read(attach['id'], attach['channel_id']):
|
if self.mark_read(attach["id"], attach["channel_id"]):
|
||||||
total_attachments += 1
|
total_attachments += 1
|
||||||
|
|
||||||
self.log(f"[API] [{total_items}] {title} - {len(attachments)}个附件")
|
self.log(f"[API] [{total_items}] {title} - {len(attachments)}个附件")
|
||||||
|
else:
|
||||||
|
# 没有附件的文章,只记录标记状态
|
||||||
|
status = "已标记" if article_marked else "标记失败"
|
||||||
|
self.log(f"[API] [{total_items}] {title} - 无附件({status})")
|
||||||
|
|
||||||
time.sleep(0.1)
|
# 智能延迟策略:根据连续失败次数和文章数量动态调整
|
||||||
|
time.sleep(self._calculate_adaptive_delay(total_items, consecutive_failures))
|
||||||
|
|
||||||
page += 1
|
time.sleep(self._calculate_page_delay(current_page, new_articles_in_page))
|
||||||
time.sleep(0.2)
|
|
||||||
|
# 决定下一步获取哪一页
|
||||||
|
if new_articles_in_page > 0:
|
||||||
|
# 有新文章被处理,重新获取第1页(因为已读文章会从列表消失,页面会上移)
|
||||||
|
current_page = 1
|
||||||
|
else:
|
||||||
|
# 当前页没有新文章,尝试下一页
|
||||||
|
current_page += 1
|
||||||
|
if current_page > total_pages:
|
||||||
|
self.log(f"[API] 已遍历所有 {total_pages} 页,结束循环")
|
||||||
|
break
|
||||||
|
|
||||||
|
try:
|
||||||
|
articles, new_total_pages, _ = self.get_article_list_page(bz, current_page)
|
||||||
|
if new_total_pages > 0:
|
||||||
|
total_pages = new_total_pages
|
||||||
|
except Exception as e:
|
||||||
|
self.log(f"[API] 获取第{current_page}页列表失败: {str(e)}")
|
||||||
|
break
|
||||||
|
|
||||||
report_progress(force=True)
|
report_progress(force=True)
|
||||||
if skipped_items:
|
if skipped_items:
|
||||||
self.log(f"[API] 浏览完成: {total_items} 条内容,{total_attachments} 个附件(跳过 {skipped_items} 条内容)")
|
self.log(
|
||||||
|
f"[API] 浏览完成: {total_items} 条内容,{total_attachments} 个附件(跳过 {skipped_items} 条内容)"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.log(f"[API] 浏览完成: {total_items} 条内容,{total_attachments} 个附件")
|
self.log(f"[API] 浏览完成: {total_items} 条内容,{total_attachments} 个附件")
|
||||||
|
|
||||||
@@ -568,7 +766,7 @@ def warmup_api_connection(proxy_config: Optional[dict] = None, log_callback: Opt
|
|||||||
|
|
||||||
# 发送一个轻量级请求建立连接
|
# 发送一个轻量级请求建立连接
|
||||||
resp = session.get(f"{BASE_URL}/admin/login.aspx", timeout=10, allow_redirects=False)
|
resp = session.get(f"{BASE_URL}/admin/login.aspx", timeout=10, allow_redirects=False)
|
||||||
log(f"✓ API 连接预热完成 (status={resp.status_code})")
|
log(f"[OK] API 连接预热完成 (status={resp.status_code})")
|
||||||
session.close()
|
session.close()
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -44,9 +44,12 @@ publicApi.interceptors.response.use(
|
|||||||
const message = payload?.error || payload?.message || error?.message || '请求失败'
|
const message = payload?.error || payload?.message || error?.message || '请求失败'
|
||||||
|
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
toastErrorOnce('401', message || '登录已过期,请重新登录', 3000)
|
|
||||||
const pathname = window.location?.pathname || ''
|
const pathname = window.location?.pathname || ''
|
||||||
if (!pathname.startsWith('/login')) window.location.href = '/login'
|
// 登录页面不弹通知,让 LoginPage.vue 自己处理错误显示
|
||||||
|
if (!pathname.startsWith('/login')) {
|
||||||
|
toastErrorOnce('401', message || '登录已过期,请重新登录', 3000)
|
||||||
|
window.location.href = '/login'
|
||||||
|
}
|
||||||
} else if (status === 403) {
|
} else if (status === 403) {
|
||||||
toastErrorOnce('403', message || '无权限', 5000)
|
toastErrorOnce('403', message || '无权限', 5000)
|
||||||
} else if (error?.code === 'ECONNABORTED') {
|
} else if (error?.code === 'ECONNABORTED') {
|
||||||
|
|||||||
@@ -30,3 +30,17 @@ export async function changePassword(payload) {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchKdocsSettings() {
|
||||||
|
const { data } = await publicApi.get('/user/kdocs')
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateKdocsSettings(payload) {
|
||||||
|
const { data } = await publicApi.post('/user/kdocs', payload)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchKdocsStatus() {
|
||||||
|
const { data } = await publicApi.get('/kdocs/status')
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ import {
|
|||||||
changePassword,
|
changePassword,
|
||||||
fetchEmailNotify,
|
fetchEmailNotify,
|
||||||
fetchUserEmail,
|
fetchUserEmail,
|
||||||
|
fetchKdocsSettings,
|
||||||
unbindEmail,
|
unbindEmail,
|
||||||
|
updateKdocsSettings,
|
||||||
updateEmailNotify,
|
updateEmailNotify,
|
||||||
} from '../api/settings'
|
} from '../api/settings'
|
||||||
import { useUserStore } from '../stores/user'
|
import { useUserStore } from '../stores/user'
|
||||||
|
import { validateStrongPassword } from '../utils/password'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -28,6 +31,56 @@ const announcementOpen = ref(false)
|
|||||||
const announcement = ref(null)
|
const announcement = ref(null)
|
||||||
const announcementLoading = ref(false)
|
const announcementLoading = ref(false)
|
||||||
|
|
||||||
|
const announcementPageToken = (() => {
|
||||||
|
try {
|
||||||
|
const timeOrigin = window.performance?.timeOrigin
|
||||||
|
if (typeof timeOrigin === 'number' && Number.isFinite(timeOrigin)) return String(timeOrigin)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
return String(Date.now())
|
||||||
|
})()
|
||||||
|
|
||||||
|
function announcementOnceKey(announcementId) {
|
||||||
|
return `announcement_closed_once_${announcementId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function announcementPermanentKey(announcementId) {
|
||||||
|
return `announcement_closed_${announcementId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function wasAnnouncementClosedOnce(announcementId) {
|
||||||
|
try {
|
||||||
|
return window.sessionStorage.getItem(announcementOnceKey(announcementId)) === announcementPageToken
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function wasAnnouncementClosedPermanently(announcementId) {
|
||||||
|
try {
|
||||||
|
return window.localStorage.getItem(announcementPermanentKey(announcementId)) === '1'
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function markAnnouncementClosedOnce(announcementId) {
|
||||||
|
try {
|
||||||
|
window.sessionStorage.setItem(announcementOnceKey(announcementId), announcementPageToken)
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function markAnnouncementClosedPermanently(announcementId) {
|
||||||
|
try {
|
||||||
|
window.localStorage.setItem(announcementPermanentKey(announcementId), '1')
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const feedbackOpen = ref(false)
|
const feedbackOpen = ref(false)
|
||||||
const feedbackTab = ref('new')
|
const feedbackTab = ref('new')
|
||||||
const feedbackSubmitting = ref(false)
|
const feedbackSubmitting = ref(false)
|
||||||
@@ -60,6 +113,10 @@ const passwordForm = reactive({
|
|||||||
confirm_password: '',
|
confirm_password: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const kdocsLoading = ref(false)
|
||||||
|
const kdocsSaving = ref(false)
|
||||||
|
const kdocsUnitValue = ref('')
|
||||||
|
|
||||||
function syncIsMobile() {
|
function syncIsMobile() {
|
||||||
isMobile.value = Boolean(mediaQuery?.matches)
|
isMobile.value = Boolean(mediaQuery?.matches)
|
||||||
if (!isMobile.value) drawerOpen.value = false
|
if (!isMobile.value) drawerOpen.value = false
|
||||||
@@ -180,7 +237,7 @@ async function openSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadSettings() {
|
async function loadSettings() {
|
||||||
await Promise.all([loadEmailInfo(), loadEmailNotify()])
|
await Promise.all([loadEmailInfo(), loadEmailNotify(), loadKdocsSettings()])
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadEmailInfo() {
|
async function loadEmailInfo() {
|
||||||
@@ -211,6 +268,30 @@ async function loadEmailNotify() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadKdocsSettings() {
|
||||||
|
kdocsLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = await fetchKdocsSettings()
|
||||||
|
kdocsUnitValue.value = data?.kdocs_unit || ''
|
||||||
|
} catch {
|
||||||
|
kdocsUnitValue.value = ''
|
||||||
|
} finally {
|
||||||
|
kdocsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveKdocsSettings() {
|
||||||
|
kdocsSaving.value = true
|
||||||
|
try {
|
||||||
|
await updateKdocsSettings({ kdocs_unit: kdocsUnitValue.value.trim() })
|
||||||
|
ElMessage.success('已更新表格县区设置')
|
||||||
|
} catch {
|
||||||
|
// handled by interceptor
|
||||||
|
} finally {
|
||||||
|
kdocsSaving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function onBindEmail() {
|
async function onBindEmail() {
|
||||||
const email = bindEmailValue.value.trim().toLowerCase()
|
const email = bindEmailValue.value.trim().toLowerCase()
|
||||||
if (!email) {
|
if (!email) {
|
||||||
@@ -292,8 +373,9 @@ async function onChangePassword() {
|
|||||||
ElMessage.error('请填写完整信息')
|
ElMessage.error('请填写完整信息')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (String(newPassword).length < 6) {
|
const passwordCheck = validateStrongPassword(newPassword)
|
||||||
ElMessage.error('新密码至少6位')
|
if (!passwordCheck.ok) {
|
||||||
|
ElMessage.error(passwordCheck.message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (newPassword !== confirmPassword) {
|
if (newPassword !== confirmPassword) {
|
||||||
@@ -327,8 +409,8 @@ async function loadAnnouncement() {
|
|||||||
const ann = data?.announcement
|
const ann = data?.announcement
|
||||||
if (!ann?.id) return
|
if (!ann?.id) return
|
||||||
|
|
||||||
const sessionKey = `announcement_closed_${ann.id}`
|
if (wasAnnouncementClosedPermanently(ann.id)) return
|
||||||
if (window.sessionStorage.getItem(sessionKey) === '1') return
|
if (wasAnnouncementClosedOnce(ann.id)) return
|
||||||
|
|
||||||
announcement.value = ann
|
announcement.value = ann
|
||||||
announcementOpen.value = true
|
announcementOpen.value = true
|
||||||
@@ -341,7 +423,7 @@ async function loadAnnouncement() {
|
|||||||
|
|
||||||
function closeAnnouncementOnce() {
|
function closeAnnouncementOnce() {
|
||||||
const ann = announcement.value
|
const ann = announcement.value
|
||||||
if (ann?.id) window.sessionStorage.setItem(`announcement_closed_${ann.id}`, '1')
|
if (ann?.id) markAnnouncementClosedOnce(ann.id)
|
||||||
announcementOpen.value = false
|
announcementOpen.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,6 +433,7 @@ async function dismissAnnouncementPermanently() {
|
|||||||
announcementOpen.value = false
|
announcementOpen.value = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
markAnnouncementClosedPermanently(ann.id)
|
||||||
try {
|
try {
|
||||||
const res = await dismissAnnouncement(ann.id)
|
const res = await dismissAnnouncement(ann.id)
|
||||||
if (res?.success) ElMessage.success('已永久关闭')
|
if (res?.success) ElMessage.success('已永久关闭')
|
||||||
@@ -433,6 +516,9 @@ async function dismissAnnouncementPermanently() {
|
|||||||
<el-dialog v-model="announcementOpen" width="min(560px, 92vw)" :title="announcement?.title || '系统公告'">
|
<el-dialog v-model="announcementOpen" width="min(560px, 92vw)" :title="announcement?.title || '系统公告'">
|
||||||
<div class="announcement-body" v-loading="announcementLoading">
|
<div class="announcement-body" v-loading="announcementLoading">
|
||||||
<div class="announcement-content">{{ announcement?.content || '' }}</div>
|
<div class="announcement-content">{{ announcement?.content || '' }}</div>
|
||||||
|
<div v-if="announcement?.image_url" class="announcement-image">
|
||||||
|
<img :src="announcement.image_url" alt="公告图片" loading="lazy" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<el-button @click="closeAnnouncementOnce">当次关闭</el-button>
|
<el-button @click="closeAnnouncementOnce">当次关闭</el-button>
|
||||||
@@ -562,7 +648,7 @@ async function dismissAnnouncementPermanently() {
|
|||||||
<el-form-item label="当前密码">
|
<el-form-item label="当前密码">
|
||||||
<el-input v-model="passwordForm.current_password" type="password" show-password autocomplete="current-password" />
|
<el-input v-model="passwordForm.current_password" type="password" show-password autocomplete="current-password" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="新密码(至少6位)">
|
<el-form-item label="新密码(至少8位且包含字母和数字)">
|
||||||
<el-input v-model="passwordForm.new_password" type="password" show-password autocomplete="new-password" />
|
<el-input v-model="passwordForm.new_password" type="password" show-password autocomplete="new-password" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="确认新密码">
|
<el-form-item label="确认新密码">
|
||||||
@@ -579,6 +665,24 @@ async function dismissAnnouncementPermanently() {
|
|||||||
</div>
|
</div>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
|
<el-tab-pane label="表格上传" name="kdocs">
|
||||||
|
<div v-loading="kdocsLoading" class="settings-section">
|
||||||
|
<el-form label-position="top">
|
||||||
|
<el-form-item label="县区(可选)">
|
||||||
|
<el-input v-model="kdocsUnitValue" placeholder="留空使用系统默认县区" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-button type="primary" :loading="kdocsSaving" @click="saveKdocsSettings">保存</el-button>
|
||||||
|
</el-form>
|
||||||
|
<el-alert
|
||||||
|
type="info"
|
||||||
|
:closable="false"
|
||||||
|
title="自动上传开关在“账号管理”页面设置(测试功能)。"
|
||||||
|
show-icon
|
||||||
|
class="settings-hint"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</el-tab-pane>
|
||||||
|
|
||||||
<el-tab-pane label="VIP信息" name="vip">
|
<el-tab-pane label="VIP信息" name="vip">
|
||||||
<div class="settings-section">
|
<div class="settings-section">
|
||||||
<el-alert
|
<el-alert
|
||||||
@@ -726,6 +830,20 @@ async function dismissAnnouncementPermanently() {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.announcement-image {
|
||||||
|
margin-top: 12px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.announcement-image img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 320px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid var(--app-border);
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
|
||||||
.feedback-title {
|
.feedback-title {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
updateAccount,
|
updateAccount,
|
||||||
updateAccountRemark,
|
updateAccountRemark,
|
||||||
} from '../api/accounts'
|
} from '../api/accounts'
|
||||||
|
import { fetchKdocsSettings, fetchKdocsStatus, updateKdocsSettings } from '../api/settings'
|
||||||
import { fetchRunStats } from '../api/stats'
|
import { fetchRunStats } from '../api/stats'
|
||||||
import { useSocket } from '../composables/useSocket'
|
import { useSocket } from '../composables/useSocket'
|
||||||
import { useUserStore } from '../stores/user'
|
import { useUserStore } from '../stores/user'
|
||||||
@@ -57,6 +58,17 @@ watch(batchEnableScreenshot, (value) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const kdocsAutoUpload = ref(false)
|
||||||
|
const kdocsSettingsLoading = ref(false)
|
||||||
|
|
||||||
|
// KDocs 在线状态
|
||||||
|
const kdocsStatus = reactive({
|
||||||
|
enabled: false,
|
||||||
|
online: false,
|
||||||
|
message: '',
|
||||||
|
})
|
||||||
|
const kdocsStatusLoading = ref(false)
|
||||||
|
|
||||||
const addOpen = ref(false)
|
const addOpen = ref(false)
|
||||||
const editOpen = ref(false)
|
const editOpen = ref(false)
|
||||||
const upgradeOpen = ref(false)
|
const upgradeOpen = ref(false)
|
||||||
@@ -135,10 +147,12 @@ function toPercent(acc) {
|
|||||||
|
|
||||||
function statusTagType(status = '') {
|
function statusTagType(status = '') {
|
||||||
const text = String(status)
|
const text = String(status)
|
||||||
if (text.includes('已完成') || text.includes('完成')) return 'success'
|
if (text.includes('已完成') || text.includes('完成')) return 'success' // 绿色
|
||||||
if (text.includes('失败') || text.includes('错误') || text.includes('异常') || text.includes('登录失败')) return 'danger'
|
if (text.includes('失败') || text.includes('错误') || text.includes('异常') || text.includes('登录失败')) return 'danger' // 红色
|
||||||
if (text.includes('排队') || text.includes('运行') || text.includes('截图')) return 'warning'
|
if (text.includes('上传截图')) return 'danger' // 上传中:红色
|
||||||
return 'info'
|
if (text.includes('等待上传')) return 'warning' // 等待上传:黄色
|
||||||
|
if (text.includes('排队') || text.includes('运行') || text.includes('截图')) return 'warning' // 黄色
|
||||||
|
return 'info' // 灰色
|
||||||
}
|
}
|
||||||
|
|
||||||
function showRuntimeProgress(acc) {
|
function showRuntimeProgress(acc) {
|
||||||
@@ -189,6 +203,46 @@ async function refreshAccounts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadKdocsSettings() {
|
||||||
|
kdocsSettingsLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = await fetchKdocsSettings()
|
||||||
|
kdocsAutoUpload.value = Number(data?.kdocs_auto_upload || 0) === 1
|
||||||
|
} catch {
|
||||||
|
kdocsAutoUpload.value = false
|
||||||
|
} finally {
|
||||||
|
kdocsSettingsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadKdocsStatus() {
|
||||||
|
kdocsStatusLoading.value = true
|
||||||
|
try {
|
||||||
|
const data = await fetchKdocsStatus()
|
||||||
|
kdocsStatus.enabled = Boolean(data?.enabled)
|
||||||
|
kdocsStatus.online = Boolean(data?.online)
|
||||||
|
kdocsStatus.message = data?.message || ''
|
||||||
|
} catch {
|
||||||
|
kdocsStatus.enabled = false
|
||||||
|
kdocsStatus.online = false
|
||||||
|
kdocsStatus.message = ''
|
||||||
|
} finally {
|
||||||
|
kdocsStatusLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onToggleKdocsAutoUpload(value) {
|
||||||
|
kdocsSettingsLoading.value = true
|
||||||
|
try {
|
||||||
|
await updateKdocsSettings({ kdocs_auto_upload: value ? 1 : 0 })
|
||||||
|
ElMessage.success(value ? '已开启自动上传(测试)' : '已关闭自动上传')
|
||||||
|
} catch (e) {
|
||||||
|
kdocsAutoUpload.value = !value
|
||||||
|
} finally {
|
||||||
|
kdocsSettingsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function onStart(acc) {
|
async function onStart(acc) {
|
||||||
try {
|
try {
|
||||||
await startAccount(acc.id, { browse_type: browseTypeById[acc.id] || '应读', enable_screenshot: batchEnableScreenshot.value })
|
await startAccount(acc.id, { browse_type: browseTypeById[acc.id] || '应读', enable_screenshot: batchEnableScreenshot.value })
|
||||||
@@ -514,6 +568,8 @@ watch(shouldPollStats, (running, prevRunning) => {
|
|||||||
syncStatsPolling(prevRunning)
|
syncStatsPolling(prevRunning)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let kdocsStatusTimer = null
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!userStore.vipInfo) {
|
if (!userStore.vipInfo) {
|
||||||
userStore.refreshVipInfo().catch(() => {
|
userStore.refreshVipInfo().catch(() => {
|
||||||
@@ -524,13 +580,19 @@ onMounted(async () => {
|
|||||||
unbindSocket = bindSocket()
|
unbindSocket = bindSocket()
|
||||||
|
|
||||||
await refreshAccounts()
|
await refreshAccounts()
|
||||||
|
await loadKdocsSettings()
|
||||||
|
await loadKdocsStatus()
|
||||||
await refreshStats()
|
await refreshStats()
|
||||||
syncStatsPolling()
|
syncStatsPolling()
|
||||||
|
|
||||||
|
// 每60秒刷新 KDocs 状态
|
||||||
|
kdocsStatusTimer = window.setInterval(() => loadKdocsStatus(), 60_000)
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
if (unbindSocket) unbindSocket()
|
if (unbindSocket) unbindSocket()
|
||||||
stopStatsPolling()
|
stopStatsPolling()
|
||||||
|
if (kdocsStatusTimer) window.clearInterval(kdocsStatusTimer)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -612,6 +674,18 @@ onBeforeUnmount(() => {
|
|||||||
<el-option v-for="opt in browseTypeOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
|
<el-option v-for="opt in browseTypeOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-switch v-model="batchEnableScreenshot" inline-prompt active-text="截图" inactive-text="不截图" />
|
<el-switch v-model="batchEnableScreenshot" inline-prompt active-text="截图" inactive-text="不截图" />
|
||||||
|
<el-switch
|
||||||
|
v-model="kdocsAutoUpload"
|
||||||
|
:disabled="kdocsSettingsLoading"
|
||||||
|
inline-prompt
|
||||||
|
active-text="上传"
|
||||||
|
inactive-text="不传"
|
||||||
|
@change="onToggleKdocsAutoUpload"
|
||||||
|
/>
|
||||||
|
<span class="app-muted">表格(测试)</span>
|
||||||
|
<el-tag v-if="kdocsStatus.enabled" :type="kdocsStatus.online ? 'success' : 'warning'" size="small" effect="plain">
|
||||||
|
{{ kdocsStatus.online ? '✅ 就绪' : '⚠️ 离线' }}
|
||||||
|
</el-tag>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="toolbar-right">
|
<div class="toolbar-right">
|
||||||
|
|||||||
@@ -105,8 +105,14 @@ async function onSubmit() {
|
|||||||
need_captcha: needCaptcha.value,
|
need_captcha: needCaptcha.value,
|
||||||
})
|
})
|
||||||
ElMessage.success('登录成功,正在跳转...')
|
ElMessage.success('登录成功,正在跳转...')
|
||||||
|
const urlParams = new URLSearchParams(window.location.search || '')
|
||||||
|
const next = String(urlParams.get('next') || '').trim()
|
||||||
|
const safeNext = next && next.startsWith('/') && !next.startsWith('//') && !next.startsWith('/\\') ? next : ''
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = '/app'
|
const target = safeNext || '/app'
|
||||||
|
router.push(target).catch(() => {
|
||||||
|
window.location.href = target
|
||||||
|
})
|
||||||
}, 300)
|
}, 300)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const status = e?.response?.status
|
const status = e?.response?.status
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useRouter } from 'vue-router'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
import { fetchEmailVerifyStatus, generateCaptcha, register } from '../api/auth'
|
import { fetchEmailVerifyStatus, generateCaptcha, register } from '../api/auth'
|
||||||
|
import { validateStrongPassword } from '../utils/password'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -68,8 +69,9 @@ async function onSubmit() {
|
|||||||
ElMessage.error(errorText.value)
|
ElMessage.error(errorText.value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (password.length < 6) {
|
const passwordCheck = validateStrongPassword(password)
|
||||||
errorText.value = '密码至少6个字符'
|
if (!passwordCheck.ok) {
|
||||||
|
errorText.value = passwordCheck.message || '密码格式不正确'
|
||||||
ElMessage.error(errorText.value)
|
ElMessage.error(errorText.value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -166,10 +168,10 @@ onMounted(async () => {
|
|||||||
v-model="form.password"
|
v-model="form.password"
|
||||||
type="password"
|
type="password"
|
||||||
show-password
|
show-password
|
||||||
placeholder="至少6个字符"
|
placeholder="至少8位且包含字母和数字"
|
||||||
autocomplete="new-password"
|
autocomplete="new-password"
|
||||||
/>
|
/>
|
||||||
<div class="hint app-muted">至少6个字符</div>
|
<div class="hint app-muted">至少8位且包含字母和数字</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="确认密码 *">
|
<el-form-item label="确认密码 *">
|
||||||
<el-input
|
<el-input
|
||||||
|
|||||||
37
app.py
37
app.py
@@ -33,9 +33,8 @@ from realtime.socketio_handlers import register_socketio_handlers
|
|||||||
from realtime.status_push import status_push_worker
|
from realtime.status_push import status_push_worker
|
||||||
from routes import register_blueprints
|
from routes import register_blueprints
|
||||||
from security import init_security_middleware
|
from security import init_security_middleware
|
||||||
from services.browser_manager import init_browser_manager
|
|
||||||
from services.checkpoints import init_checkpoint_manager
|
from services.checkpoints import init_checkpoint_manager
|
||||||
from services.maintenance import start_cleanup_scheduler
|
from services.maintenance import start_cleanup_scheduler, start_kdocs_monitor
|
||||||
from services.models import User
|
from services.models import User
|
||||||
from services.runtime import init_runtime
|
from services.runtime import init_runtime
|
||||||
from services.scheduler import scheduled_task_worker
|
from services.scheduler import scheduled_task_worker
|
||||||
@@ -138,6 +137,10 @@ def enforce_csrf_protection():
|
|||||||
return
|
return
|
||||||
if request.path.startswith("/static/"):
|
if request.path.startswith("/static/"):
|
||||||
return
|
return
|
||||||
|
# 登录相关路由豁免 CSRF 检查(登录本身就是建立 session 的过程)
|
||||||
|
csrf_exempt_paths = {"/yuyx/api/login", "/api/login", "/api/auth/login"}
|
||||||
|
if request.path in csrf_exempt_paths:
|
||||||
|
return
|
||||||
if not (current_user.is_authenticated or "admin_id" in session):
|
if not (current_user.is_authenticated or "admin_id" in session):
|
||||||
return
|
return
|
||||||
token = request.headers.get("X-CSRF-Token") or request.form.get("csrf_token")
|
token = request.headers.get("X-CSRF-Token") or request.form.get("csrf_token")
|
||||||
@@ -199,7 +202,7 @@ def cleanup_on_exit():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
logger.info("- 关闭浏览器线程池...")
|
logger.info("- 关闭截图线程池...")
|
||||||
try:
|
try:
|
||||||
shutdown_browser_worker_pool()
|
shutdown_browser_worker_pool()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -217,7 +220,7 @@ def cleanup_on_exit():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
logger.info("✓ 资源清理完成")
|
logger.info("[OK] 资源清理完成")
|
||||||
|
|
||||||
|
|
||||||
# ==================== 启动入口(保持 python app.py 可用) ====================
|
# ==================== 启动入口(保持 python app.py 可用) ====================
|
||||||
@@ -240,7 +243,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
database.init_database()
|
database.init_database()
|
||||||
init_checkpoint_manager()
|
init_checkpoint_manager()
|
||||||
logger.info("✓ 任务断点管理器已初始化")
|
logger.info("[OK] 任务断点管理器已初始化")
|
||||||
|
|
||||||
# 【新增】容器重启时清理遗留的任务状态
|
# 【新增】容器重启时清理遗留的任务状态
|
||||||
logger.info("清理遗留任务状态...")
|
logger.info("清理遗留任务状态...")
|
||||||
@@ -257,41 +260,33 @@ if __name__ == "__main__":
|
|||||||
for account_id in list(safe_get_active_task_ids()):
|
for account_id in list(safe_get_active_task_ids()):
|
||||||
safe_remove_task(account_id)
|
safe_remove_task(account_id)
|
||||||
safe_remove_task_status(account_id)
|
safe_remove_task_status(account_id)
|
||||||
logger.info("✓ 遗留任务状态已清理")
|
logger.info("[OK] 遗留任务状态已清理")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"清理遗留任务状态失败: {e}")
|
logger.warning(f"清理遗留任务状态失败: {e}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
email_service.init_email_service()
|
email_service.init_email_service()
|
||||||
logger.info("✓ 邮件服务已初始化")
|
logger.info("[OK] 邮件服务已初始化")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"警告: 邮件服务初始化失败: {e}")
|
logger.warning(f"警告: 邮件服务初始化失败: {e}")
|
||||||
|
|
||||||
start_cleanup_scheduler()
|
start_cleanup_scheduler()
|
||||||
|
start_kdocs_monitor()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
system_config = database.get_system_config() or {}
|
system_config = database.get_system_config() or {}
|
||||||
max_concurrent_global = int(system_config.get("max_concurrent_global", config.MAX_CONCURRENT_GLOBAL))
|
max_concurrent_global = int(system_config.get("max_concurrent_global", config.MAX_CONCURRENT_GLOBAL))
|
||||||
max_concurrent_per_account = int(system_config.get("max_concurrent_per_account", config.MAX_CONCURRENT_PER_ACCOUNT))
|
max_concurrent_per_account = int(system_config.get("max_concurrent_per_account", config.MAX_CONCURRENT_PER_ACCOUNT))
|
||||||
get_task_scheduler().update_limits(max_global=max_concurrent_global, max_per_user=max_concurrent_per_account)
|
get_task_scheduler().update_limits(max_global=max_concurrent_global, max_per_user=max_concurrent_per_account)
|
||||||
logger.info(f"✓ 已加载并发配置: 全局={max_concurrent_global}, 单账号={max_concurrent_per_account}")
|
logger.info(f"[OK] 已加载并发配置: 全局={max_concurrent_global}, 单账号={max_concurrent_per_account}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"警告: 加载并发配置失败,使用默认值: {e}")
|
logger.warning(f"警告: 加载并发配置失败,使用默认值: {e}")
|
||||||
|
|
||||||
logger.info("正在初始化浏览器管理器...")
|
|
||||||
try:
|
|
||||||
from services.browser_manager import init_browser_manager_async
|
|
||||||
|
|
||||||
logger.info("启动浏览器环境初始化(后台进行,不阻塞服务启动)...")
|
|
||||||
init_browser_manager_async()
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"警告: 启动浏览器初始化失败: {e}")
|
|
||||||
|
|
||||||
logger.info("启动定时任务调度器...")
|
logger.info("启动定时任务调度器...")
|
||||||
threading.Thread(target=scheduled_task_worker, daemon=True, name="scheduled-task-worker").start()
|
threading.Thread(target=scheduled_task_worker, daemon=True, name="scheduled-task-worker").start()
|
||||||
logger.info("✓ 定时任务调度器已启动")
|
logger.info("[OK] 定时任务调度器已启动")
|
||||||
|
|
||||||
logger.info("✓ 状态推送线程已启动(默认2秒/次)")
|
logger.info("[OK] 状态推送线程已启动(默认2秒/次)")
|
||||||
threading.Thread(target=status_push_worker, daemon=True, name="status-push-worker").start()
|
threading.Thread(target=status_push_worker, daemon=True, name="status-push-worker").start()
|
||||||
|
|
||||||
logger.info("服务器启动中...")
|
logger.info("服务器启动中...")
|
||||||
@@ -305,9 +300,9 @@ if __name__ == "__main__":
|
|||||||
except Exception:
|
except Exception:
|
||||||
pool_size = 3
|
pool_size = 3
|
||||||
try:
|
try:
|
||||||
logger.info(f"初始化截图线程池({pool_size}个worker,按需启动浏览器,空闲5分钟后自动关闭)...")
|
logger.info(f"初始化截图线程池({pool_size}个worker,按需启动执行环境,空闲5分钟后自动释放)...")
|
||||||
init_browser_worker_pool(pool_size=pool_size)
|
init_browser_worker_pool(pool_size=pool_size)
|
||||||
logger.info("✓ 截图线程池初始化完成")
|
logger.info("[OK] 截图线程池初始化完成")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"警告: 截图线程池初始化失败: {e}")
|
logger.warning(f"警告: 截图线程池初始化失败: {e}")
|
||||||
|
|
||||||
|
|||||||
199
app_config.py
199
app_config.py
@@ -14,38 +14,43 @@ from urllib.parse import urlsplit, urlunsplit
|
|||||||
# Bug fix: 添加警告日志,避免静默失败
|
# Bug fix: 添加警告日志,避免静默失败
|
||||||
try:
|
try:
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
env_path = Path(__file__).parent / '.env'
|
|
||||||
|
env_path = Path(__file__).parent / ".env"
|
||||||
if env_path.exists():
|
if env_path.exists():
|
||||||
load_dotenv(dotenv_path=env_path)
|
load_dotenv(dotenv_path=env_path)
|
||||||
print(f"✓ 已加载环境变量文件: {env_path}")
|
print(f"[OK] 已加载环境变量文件: {env_path}")
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# python-dotenv未安装,记录警告
|
# python-dotenv未安装,记录警告
|
||||||
import sys
|
import sys
|
||||||
print("⚠ 警告: python-dotenv未安装,将不会加载.env文件。如需使用.env文件,请运行: pip install python-dotenv", file=sys.stderr)
|
|
||||||
|
print(
|
||||||
|
"⚠ 警告: python-dotenv未安装,将不会加载.env文件。如需使用.env文件,请运行: pip install python-dotenv",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# 常量定义
|
# 常量定义
|
||||||
SECRET_KEY_FILE = 'data/secret_key.txt'
|
SECRET_KEY_FILE = "data/secret_key.txt"
|
||||||
|
|
||||||
|
|
||||||
def get_secret_key():
|
def get_secret_key():
|
||||||
"""获取SECRET_KEY(优先环境变量)"""
|
"""获取SECRET_KEY(优先环境变量)"""
|
||||||
# 优先从环境变量读取
|
# 优先从环境变量读取
|
||||||
secret_key = os.environ.get('SECRET_KEY')
|
secret_key = os.environ.get("SECRET_KEY")
|
||||||
if secret_key:
|
if secret_key:
|
||||||
return secret_key
|
return secret_key
|
||||||
|
|
||||||
# 从文件读取
|
# 从文件读取
|
||||||
if os.path.exists(SECRET_KEY_FILE):
|
if os.path.exists(SECRET_KEY_FILE):
|
||||||
with open(SECRET_KEY_FILE, 'r') as f:
|
with open(SECRET_KEY_FILE, "r") as f:
|
||||||
return f.read().strip()
|
return f.read().strip()
|
||||||
|
|
||||||
# 生成新的
|
# 生成新的
|
||||||
new_key = os.urandom(24).hex()
|
new_key = os.urandom(24).hex()
|
||||||
os.makedirs('data', exist_ok=True)
|
os.makedirs("data", exist_ok=True)
|
||||||
with open(SECRET_KEY_FILE, 'w') as f:
|
with open(SECRET_KEY_FILE, "w") as f:
|
||||||
f.write(new_key)
|
f.write(new_key)
|
||||||
print(f"✓ 已生成新的SECRET_KEY并保存到 {SECRET_KEY_FILE}")
|
print(f"[OK] 已生成新的SECRET_KEY并保存到 {SECRET_KEY_FILE}")
|
||||||
return new_key
|
return new_key
|
||||||
|
|
||||||
|
|
||||||
@@ -85,27 +90,30 @@ class Config:
|
|||||||
# ==================== 会话安全配置 ====================
|
# ==================== 会话安全配置 ====================
|
||||||
# 安全修复: 根据环境自动选择安全配置
|
# 安全修复: 根据环境自动选择安全配置
|
||||||
# 生产环境(FLASK_ENV=production)时自动启用更严格的安全设置
|
# 生产环境(FLASK_ENV=production)时自动启用更严格的安全设置
|
||||||
_is_production = os.environ.get('FLASK_ENV', 'production') == 'production'
|
_is_production = os.environ.get("FLASK_ENV", "production") == "production"
|
||||||
_force_secure = os.environ.get('SESSION_COOKIE_SECURE', '').lower() == 'true'
|
_force_secure = os.environ.get("SESSION_COOKIE_SECURE", "").lower() == "true"
|
||||||
SESSION_COOKIE_SECURE = _force_secure or (_is_production and os.environ.get('HTTPS_ENABLED', 'false').lower() == 'true')
|
SESSION_COOKIE_SECURE = _force_secure or (
|
||||||
|
_is_production and os.environ.get("HTTPS_ENABLED", "false").lower() == "true"
|
||||||
|
)
|
||||||
SESSION_COOKIE_HTTPONLY = True # 防止XSS攻击
|
SESSION_COOKIE_HTTPONLY = True # 防止XSS攻击
|
||||||
# SameSite配置:HTTPS环境使用None,HTTP环境使用Lax
|
# SameSite配置:HTTPS环境使用None,HTTP环境使用Lax
|
||||||
SESSION_COOKIE_SAMESITE = 'None' if SESSION_COOKIE_SECURE else 'Lax'
|
SESSION_COOKIE_SAMESITE = "None" if SESSION_COOKIE_SECURE else "Lax"
|
||||||
# 自定义cookie名称,避免与其他应用冲突
|
# 自定义cookie名称,避免与其他应用冲突
|
||||||
SESSION_COOKIE_NAME = os.environ.get('SESSION_COOKIE_NAME', 'zsglpt_session')
|
SESSION_COOKIE_NAME = os.environ.get("SESSION_COOKIE_NAME", "zsglpt_session")
|
||||||
# Cookie路径,确保整个应用都能访问
|
# Cookie路径,确保整个应用都能访问
|
||||||
SESSION_COOKIE_PATH = '/'
|
SESSION_COOKIE_PATH = "/"
|
||||||
PERMANENT_SESSION_LIFETIME = timedelta(hours=int(os.environ.get('SESSION_LIFETIME_HOURS', '24')))
|
PERMANENT_SESSION_LIFETIME = timedelta(hours=int(os.environ.get("SESSION_LIFETIME_HOURS", "24")))
|
||||||
|
|
||||||
# 安全警告检查
|
# 安全警告检查
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_security_warnings(cls):
|
def check_security_warnings(cls):
|
||||||
"""检查安全配置,输出警告"""
|
"""检查安全配置,输出警告"""
|
||||||
import sys
|
import sys
|
||||||
warnings = []
|
|
||||||
env = os.environ.get('FLASK_ENV', 'production')
|
|
||||||
|
|
||||||
if env == 'production':
|
warnings = []
|
||||||
|
env = os.environ.get("FLASK_ENV", "production")
|
||||||
|
|
||||||
|
if env == "production":
|
||||||
if not cls.SESSION_COOKIE_SECURE:
|
if not cls.SESSION_COOKIE_SECURE:
|
||||||
warnings.append("SESSION_COOKIE_SECURE=False: 生产环境建议启用HTTPS并设置SESSION_COOKIE_SECURE=true")
|
warnings.append("SESSION_COOKIE_SECURE=False: 生产环境建议启用HTTPS并设置SESSION_COOKIE_SECURE=true")
|
||||||
|
|
||||||
@@ -116,100 +124,108 @@ class Config:
|
|||||||
print("", file=sys.stderr)
|
print("", file=sys.stderr)
|
||||||
|
|
||||||
# ==================== 数据库配置 ====================
|
# ==================== 数据库配置 ====================
|
||||||
DB_FILE = os.environ.get('DB_FILE', 'data/app_data.db')
|
DB_FILE = os.environ.get("DB_FILE", "data/app_data.db")
|
||||||
DB_POOL_SIZE = int(os.environ.get('DB_POOL_SIZE', '5'))
|
DB_POOL_SIZE = int(os.environ.get("DB_POOL_SIZE", "5"))
|
||||||
|
|
||||||
# ==================== 浏览器配置 ====================
|
# ==================== 浏览器配置 ====================
|
||||||
SCREENSHOTS_DIR = os.environ.get('SCREENSHOTS_DIR', '截图')
|
SCREENSHOTS_DIR = os.environ.get("SCREENSHOTS_DIR", "截图")
|
||||||
COOKIES_DIR = os.environ.get('COOKIES_DIR', 'data/cookies')
|
COOKIES_DIR = os.environ.get("COOKIES_DIR", "data/cookies")
|
||||||
|
KDOCS_LOGIN_STATE_FILE = os.environ.get("KDOCS_LOGIN_STATE_FILE", "data/kdocs_login_state.json")
|
||||||
|
|
||||||
|
# ==================== 公告图片上传配置 ====================
|
||||||
|
ANNOUNCEMENT_IMAGE_DIR = os.environ.get("ANNOUNCEMENT_IMAGE_DIR", "static/announcements")
|
||||||
|
ALLOWED_ANNOUNCEMENT_IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".webp"}
|
||||||
|
MAX_ANNOUNCEMENT_IMAGE_SIZE = int(os.environ.get("MAX_ANNOUNCEMENT_IMAGE_SIZE", "5242880")) # 5MB
|
||||||
|
|
||||||
# ==================== 并发控制配置 ====================
|
# ==================== 并发控制配置 ====================
|
||||||
MAX_CONCURRENT_GLOBAL = int(os.environ.get('MAX_CONCURRENT_GLOBAL', '2'))
|
MAX_CONCURRENT_GLOBAL = int(os.environ.get("MAX_CONCURRENT_GLOBAL", "2"))
|
||||||
MAX_CONCURRENT_PER_ACCOUNT = int(os.environ.get('MAX_CONCURRENT_PER_ACCOUNT', '1'))
|
MAX_CONCURRENT_PER_ACCOUNT = int(os.environ.get("MAX_CONCURRENT_PER_ACCOUNT", "1"))
|
||||||
|
|
||||||
# ==================== 日志缓存配置 ====================
|
# ==================== 日志缓存配置 ====================
|
||||||
MAX_LOGS_PER_USER = int(os.environ.get('MAX_LOGS_PER_USER', '100'))
|
MAX_LOGS_PER_USER = int(os.environ.get("MAX_LOGS_PER_USER", "100"))
|
||||||
MAX_TOTAL_LOGS = int(os.environ.get('MAX_TOTAL_LOGS', '1000'))
|
MAX_TOTAL_LOGS = int(os.environ.get("MAX_TOTAL_LOGS", "1000"))
|
||||||
|
|
||||||
# ==================== 内存/缓存清理配置 ====================
|
# ==================== 内存/缓存清理配置 ====================
|
||||||
USER_ACCOUNTS_EXPIRE_SECONDS = int(os.environ.get('USER_ACCOUNTS_EXPIRE_SECONDS', '3600'))
|
USER_ACCOUNTS_EXPIRE_SECONDS = int(os.environ.get("USER_ACCOUNTS_EXPIRE_SECONDS", "3600"))
|
||||||
BATCH_TASK_EXPIRE_SECONDS = int(os.environ.get('BATCH_TASK_EXPIRE_SECONDS', '21600')) # 默认6小时
|
BATCH_TASK_EXPIRE_SECONDS = int(os.environ.get("BATCH_TASK_EXPIRE_SECONDS", "21600")) # 默认6小时
|
||||||
PENDING_RANDOM_EXPIRE_SECONDS = int(os.environ.get('PENDING_RANDOM_EXPIRE_SECONDS', '7200')) # 默认2小时
|
PENDING_RANDOM_EXPIRE_SECONDS = int(os.environ.get("PENDING_RANDOM_EXPIRE_SECONDS", "7200")) # 默认2小时
|
||||||
|
|
||||||
# ==================== 验证码配置 ====================
|
# ==================== 验证码配置 ====================
|
||||||
MAX_CAPTCHA_ATTEMPTS = int(os.environ.get('MAX_CAPTCHA_ATTEMPTS', '5'))
|
MAX_CAPTCHA_ATTEMPTS = int(os.environ.get("MAX_CAPTCHA_ATTEMPTS", "5"))
|
||||||
CAPTCHA_EXPIRE_SECONDS = int(os.environ.get('CAPTCHA_EXPIRE_SECONDS', '300'))
|
CAPTCHA_EXPIRE_SECONDS = int(os.environ.get("CAPTCHA_EXPIRE_SECONDS", "300"))
|
||||||
|
|
||||||
# ==================== IP限流配置 ====================
|
# ==================== IP限流配置 ====================
|
||||||
MAX_IP_ATTEMPTS_PER_HOUR = int(os.environ.get('MAX_IP_ATTEMPTS_PER_HOUR', '10'))
|
MAX_IP_ATTEMPTS_PER_HOUR = int(os.environ.get("MAX_IP_ATTEMPTS_PER_HOUR", "10"))
|
||||||
IP_LOCK_DURATION = int(os.environ.get('IP_LOCK_DURATION', '3600')) # 秒
|
IP_LOCK_DURATION = int(os.environ.get("IP_LOCK_DURATION", "3600")) # 秒
|
||||||
IP_RATE_LIMIT_LOGIN_MAX = int(os.environ.get('IP_RATE_LIMIT_LOGIN_MAX', '20'))
|
IP_RATE_LIMIT_LOGIN_MAX = int(os.environ.get("IP_RATE_LIMIT_LOGIN_MAX", "20"))
|
||||||
IP_RATE_LIMIT_LOGIN_WINDOW_SECONDS = int(os.environ.get('IP_RATE_LIMIT_LOGIN_WINDOW_SECONDS', '60'))
|
IP_RATE_LIMIT_LOGIN_WINDOW_SECONDS = int(os.environ.get("IP_RATE_LIMIT_LOGIN_WINDOW_SECONDS", "60"))
|
||||||
IP_RATE_LIMIT_REGISTER_MAX = int(os.environ.get('IP_RATE_LIMIT_REGISTER_MAX', '10'))
|
IP_RATE_LIMIT_REGISTER_MAX = int(os.environ.get("IP_RATE_LIMIT_REGISTER_MAX", "10"))
|
||||||
IP_RATE_LIMIT_REGISTER_WINDOW_SECONDS = int(os.environ.get('IP_RATE_LIMIT_REGISTER_WINDOW_SECONDS', '3600'))
|
IP_RATE_LIMIT_REGISTER_WINDOW_SECONDS = int(os.environ.get("IP_RATE_LIMIT_REGISTER_WINDOW_SECONDS", "3600"))
|
||||||
IP_RATE_LIMIT_EMAIL_MAX = int(os.environ.get('IP_RATE_LIMIT_EMAIL_MAX', '20'))
|
IP_RATE_LIMIT_EMAIL_MAX = int(os.environ.get("IP_RATE_LIMIT_EMAIL_MAX", "20"))
|
||||||
IP_RATE_LIMIT_EMAIL_WINDOW_SECONDS = int(os.environ.get('IP_RATE_LIMIT_EMAIL_WINDOW_SECONDS', '3600'))
|
IP_RATE_LIMIT_EMAIL_WINDOW_SECONDS = int(os.environ.get("IP_RATE_LIMIT_EMAIL_WINDOW_SECONDS", "3600"))
|
||||||
|
|
||||||
# ==================== 超时配置 ====================
|
# ==================== 超时配置 ====================
|
||||||
PAGE_LOAD_TIMEOUT = int(os.environ.get('PAGE_LOAD_TIMEOUT', '60000')) # 毫秒
|
PAGE_LOAD_TIMEOUT = int(os.environ.get("PAGE_LOAD_TIMEOUT", "60000")) # 毫秒
|
||||||
DEFAULT_TIMEOUT = int(os.environ.get('DEFAULT_TIMEOUT', '60000')) # 毫秒
|
DEFAULT_TIMEOUT = int(os.environ.get("DEFAULT_TIMEOUT", "60000")) # 毫秒
|
||||||
|
|
||||||
# ==================== 知识管理平台配置 ====================
|
# ==================== 知识管理平台配置 ====================
|
||||||
ZSGL_LOGIN_URL = os.environ.get('ZSGL_LOGIN_URL', 'https://postoa.aidunsoft.com/admin/login.aspx')
|
ZSGL_LOGIN_URL = os.environ.get("ZSGL_LOGIN_URL", "https://postoa.aidunsoft.com/admin/login.aspx")
|
||||||
ZSGL_INDEX_URL_PATTERN = os.environ.get('ZSGL_INDEX_URL_PATTERN', 'index.aspx')
|
ZSGL_INDEX_URL_PATTERN = os.environ.get("ZSGL_INDEX_URL_PATTERN", "index.aspx")
|
||||||
ZSGL_BASE_URL = os.environ.get('ZSGL_BASE_URL') or _derive_base_url_from_full_url(ZSGL_LOGIN_URL, 'https://postoa.aidunsoft.com')
|
ZSGL_BASE_URL = os.environ.get("ZSGL_BASE_URL") or _derive_base_url_from_full_url(
|
||||||
ZSGL_INDEX_URL = os.environ.get('ZSGL_INDEX_URL') or _derive_sibling_url(
|
ZSGL_LOGIN_URL, "https://postoa.aidunsoft.com"
|
||||||
|
)
|
||||||
|
ZSGL_INDEX_URL = os.environ.get("ZSGL_INDEX_URL") or _derive_sibling_url(
|
||||||
ZSGL_LOGIN_URL,
|
ZSGL_LOGIN_URL,
|
||||||
ZSGL_INDEX_URL_PATTERN,
|
ZSGL_INDEX_URL_PATTERN,
|
||||||
f"{ZSGL_BASE_URL}/admin/{ZSGL_INDEX_URL_PATTERN}",
|
f"{ZSGL_BASE_URL}/admin/{ZSGL_INDEX_URL_PATTERN}",
|
||||||
)
|
)
|
||||||
MAX_CONCURRENT_CONTEXTS = int(os.environ.get('MAX_CONCURRENT_CONTEXTS', '100'))
|
MAX_CONCURRENT_CONTEXTS = int(os.environ.get("MAX_CONCURRENT_CONTEXTS", "100"))
|
||||||
|
|
||||||
# ==================== 服务器配置 ====================
|
# ==================== 服务器配置 ====================
|
||||||
SERVER_HOST = os.environ.get('SERVER_HOST', '0.0.0.0')
|
SERVER_HOST = os.environ.get("SERVER_HOST", "0.0.0.0")
|
||||||
SERVER_PORT = int(os.environ.get('SERVER_PORT', '51233'))
|
SERVER_PORT = int(os.environ.get("SERVER_PORT", "51233"))
|
||||||
|
|
||||||
# ==================== SocketIO配置 ====================
|
# ==================== SocketIO配置 ====================
|
||||||
SOCKETIO_CORS_ALLOWED_ORIGINS = os.environ.get('SOCKETIO_CORS_ALLOWED_ORIGINS', '*')
|
SOCKETIO_CORS_ALLOWED_ORIGINS = os.environ.get("SOCKETIO_CORS_ALLOWED_ORIGINS", "*")
|
||||||
|
|
||||||
# ==================== 网站基础URL配置 ====================
|
# ==================== 网站基础URL配置 ====================
|
||||||
# 用于生成邮件中的验证链接等
|
# 用于生成邮件中的验证链接等
|
||||||
BASE_URL = os.environ.get('BASE_URL', 'http://localhost:51233')
|
BASE_URL = os.environ.get("BASE_URL", "http://localhost:51233")
|
||||||
|
|
||||||
# ==================== 日志配置 ====================
|
# ==================== 日志配置 ====================
|
||||||
# 安全修复: 生产环境默认使用INFO级别,避免泄露敏感调试信息
|
# 安全修复: 生产环境默认使用INFO级别,避免泄露敏感调试信息
|
||||||
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
|
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
|
||||||
LOG_FILE = os.environ.get('LOG_FILE', 'logs/app.log')
|
LOG_FILE = os.environ.get("LOG_FILE", "logs/app.log")
|
||||||
LOG_MAX_BYTES = int(os.environ.get('LOG_MAX_BYTES', '10485760')) # 10MB
|
LOG_MAX_BYTES = int(os.environ.get("LOG_MAX_BYTES", "10485760")) # 10MB
|
||||||
LOG_BACKUP_COUNT = int(os.environ.get('LOG_BACKUP_COUNT', '5'))
|
LOG_BACKUP_COUNT = int(os.environ.get("LOG_BACKUP_COUNT", "5"))
|
||||||
|
|
||||||
# ==================== 安全配置 ====================
|
# ==================== 安全配置 ====================
|
||||||
DEBUG = os.environ.get('FLASK_DEBUG', 'False').lower() == 'true'
|
DEBUG = os.environ.get("FLASK_DEBUG", "False").lower() == "true"
|
||||||
ALLOWED_SCREENSHOT_EXTENSIONS = {'.png', '.jpg', '.jpeg'}
|
ALLOWED_SCREENSHOT_EXTENSIONS = {".png", ".jpg", ".jpeg"}
|
||||||
MAX_SCREENSHOT_SIZE = int(os.environ.get('MAX_SCREENSHOT_SIZE', '10485760')) # 10MB
|
MAX_SCREENSHOT_SIZE = int(os.environ.get("MAX_SCREENSHOT_SIZE", "10485760")) # 10MB
|
||||||
LOGIN_CAPTCHA_AFTER_FAILURES = int(os.environ.get('LOGIN_CAPTCHA_AFTER_FAILURES', '3'))
|
LOGIN_CAPTCHA_AFTER_FAILURES = int(os.environ.get("LOGIN_CAPTCHA_AFTER_FAILURES", "3"))
|
||||||
LOGIN_CAPTCHA_WINDOW_SECONDS = int(os.environ.get('LOGIN_CAPTCHA_WINDOW_SECONDS', '900'))
|
LOGIN_CAPTCHA_WINDOW_SECONDS = int(os.environ.get("LOGIN_CAPTCHA_WINDOW_SECONDS", "900"))
|
||||||
LOGIN_RATE_LIMIT_WINDOW_SECONDS = int(os.environ.get('LOGIN_RATE_LIMIT_WINDOW_SECONDS', '900'))
|
LOGIN_RATE_LIMIT_WINDOW_SECONDS = int(os.environ.get("LOGIN_RATE_LIMIT_WINDOW_SECONDS", "900"))
|
||||||
LOGIN_IP_MAX_ATTEMPTS = int(os.environ.get('LOGIN_IP_MAX_ATTEMPTS', '60'))
|
LOGIN_IP_MAX_ATTEMPTS = int(os.environ.get("LOGIN_IP_MAX_ATTEMPTS", "60"))
|
||||||
LOGIN_USERNAME_MAX_ATTEMPTS = int(os.environ.get('LOGIN_USERNAME_MAX_ATTEMPTS', '30'))
|
LOGIN_USERNAME_MAX_ATTEMPTS = int(os.environ.get("LOGIN_USERNAME_MAX_ATTEMPTS", "30"))
|
||||||
LOGIN_IP_USERNAME_MAX_ATTEMPTS = int(os.environ.get('LOGIN_IP_USERNAME_MAX_ATTEMPTS', '12'))
|
LOGIN_IP_USERNAME_MAX_ATTEMPTS = int(os.environ.get("LOGIN_IP_USERNAME_MAX_ATTEMPTS", "12"))
|
||||||
LOGIN_FAIL_DELAY_BASE_MS = int(os.environ.get('LOGIN_FAIL_DELAY_BASE_MS', '200'))
|
LOGIN_FAIL_DELAY_BASE_MS = int(os.environ.get("LOGIN_FAIL_DELAY_BASE_MS", "200"))
|
||||||
LOGIN_FAIL_DELAY_MAX_MS = int(os.environ.get('LOGIN_FAIL_DELAY_MAX_MS', '1200'))
|
LOGIN_FAIL_DELAY_MAX_MS = int(os.environ.get("LOGIN_FAIL_DELAY_MAX_MS", "1200"))
|
||||||
LOGIN_ACCOUNT_LOCK_FAILURES = int(os.environ.get('LOGIN_ACCOUNT_LOCK_FAILURES', '6'))
|
LOGIN_ACCOUNT_LOCK_FAILURES = int(os.environ.get("LOGIN_ACCOUNT_LOCK_FAILURES", "6"))
|
||||||
LOGIN_ACCOUNT_LOCK_WINDOW_SECONDS = int(os.environ.get('LOGIN_ACCOUNT_LOCK_WINDOW_SECONDS', '900'))
|
LOGIN_ACCOUNT_LOCK_WINDOW_SECONDS = int(os.environ.get("LOGIN_ACCOUNT_LOCK_WINDOW_SECONDS", "900"))
|
||||||
LOGIN_ACCOUNT_LOCK_SECONDS = int(os.environ.get('LOGIN_ACCOUNT_LOCK_SECONDS', '600'))
|
LOGIN_ACCOUNT_LOCK_SECONDS = int(os.environ.get("LOGIN_ACCOUNT_LOCK_SECONDS", "600"))
|
||||||
LOGIN_SCAN_UNIQUE_USERNAME_THRESHOLD = int(os.environ.get('LOGIN_SCAN_UNIQUE_USERNAME_THRESHOLD', '8'))
|
LOGIN_SCAN_UNIQUE_USERNAME_THRESHOLD = int(os.environ.get("LOGIN_SCAN_UNIQUE_USERNAME_THRESHOLD", "8"))
|
||||||
LOGIN_SCAN_WINDOW_SECONDS = int(os.environ.get('LOGIN_SCAN_WINDOW_SECONDS', '600'))
|
LOGIN_SCAN_WINDOW_SECONDS = int(os.environ.get("LOGIN_SCAN_WINDOW_SECONDS", "600"))
|
||||||
LOGIN_SCAN_COOLDOWN_SECONDS = int(os.environ.get('LOGIN_SCAN_COOLDOWN_SECONDS', '600'))
|
LOGIN_SCAN_COOLDOWN_SECONDS = int(os.environ.get("LOGIN_SCAN_COOLDOWN_SECONDS", "600"))
|
||||||
EMAIL_RATE_LIMIT_MAX = int(os.environ.get('EMAIL_RATE_LIMIT_MAX', '6'))
|
EMAIL_RATE_LIMIT_MAX = int(os.environ.get("EMAIL_RATE_LIMIT_MAX", "6"))
|
||||||
EMAIL_RATE_LIMIT_WINDOW_SECONDS = int(os.environ.get('EMAIL_RATE_LIMIT_WINDOW_SECONDS', '3600'))
|
EMAIL_RATE_LIMIT_WINDOW_SECONDS = int(os.environ.get("EMAIL_RATE_LIMIT_WINDOW_SECONDS", "3600"))
|
||||||
LOGIN_ALERT_ENABLED = os.environ.get('LOGIN_ALERT_ENABLED', 'true').lower() == 'true'
|
LOGIN_ALERT_ENABLED = os.environ.get("LOGIN_ALERT_ENABLED", "true").lower() == "true"
|
||||||
LOGIN_ALERT_MIN_INTERVAL_SECONDS = int(os.environ.get('LOGIN_ALERT_MIN_INTERVAL_SECONDS', '3600'))
|
LOGIN_ALERT_MIN_INTERVAL_SECONDS = int(os.environ.get("LOGIN_ALERT_MIN_INTERVAL_SECONDS", "3600"))
|
||||||
ADMIN_REAUTH_WINDOW_SECONDS = int(os.environ.get('ADMIN_REAUTH_WINDOW_SECONDS', '600'))
|
ADMIN_REAUTH_WINDOW_SECONDS = int(os.environ.get("ADMIN_REAUTH_WINDOW_SECONDS", "600"))
|
||||||
SECURITY_ENABLED = os.environ.get('SECURITY_ENABLED', 'true').lower() == 'true'
|
SECURITY_ENABLED = os.environ.get("SECURITY_ENABLED", "true").lower() == "true"
|
||||||
SECURITY_LOG_LEVEL = os.environ.get('SECURITY_LOG_LEVEL', 'INFO')
|
SECURITY_LOG_LEVEL = os.environ.get("SECURITY_LOG_LEVEL", "INFO")
|
||||||
HONEYPOT_ENABLED = os.environ.get('HONEYPOT_ENABLED', 'true').lower() == 'true'
|
HONEYPOT_ENABLED = os.environ.get("HONEYPOT_ENABLED", "true").lower() == "true"
|
||||||
AUTO_BAN_ENABLED = os.environ.get('AUTO_BAN_ENABLED', 'true').lower() == 'true'
|
AUTO_BAN_ENABLED = os.environ.get("AUTO_BAN_ENABLED", "true").lower() == "true"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate(cls):
|
def validate(cls):
|
||||||
@@ -235,10 +251,10 @@ class Config:
|
|||||||
errors.append("DB_POOL_SIZE必须大于0")
|
errors.append("DB_POOL_SIZE必须大于0")
|
||||||
|
|
||||||
# 验证日志配置
|
# 验证日志配置
|
||||||
if cls.LOG_LEVEL not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
|
if cls.LOG_LEVEL not in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]:
|
||||||
errors.append(f"LOG_LEVEL无效: {cls.LOG_LEVEL}")
|
errors.append(f"LOG_LEVEL无效: {cls.LOG_LEVEL}")
|
||||||
|
|
||||||
if cls.SECURITY_LOG_LEVEL not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
|
if cls.SECURITY_LOG_LEVEL not in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]:
|
||||||
errors.append(f"SECURITY_LOG_LEVEL无效: {cls.SECURITY_LOG_LEVEL}")
|
errors.append(f"SECURITY_LOG_LEVEL无效: {cls.SECURITY_LOG_LEVEL}")
|
||||||
|
|
||||||
return errors
|
return errors
|
||||||
@@ -264,12 +280,14 @@ class Config:
|
|||||||
|
|
||||||
class DevelopmentConfig(Config):
|
class DevelopmentConfig(Config):
|
||||||
"""开发环境配置"""
|
"""开发环境配置"""
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
# 不覆盖SESSION_COOKIE_SECURE,使用父类的环境变量配置
|
# 不覆盖SESSION_COOKIE_SECURE,使用父类的环境变量配置
|
||||||
|
|
||||||
|
|
||||||
class ProductionConfig(Config):
|
class ProductionConfig(Config):
|
||||||
"""生产环境配置"""
|
"""生产环境配置"""
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
# 不覆盖SESSION_COOKIE_SECURE,使用父类的环境变量配置
|
# 不覆盖SESSION_COOKIE_SECURE,使用父类的环境变量配置
|
||||||
# 如需HTTPS,请在环境变量中设置 SESSION_COOKIE_SECURE=true
|
# 如需HTTPS,请在环境变量中设置 SESSION_COOKIE_SECURE=true
|
||||||
@@ -277,26 +295,27 @@ class ProductionConfig(Config):
|
|||||||
|
|
||||||
class TestingConfig(Config):
|
class TestingConfig(Config):
|
||||||
"""测试环境配置"""
|
"""测试环境配置"""
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
TESTING = True
|
TESTING = True
|
||||||
DB_FILE = 'data/test_app_data.db'
|
DB_FILE = "data/test_app_data.db"
|
||||||
|
|
||||||
|
|
||||||
# 根据环境变量选择配置
|
# 根据环境变量选择配置
|
||||||
config_map = {
|
config_map = {
|
||||||
'development': DevelopmentConfig,
|
"development": DevelopmentConfig,
|
||||||
'production': ProductionConfig,
|
"production": ProductionConfig,
|
||||||
'testing': TestingConfig,
|
"testing": TestingConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_config():
|
def get_config():
|
||||||
"""获取当前环境的配置"""
|
"""获取当前环境的配置"""
|
||||||
env = os.environ.get('FLASK_ENV', 'production')
|
env = os.environ.get("FLASK_ENV", "production")
|
||||||
return config_map.get(env, ProductionConfig)
|
return config_map.get(env, ProductionConfig)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
# 配置验证测试
|
# 配置验证测试
|
||||||
config = get_config()
|
config = get_config()
|
||||||
errors = config.validate()
|
errors = config.validate()
|
||||||
@@ -306,5 +325,5 @@ if __name__ == '__main__':
|
|||||||
for error in errors:
|
for error in errors:
|
||||||
print(f" ✗ {error}")
|
print(f" ✗ {error}")
|
||||||
else:
|
else:
|
||||||
print("✓ 配置验证通过")
|
print("[OK] 配置验证通过")
|
||||||
config.print_config()
|
config.print_config()
|
||||||
|
|||||||
@@ -281,9 +281,9 @@ def init_logging(log_level='INFO', log_file='logs/app.log'):
|
|||||||
# 创建审计日志器(已在AuditLogger中创建)
|
# 创建审计日志器(已在AuditLogger中创建)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
get_logger('app').info("✓ 日志系统初始化完成")
|
get_logger('app').info("[OK] 日志系统初始化完成")
|
||||||
except Exception:
|
except Exception:
|
||||||
print("✓ 日志系统初始化完成")
|
print("[OK] 日志系统初始化完成")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -1,214 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
浏览器自动下载安装模块
|
|
||||||
检测本地是否有Playwright浏览器,如果没有则自动下载安装
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# 设置浏览器安装路径(支持Docker和本地环境)
|
|
||||||
# Docker环境: PLAYWRIGHT_BROWSERS_PATH环境变量已设置为 /ms-playwright
|
|
||||||
# 本地环境: 使用Playwright默认路径
|
|
||||||
if 'PLAYWRIGHT_BROWSERS_PATH' in os.environ:
|
|
||||||
BROWSERS_PATH = os.environ['PLAYWRIGHT_BROWSERS_PATH']
|
|
||||||
else:
|
|
||||||
# Windows: %USERPROFILE%\AppData\Local\ms-playwright
|
|
||||||
# Linux: ~/.cache/ms-playwright
|
|
||||||
if sys.platform == 'win32':
|
|
||||||
BROWSERS_PATH = str(Path.home() / "AppData" / "Local" / "ms-playwright")
|
|
||||||
else:
|
|
||||||
BROWSERS_PATH = str(Path.home() / ".cache" / "ms-playwright")
|
|
||||||
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = BROWSERS_PATH
|
|
||||||
|
|
||||||
|
|
||||||
class BrowserInstaller:
|
|
||||||
"""浏览器安装器"""
|
|
||||||
|
|
||||||
def __init__(self, log_callback=None):
|
|
||||||
"""
|
|
||||||
初始化安装器
|
|
||||||
|
|
||||||
Args:
|
|
||||||
log_callback: 日志回调函数
|
|
||||||
"""
|
|
||||||
self.log_callback = log_callback
|
|
||||||
|
|
||||||
def log(self, message):
|
|
||||||
"""输出日志"""
|
|
||||||
if self.log_callback:
|
|
||||||
self.log_callback(message)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
print(message)
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
# 如果打印Unicode字符失败,替换特殊字符
|
|
||||||
safe_message = message.replace('✓', '[OK]').replace('✗', '[X]')
|
|
||||||
print(safe_message)
|
|
||||||
|
|
||||||
def check_playwright_installed(self):
|
|
||||||
"""检查Playwright是否已安装"""
|
|
||||||
try:
|
|
||||||
import playwright
|
|
||||||
self.log("✓ Playwright已安装")
|
|
||||||
return True
|
|
||||||
except ImportError:
|
|
||||||
self.log("✗ Playwright未安装")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def check_chromium_installed(self):
|
|
||||||
"""检查Chromium浏览器是否已安装"""
|
|
||||||
try:
|
|
||||||
from playwright.sync_api import sync_playwright
|
|
||||||
|
|
||||||
# 尝试启动浏览器检查是否可用
|
|
||||||
with sync_playwright() as p:
|
|
||||||
try:
|
|
||||||
# 使用超时快速检查
|
|
||||||
browser = p.chromium.launch(headless=True, timeout=5000)
|
|
||||||
browser.close()
|
|
||||||
self.log("✓ Chromium浏览器已安装且可用")
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
error_msg = str(e)
|
|
||||||
self.log(f"✗ Chromium浏览器不可用: {error_msg}")
|
|
||||||
|
|
||||||
# 检查是否是路径不存在的错误
|
|
||||||
if "Executable doesn't exist" in error_msg:
|
|
||||||
self.log("检测到浏览器文件缺失,需要重新安装")
|
|
||||||
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
self.log(f"✗ 检查浏览器时出错: {str(e)}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def install_chromium(self):
|
|
||||||
"""安装Chromium浏览器"""
|
|
||||||
try:
|
|
||||||
self.log("正在安装 Chromium 浏览器...")
|
|
||||||
|
|
||||||
# 查找 playwright 可执行文件
|
|
||||||
playwright_cli = None
|
|
||||||
possible_paths = [
|
|
||||||
os.path.join(os.path.dirname(sys.executable), "Scripts", "playwright.exe"),
|
|
||||||
os.path.join(os.path.dirname(sys.executable), "playwright.exe"),
|
|
||||||
os.path.join(os.path.dirname(sys.executable), "Scripts", "playwright"),
|
|
||||||
os.path.join(os.path.dirname(sys.executable), "playwright"),
|
|
||||||
"playwright", # 系统PATH中
|
|
||||||
]
|
|
||||||
|
|
||||||
for path in possible_paths:
|
|
||||||
if os.path.exists(path) or shutil.which(path):
|
|
||||||
playwright_cli = path
|
|
||||||
break
|
|
||||||
|
|
||||||
# 如果找到了 playwright CLI,直接调用
|
|
||||||
if playwright_cli:
|
|
||||||
self.log(f"使用 Playwright CLI: {playwright_cli}")
|
|
||||||
result = subprocess.run(
|
|
||||||
[playwright_cli, "install", "chromium"],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
timeout=300
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# 检测是否是 Nuitka 编译的程序
|
|
||||||
is_nuitka = hasattr(sys, 'frozen') or '__compiled__' in globals()
|
|
||||||
|
|
||||||
if is_nuitka:
|
|
||||||
self.log("检测到 Nuitka 编译环境")
|
|
||||||
self.log("✗ 无法找到 playwright CLI 工具")
|
|
||||||
self.log("请手动运行: playwright install chromium")
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
# 使用 python -m
|
|
||||||
result = subprocess.run(
|
|
||||||
[sys.executable, "-m", "playwright", "install", "chromium"],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
timeout=300
|
|
||||||
)
|
|
||||||
|
|
||||||
if result.returncode == 0:
|
|
||||||
self.log("✓ Chromium浏览器安装成功")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
self.log(f"✗ 浏览器安装失败: {result.stderr}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
except subprocess.TimeoutExpired:
|
|
||||||
self.log("✗ 浏览器安装超时")
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
self.log(f"✗ 浏览器安装出错: {str(e)}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def auto_install(self):
|
|
||||||
"""
|
|
||||||
自动检测并安装所需环境
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
是否成功安装或已安装
|
|
||||||
"""
|
|
||||||
self.log("=" * 60)
|
|
||||||
self.log("检查浏览器环境...")
|
|
||||||
self.log("=" * 60)
|
|
||||||
|
|
||||||
# 1. 检查Playwright是否安装
|
|
||||||
if not self.check_playwright_installed():
|
|
||||||
self.log("✗ Playwright未安装,无法继续")
|
|
||||||
self.log("请确保程序包含 Playwright 库")
|
|
||||||
return False
|
|
||||||
|
|
||||||
# 2. 检查Chromium浏览器是否安装
|
|
||||||
if not self.check_chromium_installed():
|
|
||||||
self.log("\n未检测到Chromium浏览器,开始自动安装...")
|
|
||||||
|
|
||||||
# 安装浏览器
|
|
||||||
if not self.install_chromium():
|
|
||||||
self.log("✗ 浏览器安装失败")
|
|
||||||
self.log("\n您可以尝试以下方法:")
|
|
||||||
self.log("1. 手动执行: playwright install chromium")
|
|
||||||
self.log("2. 检查网络连接后重试")
|
|
||||||
self.log("3. 检查防火墙设置")
|
|
||||||
return False
|
|
||||||
|
|
||||||
self.log("\n" + "=" * 60)
|
|
||||||
self.log("✓ 浏览器环境检查完成,一切就绪!")
|
|
||||||
self.log("=" * 60 + "\n")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def check_and_install_browser(log_callback=None):
|
|
||||||
"""
|
|
||||||
便捷函数:检查并安装浏览器
|
|
||||||
|
|
||||||
Args:
|
|
||||||
log_callback: 日志回调函数
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
是否成功
|
|
||||||
"""
|
|
||||||
installer = BrowserInstaller(log_callback)
|
|
||||||
return installer.auto_install()
|
|
||||||
|
|
||||||
|
|
||||||
# 测试代码
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print("浏览器自动安装工具")
|
|
||||||
print("=" * 60)
|
|
||||||
|
|
||||||
installer = BrowserInstaller()
|
|
||||||
success = installer.auto_install()
|
|
||||||
|
|
||||||
if success:
|
|
||||||
print("\n✓ 安装成功!您现在可以运行主程序了。")
|
|
||||||
else:
|
|
||||||
print("\n✗ 安装失败,请查看上方错误信息。")
|
|
||||||
|
|
||||||
print("=" * 60)
|
|
||||||
@@ -1,42 +1,100 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""浏览器池管理 - 工作线程池模式(真正的浏览器复用)"""
|
"""截图线程池管理 - 工作线程池模式(并发执行截图任务)"""
|
||||||
|
|
||||||
import os
|
|
||||||
import threading
|
|
||||||
import queue
|
|
||||||
import time
|
|
||||||
from typing import Callable, Optional, Dict, Any
|
|
||||||
import nest_asyncio
|
|
||||||
|
|
||||||
_NEST_ASYNCIO_APPLIED = False
|
import os
|
||||||
_NEST_ASYNCIO_LOCK = threading.Lock()
|
import threading
|
||||||
|
import queue
|
||||||
|
import time
|
||||||
|
from typing import Callable, Optional, Dict, Any
|
||||||
|
|
||||||
|
|
||||||
def _apply_nest_asyncio_once() -> None:
|
|
||||||
"""按需应用 nest_asyncio,避免 import 时产生全局副作用。"""
|
|
||||||
global _NEST_ASYNCIO_APPLIED
|
|
||||||
|
|
||||||
if _NEST_ASYNCIO_APPLIED:
|
|
||||||
return
|
|
||||||
with _NEST_ASYNCIO_LOCK:
|
|
||||||
if _NEST_ASYNCIO_APPLIED:
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
nest_asyncio.apply()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
_NEST_ASYNCIO_APPLIED = True
|
|
||||||
|
|
||||||
# 安全修复: 将魔法数字提取为可配置常量
|
# 安全修复: 将魔法数字提取为可配置常量
|
||||||
BROWSER_IDLE_TIMEOUT = int(os.environ.get('BROWSER_IDLE_TIMEOUT', '300')) # 空闲超时(秒),默认5分钟
|
BROWSER_IDLE_TIMEOUT = int(os.environ.get("BROWSER_IDLE_TIMEOUT", "300")) # 空闲超时(秒),默认5分钟
|
||||||
TASK_QUEUE_TIMEOUT = int(os.environ.get('TASK_QUEUE_TIMEOUT', '10')) # 队列获取超时(秒)
|
TASK_QUEUE_TIMEOUT = int(os.environ.get("TASK_QUEUE_TIMEOUT", "10")) # 队列获取超时(秒)
|
||||||
TASK_QUEUE_MAXSIZE = int(os.environ.get('BROWSER_TASK_QUEUE_MAXSIZE', '200')) # 队列最大长度(0表示无限制)
|
TASK_QUEUE_MAXSIZE = int(os.environ.get("BROWSER_TASK_QUEUE_MAXSIZE", "200")) # 队列最大长度(0表示无限制)
|
||||||
BROWSER_MAX_USE_COUNT = int(os.environ.get('BROWSER_MAX_USE_COUNT', '0')) # 每个浏览器最大复用次数(0表示不限制)
|
BROWSER_MAX_USE_COUNT = int(os.environ.get("BROWSER_MAX_USE_COUNT", "0")) # 每个执行环境最大复用次数(0表示不限制)
|
||||||
|
|
||||||
|
# 新增:自适应资源配置
|
||||||
|
ADAPTIVE_CONFIG = os.environ.get("BROWSER_ADAPTIVE_CONFIG", "1").strip().lower() in ("1", "true", "yes", "on")
|
||||||
|
LOAD_HISTORY_SIZE = 50 # 负载历史记录大小
|
||||||
|
|
||||||
|
|
||||||
|
class AdaptiveResourceManager:
|
||||||
|
"""自适应资源管理器"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._load_history = []
|
||||||
|
self._current_load = 0
|
||||||
|
self._last_adjustment = 0
|
||||||
|
self._adjustment_cooldown = 30 # 调整冷却时间30秒
|
||||||
|
|
||||||
|
def record_task_interval(self, interval: float):
|
||||||
|
"""记录任务间隔,更新负载历史"""
|
||||||
|
if len(self._load_history) >= LOAD_HISTORY_SIZE:
|
||||||
|
self._load_history.pop(0)
|
||||||
|
self._load_history.append(interval)
|
||||||
|
|
||||||
|
# 计算当前负载
|
||||||
|
if len(self._load_history) >= 2:
|
||||||
|
recent_intervals = self._load_history[-10:] # 最近10个任务
|
||||||
|
avg_interval = sum(recent_intervals) / len(recent_intervals)
|
||||||
|
# 负载越高,间隔越短
|
||||||
|
self._current_load = 1.0 / max(avg_interval, 0.1)
|
||||||
|
|
||||||
|
def should_adjust_timeout(self) -> bool:
|
||||||
|
"""判断是否应该调整超时配置"""
|
||||||
|
if not ADAPTIVE_CONFIG:
|
||||||
|
return False
|
||||||
|
|
||||||
|
current_time = time.time()
|
||||||
|
if current_time - self._last_adjustment < self._adjustment_cooldown:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return len(self._load_history) >= 10 # 至少需要10个数据点
|
||||||
|
|
||||||
|
def calculate_optimal_idle_timeout(self) -> int:
|
||||||
|
"""基于历史负载计算最优空闲超时"""
|
||||||
|
if not self._load_history:
|
||||||
|
return BROWSER_IDLE_TIMEOUT
|
||||||
|
|
||||||
|
# 计算最近任务间隔的平均值
|
||||||
|
recent_intervals = self._load_history[-20:] # 最近20个任务
|
||||||
|
if len(recent_intervals) < 2:
|
||||||
|
return BROWSER_IDLE_TIMEOUT
|
||||||
|
|
||||||
|
avg_interval = sum(recent_intervals) / len(recent_intervals)
|
||||||
|
|
||||||
|
# 根据负载动态调整超时
|
||||||
|
# 高负载时缩短超时,低负载时延长超时
|
||||||
|
if self._current_load > 2.0: # 高负载
|
||||||
|
optimal_timeout = min(avg_interval * 1.5, 600) # 最多10分钟
|
||||||
|
elif self._current_load < 0.5: # 低负载
|
||||||
|
optimal_timeout = min(avg_interval * 3.0, 1800) # 最多30分钟
|
||||||
|
else: # 正常负载
|
||||||
|
optimal_timeout = min(avg_interval * 2.0, 900) # 最多15分钟
|
||||||
|
|
||||||
|
return max(int(optimal_timeout), 60) # 最少1分钟
|
||||||
|
|
||||||
|
def get_optimal_queue_timeout(self) -> int:
|
||||||
|
"""获取最优队列超时"""
|
||||||
|
if not self._load_history:
|
||||||
|
return TASK_QUEUE_TIMEOUT
|
||||||
|
|
||||||
|
# 根据任务频率调整队列超时
|
||||||
|
if self._current_load > 2.0: # 高负载时减少等待
|
||||||
|
return max(TASK_QUEUE_TIMEOUT // 2, 3)
|
||||||
|
elif self._current_load < 0.5: # 低负载时可以增加等待
|
||||||
|
return min(TASK_QUEUE_TIMEOUT * 2, 30)
|
||||||
|
else:
|
||||||
|
return TASK_QUEUE_TIMEOUT
|
||||||
|
|
||||||
|
def record_adjustment(self):
|
||||||
|
"""记录一次调整操作"""
|
||||||
|
self._last_adjustment = time.time()
|
||||||
|
|
||||||
|
|
||||||
class BrowserWorker(threading.Thread):
|
class BrowserWorker(threading.Thread):
|
||||||
"""浏览器工作线程 - 每个worker维护自己的浏览器"""
|
"""截图工作线程 - 每个worker维护自己的执行环境"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -55,177 +113,206 @@ class BrowserWorker(threading.Thread):
|
|||||||
self.total_tasks = 0
|
self.total_tasks = 0
|
||||||
self.failed_tasks = 0
|
self.failed_tasks = 0
|
||||||
self.pre_warm = pre_warm
|
self.pre_warm = pre_warm
|
||||||
|
self.last_activity_ts = 0.0
|
||||||
def log(self, message: str):
|
self.task_start_time = 0.0
|
||||||
"""日志输出"""
|
|
||||||
if self.log_callback:
|
# 初始化自适应资源管理器
|
||||||
self.log_callback(f"[Worker-{self.worker_id}] {message}")
|
if ADAPTIVE_CONFIG:
|
||||||
else:
|
self._adaptive_mgr = AdaptiveResourceManager()
|
||||||
print(f"[浏览器池][Worker-{self.worker_id}] {message}")
|
else:
|
||||||
|
self._adaptive_mgr = None
|
||||||
def _create_browser(self):
|
|
||||||
"""创建浏览器实例"""
|
def log(self, message: str):
|
||||||
try:
|
"""日志输出"""
|
||||||
from playwright.sync_api import sync_playwright
|
if self.log_callback:
|
||||||
|
self.log_callback(f"[Worker-{self.worker_id}] {message}")
|
||||||
self.log("正在创建浏览器...")
|
else:
|
||||||
playwright = sync_playwright().start()
|
print(f"[截图池][Worker-{self.worker_id}] {message}")
|
||||||
browser = playwright.chromium.launch(
|
|
||||||
headless=True,
|
def _create_browser(self):
|
||||||
args=[
|
"""创建截图执行环境(逻辑占位,无需真实浏览器)"""
|
||||||
'--no-sandbox',
|
created_at = time.time()
|
||||||
'--disable-setuid-sandbox',
|
self.browser_instance = {
|
||||||
'--disable-dev-shm-usage',
|
"created_at": created_at,
|
||||||
'--disable-gpu',
|
"use_count": 0,
|
||||||
]
|
"worker_id": self.worker_id,
|
||||||
)
|
}
|
||||||
|
self.last_activity_ts = created_at
|
||||||
self.browser_instance = {
|
self.log("截图执行环境就绪")
|
||||||
'playwright': playwright,
|
return True
|
||||||
'browser': browser,
|
|
||||||
'created_at': time.time(),
|
def _close_browser(self):
|
||||||
'use_count': 0,
|
"""关闭截图执行环境"""
|
||||||
'worker_id': self.worker_id
|
if self.browser_instance:
|
||||||
}
|
self.log(f"执行环境已释放(共处理{self.browser_instance.get('use_count', 0)}个任务)")
|
||||||
self.log(f"浏览器创建成功")
|
self.browser_instance = None
|
||||||
return True
|
|
||||||
|
def _check_browser_health(self) -> bool:
|
||||||
except Exception as e:
|
"""检查执行环境是否就绪"""
|
||||||
self.log(f"创建浏览器失败: {e}")
|
return bool(self.browser_instance)
|
||||||
return False
|
|
||||||
|
def _ensure_browser(self) -> bool:
|
||||||
def _close_browser(self):
|
"""确保执行环境可用"""
|
||||||
"""关闭浏览器"""
|
if self._check_browser_health():
|
||||||
if self.browser_instance:
|
return True
|
||||||
try:
|
self.log("执行环境不可用,尝试重新创建...")
|
||||||
self.log("正在关闭浏览器...")
|
self._close_browser()
|
||||||
if self.browser_instance['browser']:
|
return self._create_browser()
|
||||||
self.browser_instance['browser'].close()
|
|
||||||
if self.browser_instance['playwright']:
|
def run(self):
|
||||||
self.browser_instance['playwright'].stop()
|
"""工作线程主循环 - 按需启动执行环境模式"""
|
||||||
self.log(f"浏览器已关闭(共处理{self.browser_instance['use_count']}个任务)")
|
if self.pre_warm:
|
||||||
except Exception as e:
|
self.log("Worker启动(预热模式,启动即准备执行环境)")
|
||||||
self.log(f"关闭浏览器时出错: {e}")
|
else:
|
||||||
finally:
|
self.log("Worker启动(按需模式,等待任务时不占用资源)")
|
||||||
self.browser_instance = None
|
|
||||||
|
|
||||||
def _check_browser_health(self) -> bool:
|
|
||||||
"""检查浏览器是否健康"""
|
|
||||||
if not self.browser_instance:
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
|
||||||
return self.browser_instance['browser'].is_connected()
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def _ensure_browser(self) -> bool:
|
|
||||||
"""确保浏览器可用(如果不可用则重新创建)"""
|
|
||||||
if self._check_browser_health():
|
|
||||||
return True
|
|
||||||
|
|
||||||
# 浏览器不可用,尝试重新创建
|
|
||||||
self.log("浏览器不可用,尝试重新创建...")
|
|
||||||
self._close_browser()
|
|
||||||
return self._create_browser()
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
"""工作线程主循环 - 按需启动浏览器模式"""
|
|
||||||
if self.pre_warm:
|
|
||||||
self.log("Worker启动(预热模式,启动即创建浏览器)")
|
|
||||||
else:
|
|
||||||
self.log("Worker启动(按需模式,等待任务时不占用浏览器资源)")
|
|
||||||
|
|
||||||
last_activity_time = 0
|
|
||||||
if self.pre_warm and not self.browser_instance:
|
if self.pre_warm and not self.browser_instance:
|
||||||
if self._create_browser():
|
self._create_browser()
|
||||||
last_activity_time = time.time()
|
|
||||||
self.pre_warm = False
|
self.pre_warm = False
|
||||||
|
|
||||||
while self.running:
|
while self.running:
|
||||||
try:
|
try:
|
||||||
# 允许运行中触发预热(例如池在初始化后调用 warmup)
|
# 允许运行中触发预热(例如池在初始化后调用 warmup)
|
||||||
if self.pre_warm and not self.browser_instance:
|
if self.pre_warm and not self.browser_instance:
|
||||||
if self._create_browser():
|
self._create_browser()
|
||||||
last_activity_time = time.time()
|
|
||||||
self.pre_warm = False
|
self.pre_warm = False
|
||||||
|
|
||||||
# 从队列获取任务(带超时,以便能响应停止信号和空闲检查)
|
# 从队列获取任务(带超时,以便能响应停止信号和空闲检查)
|
||||||
self.idle = True
|
self.idle = True
|
||||||
|
|
||||||
|
# 使用自适应队列超时
|
||||||
|
queue_timeout = (
|
||||||
|
self._adaptive_mgr.get_optimal_queue_timeout() if self._adaptive_mgr else TASK_QUEUE_TIMEOUT
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
task = self.task_queue.get(timeout=TASK_QUEUE_TIMEOUT)
|
task = self.task_queue.get(timeout=queue_timeout)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
# 检查是否需要关闭空闲的浏览器
|
# 检查是否需要释放空闲的执行环境
|
||||||
if self.browser_instance and last_activity_time > 0:
|
if self.browser_instance and self.last_activity_ts > 0:
|
||||||
idle_time = time.time() - last_activity_time
|
idle_time = time.time() - self.last_activity_ts
|
||||||
if idle_time > BROWSER_IDLE_TIMEOUT:
|
|
||||||
self.log(f"空闲{int(idle_time)}秒,关闭浏览器释放资源")
|
# 使用自适应空闲超时
|
||||||
|
optimal_timeout = (
|
||||||
|
self._adaptive_mgr.calculate_optimal_idle_timeout()
|
||||||
|
if self._adaptive_mgr
|
||||||
|
else BROWSER_IDLE_TIMEOUT
|
||||||
|
)
|
||||||
|
|
||||||
|
if idle_time > optimal_timeout:
|
||||||
|
self.log(f"空闲{int(idle_time)}秒(优化超时:{optimal_timeout}秒),释放执行环境")
|
||||||
self._close_browser()
|
self._close_browser()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.idle = False
|
self.idle = False
|
||||||
|
|
||||||
if task is None: # None作为停止信号
|
if task is None: # None作为停止信号
|
||||||
self.log("收到停止信号")
|
self.log("收到停止信号")
|
||||||
break
|
break
|
||||||
|
|
||||||
# 按需创建或确保浏览器可用
|
# 按需创建或确保执行环境可用
|
||||||
if not self._ensure_browser():
|
browser_ready = False
|
||||||
self.log("浏览器不可用,任务失败")
|
for attempt in range(2):
|
||||||
task['callback'](None, "浏览器不可用")
|
if self._ensure_browser():
|
||||||
self.failed_tasks += 1
|
browser_ready = True
|
||||||
continue
|
break
|
||||||
|
if attempt < 1:
|
||||||
# 执行任务
|
self.log("执行环境创建失败,重试...")
|
||||||
task_func = task.get('func')
|
time.sleep(0.5)
|
||||||
task_args = task.get('args', ())
|
|
||||||
task_kwargs = task.get('kwargs', {})
|
if not browser_ready:
|
||||||
callback = task.get('callback')
|
retry_count = int(task.get("retry_count", 0) or 0) if isinstance(task, dict) else 0
|
||||||
|
if retry_count < 1 and isinstance(task, dict):
|
||||||
self.total_tasks += 1
|
task["retry_count"] = retry_count + 1
|
||||||
self.browser_instance['use_count'] += 1
|
try:
|
||||||
|
self.task_queue.put(task, timeout=1)
|
||||||
self.log(f"开始执行任务(第{self.browser_instance['use_count']}次使用浏览器)")
|
self.log("执行环境不可用,任务重新入队")
|
||||||
|
except queue.Full:
|
||||||
|
self.log("任务队列已满,无法重新入队,任务失败")
|
||||||
|
callback = task.get("callback")
|
||||||
|
if callable(callback):
|
||||||
|
callback(None, "执行环境不可用")
|
||||||
|
self.total_tasks += 1
|
||||||
|
self.failed_tasks += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.log("执行环境不可用,任务失败")
|
||||||
|
callback = task.get("callback") if isinstance(task, dict) else None
|
||||||
|
if callable(callback):
|
||||||
|
callback(None, "执行环境不可用")
|
||||||
|
self.total_tasks += 1
|
||||||
|
self.failed_tasks += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 执行任务
|
||||||
|
task_func = task.get("func")
|
||||||
|
task_args = task.get("args", ())
|
||||||
|
task_kwargs = task.get("kwargs", {})
|
||||||
|
callback = task.get("callback")
|
||||||
|
|
||||||
|
self.total_tasks += 1
|
||||||
|
|
||||||
|
# 确保browser_instance存在后再访问
|
||||||
|
if self.browser_instance is None:
|
||||||
|
self.log("执行环境不可用,任务失败")
|
||||||
|
if callable(callback):
|
||||||
|
callback(None, "执行环境不可用")
|
||||||
|
self.failed_tasks += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.browser_instance["use_count"] += 1
|
||||||
|
|
||||||
|
self.log(f"开始执行任务(第{self.browser_instance['use_count']}次执行)")
|
||||||
|
|
||||||
|
# 记录任务开始时间
|
||||||
|
task_start_time = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 将浏览器实例传递给任务函数
|
# 将执行环境实例传递给任务函数
|
||||||
result = task_func(self.browser_instance, *task_args, **task_kwargs)
|
result = task_func(self.browser_instance, *task_args, **task_kwargs)
|
||||||
callback(result, None)
|
callback(result, None)
|
||||||
self.log(f"任务执行成功")
|
self.log(f"任务执行成功")
|
||||||
last_activity_time = time.time()
|
|
||||||
|
# 记录任务完成并更新负载历史
|
||||||
|
task_end_time = time.time()
|
||||||
|
task_interval = task_end_time - task_start_time
|
||||||
|
if self._adaptive_mgr:
|
||||||
|
self._adaptive_mgr.record_task_interval(task_interval)
|
||||||
|
|
||||||
|
self.last_activity_ts = time.time()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(f"任务执行失败: {e}")
|
self.log(f"任务执行失败: {e}")
|
||||||
callback(None, str(e))
|
callback(None, str(e))
|
||||||
self.failed_tasks += 1
|
self.failed_tasks += 1
|
||||||
last_activity_time = time.time()
|
self.last_activity_ts = time.time()
|
||||||
|
|
||||||
# 任务失败后,检查浏览器健康
|
# 任务失败后,检查执行环境健康
|
||||||
if not self._check_browser_health():
|
if not self._check_browser_health():
|
||||||
self.log("任务失败导致浏览器异常,将在下次任务前重建")
|
self.log("任务失败导致执行环境异常,将在下次任务前重建")
|
||||||
self._close_browser()
|
self._close_browser()
|
||||||
|
|
||||||
# 定期重启浏览器,释放Chromium可能累积的内存
|
# 定期重启执行环境,释放可能累积的资源
|
||||||
if self.browser_instance and BROWSER_MAX_USE_COUNT > 0:
|
if self.browser_instance and BROWSER_MAX_USE_COUNT > 0:
|
||||||
if self.browser_instance.get('use_count', 0) >= BROWSER_MAX_USE_COUNT:
|
if self.browser_instance.get("use_count", 0) >= BROWSER_MAX_USE_COUNT:
|
||||||
self.log(f"浏览器已复用{self.browser_instance['use_count']}次,重启释放资源")
|
self.log(f"执行环境已复用{self.browser_instance['use_count']}次,重启释放资源")
|
||||||
self._close_browser()
|
self._close_browser()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log(f"Worker出错: {e}")
|
self.log(f"Worker出错: {e}")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# 清理资源
|
# 清理资源
|
||||||
self._close_browser()
|
self._close_browser()
|
||||||
self.log(f"Worker停止(总任务:{self.total_tasks}, 失败:{self.failed_tasks})")
|
self.log(f"Worker停止(总任务:{self.total_tasks}, 失败:{self.failed_tasks})")
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""停止worker"""
|
"""停止worker"""
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
|
|
||||||
class BrowserWorkerPool:
|
class BrowserWorkerPool:
|
||||||
"""浏览器工作线程池"""
|
"""截图工作线程池"""
|
||||||
|
|
||||||
def __init__(self, pool_size: int = 3, log_callback: Optional[Callable] = None):
|
def __init__(self, pool_size: int = 3, log_callback: Optional[Callable] = None):
|
||||||
self.pool_size = pool_size
|
self.pool_size = pool_size
|
||||||
@@ -235,23 +322,21 @@ class BrowserWorkerPool:
|
|||||||
self.workers = []
|
self.workers = []
|
||||||
self.initialized = False
|
self.initialized = False
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
def log(self, message: str):
|
def log(self, message: str):
|
||||||
"""日志输出"""
|
"""日志输出"""
|
||||||
if self.log_callback:
|
if self.log_callback:
|
||||||
self.log_callback(message)
|
self.log_callback(message)
|
||||||
else:
|
else:
|
||||||
print(f"[浏览器池] {message}")
|
print(f"[截图池] {message}")
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
"""初始化工作线程池(按需模式,默认预热1个浏览器)"""
|
"""初始化工作线程池(按需模式,默认预热1个执行环境)"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if self.initialized:
|
if self.initialized:
|
||||||
return
|
return
|
||||||
|
|
||||||
_apply_nest_asyncio_once()
|
self.log(f"正在初始化截图线程池({self.pool_size}个worker,按需启动执行环境)...")
|
||||||
|
|
||||||
self.log(f"正在初始化工作线程池({self.pool_size}个worker,按需启动浏览器)...")
|
|
||||||
|
|
||||||
for i in range(self.pool_size):
|
for i in range(self.pool_size):
|
||||||
worker = BrowserWorker(
|
worker = BrowserWorker(
|
||||||
@@ -264,13 +349,13 @@ class BrowserWorkerPool:
|
|||||||
self.workers.append(worker)
|
self.workers.append(worker)
|
||||||
|
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
self.log(f"✓ 工作线程池初始化完成({self.pool_size}个worker就绪,浏览器将在有任务时按需启动)")
|
self.log(f"[OK] 截图线程池初始化完成({self.pool_size}个worker就绪,执行环境将在有任务时按需启动)")
|
||||||
|
|
||||||
# 初始化完成后,默认预热1个浏览器,降低容器重启后前几批任务的冷启动开销
|
# 初始化完成后,默认预热1个执行环境,降低容器重启后前几批任务的冷启动开销
|
||||||
self.warmup(1)
|
self.warmup(1)
|
||||||
|
|
||||||
def warmup(self, count: int = 1) -> int:
|
def warmup(self, count: int = 1) -> int:
|
||||||
"""预热浏览器池 - 预创建指定数量的浏览器"""
|
"""预热截图线程池 - 预创建指定数量的执行环境"""
|
||||||
if count <= 0:
|
if count <= 0:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -281,7 +366,7 @@ class BrowserWorkerPool:
|
|||||||
with self.lock:
|
with self.lock:
|
||||||
target_workers = list(self.workers[: min(count, len(self.workers))])
|
target_workers = list(self.workers[: min(count, len(self.workers))])
|
||||||
|
|
||||||
self.log(f"预热浏览器池(预创建{len(target_workers)}个浏览器)...")
|
self.log(f"预热截图线程池(预创建{len(target_workers)}个执行环境)...")
|
||||||
|
|
||||||
for worker in target_workers:
|
for worker in target_workers:
|
||||||
if not worker.browser_instance:
|
if not worker.browser_instance:
|
||||||
@@ -296,147 +381,208 @@ class BrowserWorkerPool:
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
warmed = sum(1 for w in target_workers if w.browser_instance)
|
warmed = sum(1 for w in target_workers if w.browser_instance)
|
||||||
self.log(f"✓ 浏览器池预热完成({warmed}个浏览器就绪)")
|
self.log(f"[OK] 截图线程池预热完成({warmed}个执行环境就绪)")
|
||||||
return warmed
|
return warmed
|
||||||
|
|
||||||
def submit_task(self, task_func: Callable, callback: Callable, *args, **kwargs) -> bool:
|
def submit_task(self, task_func: Callable, callback: Callable, *args, **kwargs) -> bool:
|
||||||
"""
|
"""
|
||||||
提交任务到队列
|
提交任务到队列
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
task_func: 任务函数,签名为 func(browser_instance, *args, **kwargs)
|
task_func: 任务函数,签名为 func(browser_instance, *args, **kwargs)
|
||||||
callback: 回调函数,签名为 callback(result, error)
|
callback: 回调函数,签名为 callback(result, error)
|
||||||
*args, **kwargs: 传递给task_func的参数
|
*args, **kwargs: 传递给task_func的参数
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
是否成功提交
|
是否成功提交
|
||||||
"""
|
"""
|
||||||
if not self.initialized:
|
if not self.initialized:
|
||||||
self.log("警告:线程池未初始化")
|
self.log("警告:线程池未初始化")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
task = {
|
task = {
|
||||||
'func': task_func,
|
"func": task_func,
|
||||||
'args': args,
|
"args": args,
|
||||||
'kwargs': kwargs,
|
"kwargs": kwargs,
|
||||||
'callback': callback
|
"callback": callback,
|
||||||
}
|
"retry_count": 0,
|
||||||
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.task_queue.put(task, timeout=1)
|
self.task_queue.put(task, timeout=1)
|
||||||
return True
|
return True
|
||||||
except queue.Full:
|
except queue.Full:
|
||||||
self.log(f"警告:任务队列已满(maxsize={self.task_queue.maxsize}),拒绝提交任务")
|
self.log(f"警告:任务队列已满(maxsize={self.task_queue.maxsize}),拒绝提交任务")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_stats(self) -> Dict[str, Any]:
|
def get_stats(self) -> Dict[str, Any]:
|
||||||
"""获取线程池统计信息"""
|
"""获取线程池统计信息"""
|
||||||
idle_count = sum(1 for w in self.workers if w.idle)
|
workers = list(self.workers or [])
|
||||||
total_tasks = sum(w.total_tasks for w in self.workers)
|
idle_count = sum(1 for w in workers if getattr(w, "idle", False))
|
||||||
failed_tasks = sum(w.failed_tasks for w in self.workers)
|
total_tasks = sum(int(getattr(w, "total_tasks", 0) or 0) for w in workers)
|
||||||
|
failed_tasks = sum(int(getattr(w, "failed_tasks", 0) or 0) for w in workers)
|
||||||
return {
|
|
||||||
'pool_size': self.pool_size,
|
worker_details = []
|
||||||
'idle_workers': idle_count,
|
for w in workers:
|
||||||
'busy_workers': self.pool_size - idle_count,
|
browser_instance = getattr(w, "browser_instance", None)
|
||||||
'queue_size': self.task_queue.qsize(),
|
browser_use_count = 0
|
||||||
'total_tasks': total_tasks,
|
browser_created_at = None
|
||||||
'failed_tasks': failed_tasks,
|
if isinstance(browser_instance, dict):
|
||||||
'success_rate': f"{(total_tasks - failed_tasks) / total_tasks * 100:.1f}%" if total_tasks > 0 else "N/A"
|
browser_use_count = int(browser_instance.get("use_count", 0) or 0)
|
||||||
}
|
browser_created_at = browser_instance.get("created_at")
|
||||||
|
|
||||||
def wait_for_completion(self, timeout: Optional[float] = None):
|
worker_details.append(
|
||||||
"""等待所有任务完成"""
|
{
|
||||||
start_time = time.time()
|
"worker_id": getattr(w, "worker_id", None),
|
||||||
while not self.task_queue.empty():
|
"idle": bool(getattr(w, "idle", False)),
|
||||||
if timeout and (time.time() - start_time) > timeout:
|
"has_browser": bool(browser_instance),
|
||||||
self.log("等待超时")
|
"total_tasks": int(getattr(w, "total_tasks", 0) or 0),
|
||||||
return False
|
"failed_tasks": int(getattr(w, "failed_tasks", 0) or 0),
|
||||||
time.sleep(0.5)
|
"browser_use_count": browser_use_count,
|
||||||
|
"browser_created_at": browser_created_at,
|
||||||
# 再等待一下确保正在执行的任务完成
|
"last_active_ts": float(getattr(w, "last_activity_ts", 0) or 0),
|
||||||
time.sleep(2)
|
"thread_alive": bool(getattr(w, "is_alive", lambda: False)()),
|
||||||
return True
|
}
|
||||||
|
)
|
||||||
def shutdown(self):
|
|
||||||
"""关闭线程池"""
|
return {
|
||||||
self.log("正在关闭工作线程池...")
|
"pool_size": self.pool_size,
|
||||||
|
"idle_workers": idle_count,
|
||||||
# 发送停止信号
|
"busy_workers": max(0, len(workers) - idle_count),
|
||||||
for _ in self.workers:
|
"queue_size": self.task_queue.qsize(),
|
||||||
self.task_queue.put(None)
|
"total_tasks": total_tasks,
|
||||||
|
"failed_tasks": failed_tasks,
|
||||||
# 等待所有worker停止
|
"success_rate": f"{(total_tasks - failed_tasks) / total_tasks * 100:.1f}%" if total_tasks > 0 else "N/A",
|
||||||
for worker in self.workers:
|
"workers": worker_details,
|
||||||
worker.join(timeout=10)
|
"timestamp": time.time(),
|
||||||
|
}
|
||||||
self.workers.clear()
|
|
||||||
self.initialized = False
|
def wait_for_completion(self, timeout: Optional[float] = None):
|
||||||
self.log("✓ 工作线程池已关闭")
|
"""等待所有任务完成"""
|
||||||
|
start_time = time.time()
|
||||||
|
while not self.task_queue.empty():
|
||||||
# 全局实例
|
if timeout and (time.time() - start_time) > timeout:
|
||||||
_global_pool: Optional[BrowserWorkerPool] = None
|
self.log("等待超时")
|
||||||
_pool_lock = threading.Lock()
|
return False
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
def get_browser_worker_pool(pool_size: int = 3, log_callback: Optional[Callable] = None) -> BrowserWorkerPool:
|
# 再等待一下确保正在执行的任务完成
|
||||||
"""获取全局浏览器工作线程池(单例)"""
|
time.sleep(2)
|
||||||
global _global_pool
|
return True
|
||||||
|
|
||||||
with _pool_lock:
|
def shutdown(self):
|
||||||
if _global_pool is None:
|
"""关闭线程池"""
|
||||||
_global_pool = BrowserWorkerPool(pool_size=pool_size, log_callback=log_callback)
|
self.log("正在关闭工作线程池...")
|
||||||
_global_pool.initialize()
|
|
||||||
|
# 发送停止信号
|
||||||
return _global_pool
|
for _ in self.workers:
|
||||||
|
self.task_queue.put(None)
|
||||||
|
|
||||||
def init_browser_worker_pool(pool_size: int = 3, log_callback: Optional[Callable] = None):
|
# 等待所有worker停止
|
||||||
"""初始化全局浏览器工作线程池"""
|
for worker in self.workers:
|
||||||
get_browser_worker_pool(pool_size=pool_size, log_callback=log_callback)
|
worker.join(timeout=10)
|
||||||
|
|
||||||
|
self.workers.clear()
|
||||||
def shutdown_browser_worker_pool():
|
self.initialized = False
|
||||||
"""关闭全局浏览器工作线程池"""
|
self.log("[OK] 工作线程池已关闭")
|
||||||
global _global_pool
|
|
||||||
|
|
||||||
with _pool_lock:
|
# 全局实例
|
||||||
if _global_pool:
|
_global_pool: Optional[BrowserWorkerPool] = None
|
||||||
_global_pool.shutdown()
|
_pool_lock = threading.Lock()
|
||||||
_global_pool = None
|
|
||||||
|
|
||||||
|
def get_browser_worker_pool(pool_size: int = 3, log_callback: Optional[Callable] = None) -> BrowserWorkerPool:
|
||||||
if __name__ == '__main__':
|
"""获取全局截图工作线程池(单例)"""
|
||||||
# 测试代码
|
global _global_pool
|
||||||
print("测试浏览器工作线程池...")
|
|
||||||
|
with _pool_lock:
|
||||||
def test_task(browser_instance, url: str, task_id: int):
|
if _global_pool is None:
|
||||||
"""测试任务:访问URL"""
|
_global_pool = BrowserWorkerPool(pool_size=pool_size, log_callback=log_callback)
|
||||||
print(f"[Task-{task_id}] 开始访问: {url}")
|
_global_pool.initialize()
|
||||||
time.sleep(2) # 模拟截图耗时
|
|
||||||
return {'task_id': task_id, 'url': url, 'status': 'success'}
|
return _global_pool
|
||||||
|
|
||||||
def test_callback(result, error):
|
|
||||||
"""测试回调"""
|
def init_browser_worker_pool(pool_size: int = 3, log_callback: Optional[Callable] = None):
|
||||||
if error:
|
"""初始化全局截图工作线程池"""
|
||||||
print(f"任务失败: {error}")
|
get_browser_worker_pool(pool_size=pool_size, log_callback=log_callback)
|
||||||
else:
|
|
||||||
print(f"任务成功: {result}")
|
|
||||||
|
def _shutdown_pool_when_idle(pool: BrowserWorkerPool) -> None:
|
||||||
# 创建线程池(2个worker)
|
try:
|
||||||
pool = BrowserWorkerPool(pool_size=2)
|
pool.wait_for_completion(timeout=60)
|
||||||
pool.initialize()
|
except Exception:
|
||||||
|
pass
|
||||||
# 提交4个任务
|
try:
|
||||||
for i in range(4):
|
pool.shutdown()
|
||||||
pool.submit_task(test_task, test_callback, f"https://example.com/{i}", i + 1)
|
except Exception:
|
||||||
|
pass
|
||||||
print("\n任务已提交,等待完成...")
|
|
||||||
pool.wait_for_completion()
|
|
||||||
|
def resize_browser_worker_pool(pool_size: int, log_callback: Optional[Callable] = None) -> bool:
|
||||||
print("\n统计信息:", pool.get_stats())
|
"""调整截图线程池并发(新任务走新池,旧池空闲后自动关闭)"""
|
||||||
|
global _global_pool
|
||||||
# 关闭线程池
|
|
||||||
pool.shutdown()
|
try:
|
||||||
print("\n测试完成!")
|
target_size = max(1, int(pool_size))
|
||||||
|
except Exception:
|
||||||
|
target_size = 1
|
||||||
|
|
||||||
|
with _pool_lock:
|
||||||
|
old_pool = _global_pool
|
||||||
|
if old_pool and int(getattr(old_pool, "pool_size", 0) or 0) == target_size:
|
||||||
|
return False
|
||||||
|
effective_log_callback = log_callback or (getattr(old_pool, "log_callback", None) if old_pool else None)
|
||||||
|
_global_pool = BrowserWorkerPool(pool_size=target_size, log_callback=effective_log_callback)
|
||||||
|
_global_pool.initialize()
|
||||||
|
|
||||||
|
if old_pool:
|
||||||
|
threading.Thread(target=_shutdown_pool_when_idle, args=(old_pool,), daemon=True).start()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def shutdown_browser_worker_pool():
|
||||||
|
"""关闭全局截图工作线程池"""
|
||||||
|
global _global_pool
|
||||||
|
|
||||||
|
with _pool_lock:
|
||||||
|
if _global_pool:
|
||||||
|
_global_pool.shutdown()
|
||||||
|
_global_pool = None
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 测试代码
|
||||||
|
print("测试截图工作线程池...")
|
||||||
|
|
||||||
|
def test_task(browser_instance, url: str, task_id: int):
|
||||||
|
"""测试任务:访问URL"""
|
||||||
|
print(f"[Task-{task_id}] 开始访问: {url}")
|
||||||
|
time.sleep(2) # 模拟截图耗时
|
||||||
|
return {"task_id": task_id, "url": url, "status": "success"}
|
||||||
|
|
||||||
|
def test_callback(result, error):
|
||||||
|
"""测试回调"""
|
||||||
|
if error:
|
||||||
|
print(f"任务失败: {error}")
|
||||||
|
else:
|
||||||
|
print(f"任务成功: {result}")
|
||||||
|
|
||||||
|
# 创建线程池(2个worker)
|
||||||
|
pool = BrowserWorkerPool(pool_size=2)
|
||||||
|
pool.initialize()
|
||||||
|
|
||||||
|
# 提交4个任务
|
||||||
|
for i in range(4):
|
||||||
|
pool.submit_task(test_task, test_callback, f"https://example.com/{i}", i + 1)
|
||||||
|
|
||||||
|
print("\n任务已提交,等待完成...")
|
||||||
|
pool.wait_for_completion()
|
||||||
|
|
||||||
|
print("\n统计信息:", pool.get_stats())
|
||||||
|
|
||||||
|
# 关闭线程池
|
||||||
|
pool.shutdown()
|
||||||
|
print("\n测试完成!")
|
||||||
|
|||||||
120
crypto_utils.py
120
crypto_utils.py
@@ -4,9 +4,15 @@
|
|||||||
加密工具模块
|
加密工具模块
|
||||||
用于加密存储敏感信息(如第三方账号密码)
|
用于加密存储敏感信息(如第三方账号密码)
|
||||||
使用Fernet对称加密
|
使用Fernet对称加密
|
||||||
|
|
||||||
|
安全增强版本 - 2026-01-21
|
||||||
|
- 支持 ENCRYPTION_KEY_RAW 直接使用 Fernet 密钥
|
||||||
|
- 增加密钥丢失保护机制
|
||||||
|
- 增加启动时密钥验证
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import base64
|
import base64
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
@@ -47,27 +53,89 @@ def _derive_key(password: bytes, salt: bytes) -> bytes:
|
|||||||
return base64.urlsafe_b64encode(kdf.derive(password))
|
return base64.urlsafe_b64encode(kdf.derive(password))
|
||||||
|
|
||||||
|
|
||||||
|
def _check_existing_encrypted_data() -> bool:
|
||||||
|
"""
|
||||||
|
检查是否存在已加密的数据
|
||||||
|
用于防止在有加密数据的情况下意外生成新密钥
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
import sqlite3
|
||||||
|
db_path = os.environ.get('DB_FILE', 'data/app_data.db')
|
||||||
|
if not Path(db_path).exists():
|
||||||
|
return False
|
||||||
|
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT COUNT(*) FROM accounts WHERE password LIKE 'gAAAAA%'")
|
||||||
|
count = cursor.fetchone()[0]
|
||||||
|
conn.close()
|
||||||
|
return count > 0
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"检查加密数据时出错: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_encryption_key():
|
def get_encryption_key():
|
||||||
"""获取加密密钥(优先环境变量,否则从文件读取或生成)"""
|
"""
|
||||||
# 优先从环境变量读取
|
获取加密密钥
|
||||||
|
|
||||||
|
优先级:
|
||||||
|
1. ENCRYPTION_KEY_RAW - 直接使用 Fernet 密钥(推荐用于 Docker 部署)
|
||||||
|
2. ENCRYPTION_KEY - 通过 PBKDF2 派生密钥
|
||||||
|
3. 从文件读取
|
||||||
|
4. 生成新密钥(仅在无现有加密数据时)
|
||||||
|
"""
|
||||||
|
# 优先级 1: 直接使用 Fernet 密钥(推荐)
|
||||||
|
raw_key = os.environ.get('ENCRYPTION_KEY_RAW')
|
||||||
|
if raw_key:
|
||||||
|
logger.info("使用环境变量 ENCRYPTION_KEY_RAW 作为加密密钥")
|
||||||
|
return raw_key.encode() if isinstance(raw_key, str) else raw_key
|
||||||
|
|
||||||
|
# 优先级 2: 从环境变量派生密钥
|
||||||
env_key = os.environ.get('ENCRYPTION_KEY')
|
env_key = os.environ.get('ENCRYPTION_KEY')
|
||||||
if env_key:
|
if env_key:
|
||||||
# 使用环境变量中的密钥派生Fernet密钥
|
logger.info("使用环境变量 ENCRYPTION_KEY 派生加密密钥")
|
||||||
salt = _get_or_create_salt()
|
salt = _get_or_create_salt()
|
||||||
return _derive_key(env_key.encode(), salt)
|
return _derive_key(env_key.encode(), salt)
|
||||||
|
|
||||||
# 从文件读取
|
# 优先级 3: 从文件读取
|
||||||
key_path = Path(ENCRYPTION_KEY_FILE)
|
key_path = Path(ENCRYPTION_KEY_FILE)
|
||||||
if key_path.exists():
|
if key_path.exists():
|
||||||
|
logger.info(f"从文件 {ENCRYPTION_KEY_FILE} 读取加密密钥")
|
||||||
with open(key_path, 'rb') as f:
|
with open(key_path, 'rb') as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
|
# 优先级 4: 生成新密钥(带保护检查)
|
||||||
|
# 安全检查:如果已有加密数据,禁止生成新密钥
|
||||||
|
if _check_existing_encrypted_data():
|
||||||
|
error_msg = (
|
||||||
|
"\n" + "=" * 60 + "\n"
|
||||||
|
"[严重错误] 检测到数据库中存在已加密的密码数据,但加密密钥文件丢失!\n"
|
||||||
|
"\n"
|
||||||
|
"这将导致所有已加密的密码无法解密!\n"
|
||||||
|
"\n"
|
||||||
|
"解决方案:\n"
|
||||||
|
"1. 恢复 data/encryption_key.bin 文件(如有备份)\n"
|
||||||
|
"2. 或在 docker-compose.yml 中设置 ENCRYPTION_KEY_RAW 环境变量\n"
|
||||||
|
"3. 如果密钥确实丢失,需要重新录入所有账号密码\n"
|
||||||
|
"\n"
|
||||||
|
"设置 ALLOW_NEW_KEY=true 环境变量可强制生成新密钥(不推荐)\n"
|
||||||
|
+ "=" * 60
|
||||||
|
)
|
||||||
|
logger.error(error_msg)
|
||||||
|
|
||||||
|
# 检查是否强制允许生成新密钥
|
||||||
|
if os.environ.get('ALLOW_NEW_KEY', '').lower() != 'true':
|
||||||
|
print(error_msg, file=sys.stderr)
|
||||||
|
raise RuntimeError("加密密钥丢失且存在已加密数据,请检查配置")
|
||||||
|
|
||||||
# 生成新的密钥
|
# 生成新的密钥
|
||||||
key = Fernet.generate_key()
|
key = Fernet.generate_key()
|
||||||
os.makedirs(key_path.parent, exist_ok=True)
|
os.makedirs(key_path.parent, exist_ok=True)
|
||||||
with open(key_path, 'wb') as f:
|
with open(key_path, 'wb') as f:
|
||||||
f.write(key)
|
f.write(key)
|
||||||
logger.info(f"已生成新的加密密钥并保存到 {ENCRYPTION_KEY_FILE}")
|
logger.info(f"已生成新的加密密钥并保存到 {ENCRYPTION_KEY_FILE}")
|
||||||
|
logger.warning("请立即备份此密钥文件,并建议设置 ENCRYPTION_KEY_RAW 环境变量!")
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
|
||||||
@@ -120,8 +188,11 @@ def decrypt_password(encrypted_password: str) -> str:
|
|||||||
decrypted = fernet.decrypt(encrypted_password.encode('utf-8'))
|
decrypted = fernet.decrypt(encrypted_password.encode('utf-8'))
|
||||||
return decrypted.decode('utf-8')
|
return decrypted.decode('utf-8')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 解密失败,可能是旧的明文密码
|
# 解密失败,可能是旧的明文密码或密钥不匹配
|
||||||
logger.warning(f"密码解密失败,可能是未加密的旧数据: {e}")
|
if is_encrypted(encrypted_password):
|
||||||
|
logger.error(f"密码解密失败(密钥可能不匹配): {e}")
|
||||||
|
else:
|
||||||
|
logger.warning(f"密码解密失败,可能是未加密的旧数据: {e}")
|
||||||
return encrypted_password
|
return encrypted_password
|
||||||
|
|
||||||
|
|
||||||
@@ -138,7 +209,6 @@ def is_encrypted(password: str) -> bool:
|
|||||||
"""
|
"""
|
||||||
if not password:
|
if not password:
|
||||||
return False
|
return False
|
||||||
# Fernet加密的数据是base64编码,以'gAAAAA'开头
|
|
||||||
return password.startswith('gAAAAA')
|
return password.startswith('gAAAAA')
|
||||||
|
|
||||||
|
|
||||||
@@ -157,6 +227,39 @@ def migrate_password(password: str) -> str:
|
|||||||
return encrypt_password(password)
|
return encrypt_password(password)
|
||||||
|
|
||||||
|
|
||||||
|
def verify_encryption_key() -> bool:
|
||||||
|
"""
|
||||||
|
验证当前密钥是否能解密现有数据
|
||||||
|
用于启动时检查
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 密钥是否有效
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
import sqlite3
|
||||||
|
db_path = os.environ.get('DB_FILE', 'data/app_data.db')
|
||||||
|
if not Path(db_path).exists():
|
||||||
|
return True
|
||||||
|
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT password FROM accounts WHERE password LIKE 'gAAAAA%' LIMIT 1")
|
||||||
|
row = cursor.fetchone()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if not row:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# 尝试解密
|
||||||
|
fernet = _get_fernet()
|
||||||
|
fernet.decrypt(row[0].encode('utf-8'))
|
||||||
|
logger.info("加密密钥验证成功")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"加密密钥验证失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# 测试加密解密
|
# 测试加密解密
|
||||||
test_password = "test_password_123"
|
test_password = "test_password_123"
|
||||||
@@ -169,3 +272,6 @@ if __name__ == '__main__':
|
|||||||
print(f"加密解密成功: {test_password == decrypted}")
|
print(f"加密解密成功: {test_password == decrypted}")
|
||||||
print(f"是否已加密: {is_encrypted(encrypted)}")
|
print(f"是否已加密: {is_encrypted(encrypted)}")
|
||||||
print(f"明文是否加密: {is_encrypted(test_password)}")
|
print(f"明文是否加密: {is_encrypted(test_password)}")
|
||||||
|
|
||||||
|
# 验证密钥
|
||||||
|
print(f"\n密钥验证: {verify_encryption_key()}")
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Netscape HTTP Cookie File
|
||||||
|
# This file was generated by zsglpt
|
||||||
|
postoa.aidunsoft.com FALSE / FALSE 0 ASP.NET_SessionId xtjioeuz4yvk4bx3xqyt0pyp
|
||||||
|
postoa.aidunsoft.com FALSE / FALSE 1800092244 UserInfo userName=13974663700&Pwd=9B8DC766B11550651353D98805B4995B
|
||||||
1
data/encryption_key.bin
Normal file
1
data/encryption_key.bin
Normal file
@@ -0,0 +1 @@
|
|||||||
|
_S5Vpk71XaK9bm5U8jHJe-x2ASm38YWNweVlmCcIauM=
|
||||||
1
data/kdocs_login_state.json
Normal file
1
data/kdocs_login_state.json
Normal file
File diff suppressed because one or more lines are too long
1
data/secret_key.txt
Normal file
1
data/secret_key.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
4abccefe523ed05bdbb717d1153e202d25ade95458c4d78e
|
||||||
29
database.py
29
database.py
@@ -40,6 +40,7 @@ from db.accounts import (
|
|||||||
delete_user_accounts,
|
delete_user_accounts,
|
||||||
get_account,
|
get_account,
|
||||||
get_account_status,
|
get_account_status,
|
||||||
|
get_account_status_batch,
|
||||||
get_user_accounts,
|
get_user_accounts,
|
||||||
increment_account_login_fail,
|
increment_account_login_fail,
|
||||||
reset_account_login_status,
|
reset_account_login_status,
|
||||||
@@ -99,6 +100,7 @@ from db.users import (
|
|||||||
get_pending_users,
|
get_pending_users,
|
||||||
get_user_by_id,
|
get_user_by_id,
|
||||||
get_user_by_username,
|
get_user_by_username,
|
||||||
|
get_user_kdocs_settings,
|
||||||
get_user_stats,
|
get_user_stats,
|
||||||
get_user_vip_info,
|
get_user_vip_info,
|
||||||
get_vip_config,
|
get_vip_config,
|
||||||
@@ -107,6 +109,7 @@ from db.users import (
|
|||||||
remove_user_vip,
|
remove_user_vip,
|
||||||
set_default_vip_days,
|
set_default_vip_days,
|
||||||
set_user_vip,
|
set_user_vip,
|
||||||
|
update_user_kdocs_settings,
|
||||||
verify_user,
|
verify_user,
|
||||||
)
|
)
|
||||||
from db.security import record_login_context
|
from db.security import record_login_context
|
||||||
@@ -117,7 +120,7 @@ config = get_config()
|
|||||||
DB_FILE = config.DB_FILE
|
DB_FILE = config.DB_FILE
|
||||||
|
|
||||||
# 数据库版本 (用于迁移管理)
|
# 数据库版本 (用于迁移管理)
|
||||||
DB_VERSION = 15
|
DB_VERSION = 17
|
||||||
|
|
||||||
|
|
||||||
# ==================== 系统配置缓存(P1 / O-03) ====================
|
# ==================== 系统配置缓存(P1 / O-03) ====================
|
||||||
@@ -186,12 +189,24 @@ def update_system_config(
|
|||||||
schedule_weekdays=None,
|
schedule_weekdays=None,
|
||||||
max_concurrent_per_account=None,
|
max_concurrent_per_account=None,
|
||||||
max_screenshot_concurrent=None,
|
max_screenshot_concurrent=None,
|
||||||
|
enable_screenshot=None,
|
||||||
proxy_enabled=None,
|
proxy_enabled=None,
|
||||||
proxy_api_url=None,
|
proxy_api_url=None,
|
||||||
proxy_expire_minutes=None,
|
proxy_expire_minutes=None,
|
||||||
auto_approve_enabled=None,
|
auto_approve_enabled=None,
|
||||||
auto_approve_hourly_limit=None,
|
auto_approve_hourly_limit=None,
|
||||||
auto_approve_vip_days=None,
|
auto_approve_vip_days=None,
|
||||||
|
kdocs_enabled=None,
|
||||||
|
kdocs_doc_url=None,
|
||||||
|
kdocs_default_unit=None,
|
||||||
|
kdocs_sheet_name=None,
|
||||||
|
kdocs_sheet_index=None,
|
||||||
|
kdocs_unit_column=None,
|
||||||
|
kdocs_image_column=None,
|
||||||
|
kdocs_admin_notify_enabled=None,
|
||||||
|
kdocs_admin_notify_email=None,
|
||||||
|
kdocs_row_start=None,
|
||||||
|
kdocs_row_end=None,
|
||||||
):
|
):
|
||||||
"""更新系统配置(写入后立即失效缓存)。"""
|
"""更新系统配置(写入后立即失效缓存)。"""
|
||||||
ok = _update_system_config(
|
ok = _update_system_config(
|
||||||
@@ -202,12 +217,24 @@ def update_system_config(
|
|||||||
schedule_weekdays=schedule_weekdays,
|
schedule_weekdays=schedule_weekdays,
|
||||||
max_concurrent_per_account=max_concurrent_per_account,
|
max_concurrent_per_account=max_concurrent_per_account,
|
||||||
max_screenshot_concurrent=max_screenshot_concurrent,
|
max_screenshot_concurrent=max_screenshot_concurrent,
|
||||||
|
enable_screenshot=enable_screenshot,
|
||||||
proxy_enabled=proxy_enabled,
|
proxy_enabled=proxy_enabled,
|
||||||
proxy_api_url=proxy_api_url,
|
proxy_api_url=proxy_api_url,
|
||||||
proxy_expire_minutes=proxy_expire_minutes,
|
proxy_expire_minutes=proxy_expire_minutes,
|
||||||
auto_approve_enabled=auto_approve_enabled,
|
auto_approve_enabled=auto_approve_enabled,
|
||||||
auto_approve_hourly_limit=auto_approve_hourly_limit,
|
auto_approve_hourly_limit=auto_approve_hourly_limit,
|
||||||
auto_approve_vip_days=auto_approve_vip_days,
|
auto_approve_vip_days=auto_approve_vip_days,
|
||||||
|
kdocs_enabled=kdocs_enabled,
|
||||||
|
kdocs_doc_url=kdocs_doc_url,
|
||||||
|
kdocs_default_unit=kdocs_default_unit,
|
||||||
|
kdocs_sheet_name=kdocs_sheet_name,
|
||||||
|
kdocs_sheet_index=kdocs_sheet_index,
|
||||||
|
kdocs_unit_column=kdocs_unit_column,
|
||||||
|
kdocs_image_column=kdocs_image_column,
|
||||||
|
kdocs_admin_notify_enabled=kdocs_admin_notify_enabled,
|
||||||
|
kdocs_admin_notify_email=kdocs_admin_notify_email,
|
||||||
|
kdocs_row_start=kdocs_row_start,
|
||||||
|
kdocs_row_end=kdocs_row_end,
|
||||||
)
|
)
|
||||||
if ok:
|
if ok:
|
||||||
invalidate_system_config_cache()
|
invalidate_system_config_cache()
|
||||||
|
|||||||
@@ -140,6 +140,36 @@ def get_account_status(account_id):
|
|||||||
return cursor.fetchone()
|
return cursor.fetchone()
|
||||||
|
|
||||||
|
|
||||||
|
def get_account_status_batch(account_ids):
|
||||||
|
"""批量获取账号状态信息"""
|
||||||
|
account_ids = [str(account_id) for account_id in (account_ids or []) if account_id]
|
||||||
|
if not account_ids:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
results = {}
|
||||||
|
chunk_size = 900 # 避免触发 SQLite 绑定参数上限
|
||||||
|
with db_pool.get_db() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
for idx in range(0, len(account_ids), chunk_size):
|
||||||
|
chunk = account_ids[idx : idx + chunk_size]
|
||||||
|
placeholders = ",".join("?" for _ in chunk)
|
||||||
|
cursor.execute(
|
||||||
|
f"""
|
||||||
|
SELECT id, status, login_fail_count, last_login_error
|
||||||
|
FROM accounts
|
||||||
|
WHERE id IN ({placeholders})
|
||||||
|
""",
|
||||||
|
chunk,
|
||||||
|
)
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
row_dict = dict(row)
|
||||||
|
account_id = str(row_dict.pop("id", ""))
|
||||||
|
if account_id:
|
||||||
|
results[account_id] = row_dict
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def delete_user_accounts(user_id):
|
def delete_user_accounts(user_id):
|
||||||
"""删除用户的所有账号"""
|
"""删除用户的所有账号"""
|
||||||
with db_pool.get_db() as conn:
|
with db_pool.get_db() as conn:
|
||||||
@@ -147,4 +177,3 @@ def delete_user_accounts(user_id):
|
|||||||
cursor.execute("DELETE FROM accounts WHERE user_id = ?", (user_id,))
|
cursor.execute("DELETE FROM accounts WHERE user_id = ?", (user_id,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return cursor.rowcount
|
return cursor.rowcount
|
||||||
|
|
||||||
|
|||||||
71
db/admin.py
71
db/admin.py
@@ -172,6 +172,17 @@ def get_system_config_raw() -> dict:
|
|||||||
"auto_approve_enabled": 0,
|
"auto_approve_enabled": 0,
|
||||||
"auto_approve_hourly_limit": 10,
|
"auto_approve_hourly_limit": 10,
|
||||||
"auto_approve_vip_days": 7,
|
"auto_approve_vip_days": 7,
|
||||||
|
"kdocs_enabled": 0,
|
||||||
|
"kdocs_doc_url": "",
|
||||||
|
"kdocs_default_unit": "",
|
||||||
|
"kdocs_sheet_name": "",
|
||||||
|
"kdocs_sheet_index": 0,
|
||||||
|
"kdocs_unit_column": "A",
|
||||||
|
"kdocs_image_column": "D",
|
||||||
|
"kdocs_admin_notify_enabled": 0,
|
||||||
|
"kdocs_admin_notify_email": "",
|
||||||
|
"kdocs_row_start": 0,
|
||||||
|
"kdocs_row_end": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -184,12 +195,24 @@ def update_system_config(
|
|||||||
schedule_weekdays=None,
|
schedule_weekdays=None,
|
||||||
max_concurrent_per_account=None,
|
max_concurrent_per_account=None,
|
||||||
max_screenshot_concurrent=None,
|
max_screenshot_concurrent=None,
|
||||||
|
enable_screenshot=None,
|
||||||
proxy_enabled=None,
|
proxy_enabled=None,
|
||||||
proxy_api_url=None,
|
proxy_api_url=None,
|
||||||
proxy_expire_minutes=None,
|
proxy_expire_minutes=None,
|
||||||
auto_approve_enabled=None,
|
auto_approve_enabled=None,
|
||||||
auto_approve_hourly_limit=None,
|
auto_approve_hourly_limit=None,
|
||||||
auto_approve_vip_days=None,
|
auto_approve_vip_days=None,
|
||||||
|
kdocs_enabled=None,
|
||||||
|
kdocs_doc_url=None,
|
||||||
|
kdocs_default_unit=None,
|
||||||
|
kdocs_sheet_name=None,
|
||||||
|
kdocs_sheet_index=None,
|
||||||
|
kdocs_unit_column=None,
|
||||||
|
kdocs_image_column=None,
|
||||||
|
kdocs_admin_notify_enabled=None,
|
||||||
|
kdocs_admin_notify_email=None,
|
||||||
|
kdocs_row_start=None,
|
||||||
|
kdocs_row_end=None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""更新系统配置(仅更新DB,不做缓存处理)。"""
|
"""更新系统配置(仅更新DB,不做缓存处理)。"""
|
||||||
allowed_fields = {
|
allowed_fields = {
|
||||||
@@ -200,12 +223,24 @@ def update_system_config(
|
|||||||
"schedule_weekdays",
|
"schedule_weekdays",
|
||||||
"max_concurrent_per_account",
|
"max_concurrent_per_account",
|
||||||
"max_screenshot_concurrent",
|
"max_screenshot_concurrent",
|
||||||
|
"enable_screenshot",
|
||||||
"proxy_enabled",
|
"proxy_enabled",
|
||||||
"proxy_api_url",
|
"proxy_api_url",
|
||||||
"proxy_expire_minutes",
|
"proxy_expire_minutes",
|
||||||
"auto_approve_enabled",
|
"auto_approve_enabled",
|
||||||
"auto_approve_hourly_limit",
|
"auto_approve_hourly_limit",
|
||||||
"auto_approve_vip_days",
|
"auto_approve_vip_days",
|
||||||
|
"kdocs_enabled",
|
||||||
|
"kdocs_doc_url",
|
||||||
|
"kdocs_default_unit",
|
||||||
|
"kdocs_sheet_name",
|
||||||
|
"kdocs_sheet_index",
|
||||||
|
"kdocs_unit_column",
|
||||||
|
"kdocs_image_column",
|
||||||
|
"kdocs_admin_notify_enabled",
|
||||||
|
"kdocs_admin_notify_email",
|
||||||
|
"kdocs_row_start",
|
||||||
|
"kdocs_row_end",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +267,9 @@ def update_system_config(
|
|||||||
if max_screenshot_concurrent is not None:
|
if max_screenshot_concurrent is not None:
|
||||||
updates.append("max_screenshot_concurrent = ?")
|
updates.append("max_screenshot_concurrent = ?")
|
||||||
params.append(max_screenshot_concurrent)
|
params.append(max_screenshot_concurrent)
|
||||||
|
if enable_screenshot is not None:
|
||||||
|
updates.append("enable_screenshot = ?")
|
||||||
|
params.append(enable_screenshot)
|
||||||
if schedule_weekdays is not None:
|
if schedule_weekdays is not None:
|
||||||
updates.append("schedule_weekdays = ?")
|
updates.append("schedule_weekdays = ?")
|
||||||
params.append(schedule_weekdays)
|
params.append(schedule_weekdays)
|
||||||
@@ -253,6 +291,39 @@ def update_system_config(
|
|||||||
if auto_approve_vip_days is not None:
|
if auto_approve_vip_days is not None:
|
||||||
updates.append("auto_approve_vip_days = ?")
|
updates.append("auto_approve_vip_days = ?")
|
||||||
params.append(auto_approve_vip_days)
|
params.append(auto_approve_vip_days)
|
||||||
|
if kdocs_enabled is not None:
|
||||||
|
updates.append("kdocs_enabled = ?")
|
||||||
|
params.append(kdocs_enabled)
|
||||||
|
if kdocs_doc_url is not None:
|
||||||
|
updates.append("kdocs_doc_url = ?")
|
||||||
|
params.append(kdocs_doc_url)
|
||||||
|
if kdocs_default_unit is not None:
|
||||||
|
updates.append("kdocs_default_unit = ?")
|
||||||
|
params.append(kdocs_default_unit)
|
||||||
|
if kdocs_sheet_name is not None:
|
||||||
|
updates.append("kdocs_sheet_name = ?")
|
||||||
|
params.append(kdocs_sheet_name)
|
||||||
|
if kdocs_sheet_index is not None:
|
||||||
|
updates.append("kdocs_sheet_index = ?")
|
||||||
|
params.append(kdocs_sheet_index)
|
||||||
|
if kdocs_unit_column is not None:
|
||||||
|
updates.append("kdocs_unit_column = ?")
|
||||||
|
params.append(kdocs_unit_column)
|
||||||
|
if kdocs_image_column is not None:
|
||||||
|
updates.append("kdocs_image_column = ?")
|
||||||
|
params.append(kdocs_image_column)
|
||||||
|
if kdocs_admin_notify_enabled is not None:
|
||||||
|
updates.append("kdocs_admin_notify_enabled = ?")
|
||||||
|
params.append(kdocs_admin_notify_enabled)
|
||||||
|
if kdocs_admin_notify_email is not None:
|
||||||
|
updates.append("kdocs_admin_notify_email = ?")
|
||||||
|
params.append(kdocs_admin_notify_email)
|
||||||
|
if kdocs_row_start is not None:
|
||||||
|
updates.append("kdocs_row_start = ?")
|
||||||
|
params.append(kdocs_row_start)
|
||||||
|
if kdocs_row_end is not None:
|
||||||
|
updates.append("kdocs_row_end = ?")
|
||||||
|
params.append(kdocs_row_end)
|
||||||
|
|
||||||
if not updates:
|
if not updates:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import db_pool
|
|||||||
from db.utils import get_cst_now_str
|
from db.utils import get_cst_now_str
|
||||||
|
|
||||||
|
|
||||||
def create_announcement(title, content, is_active=True):
|
def create_announcement(title, content, image_url=None, is_active=True):
|
||||||
"""创建公告(默认启用;启用时会自动停用其他公告)"""
|
"""创建公告(默认启用;启用时会自动停用其他公告)"""
|
||||||
title = (title or "").strip()
|
title = (title or "").strip()
|
||||||
content = (content or "").strip()
|
content = (content or "").strip()
|
||||||
|
image_url = (image_url or "").strip()
|
||||||
|
image_url = image_url or None
|
||||||
if not title or not content:
|
if not title or not content:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -22,10 +24,10 @@ def create_announcement(title, content, is_active=True):
|
|||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO announcements (title, content, is_active, created_at, updated_at)
|
INSERT INTO announcements (title, content, image_url, is_active, created_at, updated_at)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(title, content, 1 if is_active else 0, cst_time, cst_time),
|
(title, content, image_url, 1 if is_active else 0, cst_time, cst_time),
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return cursor.lastrowid
|
return cursor.lastrowid
|
||||||
@@ -129,4 +131,3 @@ def dismiss_announcement_for_user(user_id, announcement_id):
|
|||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return cursor.rowcount >= 0
|
return cursor.rowcount >= 0
|
||||||
|
|
||||||
|
|||||||
143
db/migrations.py
143
db/migrations.py
@@ -81,6 +81,15 @@ def migrate_database(conn, target_version: int) -> None:
|
|||||||
if current_version < 15:
|
if current_version < 15:
|
||||||
_migrate_to_v15(conn)
|
_migrate_to_v15(conn)
|
||||||
current_version = 15
|
current_version = 15
|
||||||
|
if current_version < 16:
|
||||||
|
_migrate_to_v16(conn)
|
||||||
|
current_version = 16
|
||||||
|
if current_version < 17:
|
||||||
|
_migrate_to_v17(conn)
|
||||||
|
current_version = 17
|
||||||
|
if current_version < 18:
|
||||||
|
_migrate_to_v18(conn)
|
||||||
|
current_version = 18
|
||||||
|
|
||||||
if current_version != int(target_version):
|
if current_version != int(target_version):
|
||||||
set_current_version(conn, int(target_version))
|
set_current_version(conn, int(target_version))
|
||||||
@@ -95,29 +104,29 @@ def _migrate_to_v1(conn):
|
|||||||
|
|
||||||
if "schedule_weekdays" not in columns:
|
if "schedule_weekdays" not in columns:
|
||||||
cursor.execute('ALTER TABLE system_config ADD COLUMN schedule_weekdays TEXT DEFAULT "1,2,3,4,5,6,7"')
|
cursor.execute('ALTER TABLE system_config ADD COLUMN schedule_weekdays TEXT DEFAULT "1,2,3,4,5,6,7"')
|
||||||
print(" ✓ 添加 schedule_weekdays 字段")
|
print(" [OK] 添加 schedule_weekdays 字段")
|
||||||
|
|
||||||
if "max_screenshot_concurrent" not in columns:
|
if "max_screenshot_concurrent" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN max_screenshot_concurrent INTEGER DEFAULT 3")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN max_screenshot_concurrent INTEGER DEFAULT 3")
|
||||||
print(" ✓ 添加 max_screenshot_concurrent 字段")
|
print(" [OK] 添加 max_screenshot_concurrent 字段")
|
||||||
if "max_concurrent_per_account" not in columns:
|
if "max_concurrent_per_account" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN max_concurrent_per_account INTEGER DEFAULT 1")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN max_concurrent_per_account INTEGER DEFAULT 1")
|
||||||
print(" ✓ 添加 max_concurrent_per_account 字段")
|
print(" [OK] 添加 max_concurrent_per_account 字段")
|
||||||
if "auto_approve_enabled" not in columns:
|
if "auto_approve_enabled" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_enabled INTEGER DEFAULT 0")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_enabled INTEGER DEFAULT 0")
|
||||||
print(" ✓ 添加 auto_approve_enabled 字段")
|
print(" [OK] 添加 auto_approve_enabled 字段")
|
||||||
if "auto_approve_hourly_limit" not in columns:
|
if "auto_approve_hourly_limit" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_hourly_limit INTEGER DEFAULT 10")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_hourly_limit INTEGER DEFAULT 10")
|
||||||
print(" ✓ 添加 auto_approve_hourly_limit 字段")
|
print(" [OK] 添加 auto_approve_hourly_limit 字段")
|
||||||
if "auto_approve_vip_days" not in columns:
|
if "auto_approve_vip_days" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_vip_days INTEGER DEFAULT 7")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_vip_days INTEGER DEFAULT 7")
|
||||||
print(" ✓ 添加 auto_approve_vip_days 字段")
|
print(" [OK] 添加 auto_approve_vip_days 字段")
|
||||||
|
|
||||||
cursor.execute("PRAGMA table_info(task_logs)")
|
cursor.execute("PRAGMA table_info(task_logs)")
|
||||||
columns = [col[1] for col in cursor.fetchall()]
|
columns = [col[1] for col in cursor.fetchall()]
|
||||||
if "duration" not in columns:
|
if "duration" not in columns:
|
||||||
cursor.execute("ALTER TABLE task_logs ADD COLUMN duration INTEGER")
|
cursor.execute("ALTER TABLE task_logs ADD COLUMN duration INTEGER")
|
||||||
print(" ✓ 添加 duration 字段到 task_logs")
|
print(" [OK] 添加 duration 字段到 task_logs")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -131,19 +140,19 @@ def _migrate_to_v2(conn):
|
|||||||
|
|
||||||
if "proxy_enabled" not in columns:
|
if "proxy_enabled" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN proxy_enabled INTEGER DEFAULT 0")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN proxy_enabled INTEGER DEFAULT 0")
|
||||||
print(" ✓ 添加 proxy_enabled 字段")
|
print(" [OK] 添加 proxy_enabled 字段")
|
||||||
|
|
||||||
if "proxy_api_url" not in columns:
|
if "proxy_api_url" not in columns:
|
||||||
cursor.execute('ALTER TABLE system_config ADD COLUMN proxy_api_url TEXT DEFAULT ""')
|
cursor.execute('ALTER TABLE system_config ADD COLUMN proxy_api_url TEXT DEFAULT ""')
|
||||||
print(" ✓ 添加 proxy_api_url 字段")
|
print(" [OK] 添加 proxy_api_url 字段")
|
||||||
|
|
||||||
if "proxy_expire_minutes" not in columns:
|
if "proxy_expire_minutes" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN proxy_expire_minutes INTEGER DEFAULT 3")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN proxy_expire_minutes INTEGER DEFAULT 3")
|
||||||
print(" ✓ 添加 proxy_expire_minutes 字段")
|
print(" [OK] 添加 proxy_expire_minutes 字段")
|
||||||
|
|
||||||
if "enable_screenshot" not in columns:
|
if "enable_screenshot" not in columns:
|
||||||
cursor.execute("ALTER TABLE system_config ADD COLUMN enable_screenshot INTEGER DEFAULT 1")
|
cursor.execute("ALTER TABLE system_config ADD COLUMN enable_screenshot INTEGER DEFAULT 1")
|
||||||
print(" ✓ 添加 enable_screenshot 字段")
|
print(" [OK] 添加 enable_screenshot 字段")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -157,15 +166,15 @@ def _migrate_to_v3(conn):
|
|||||||
|
|
||||||
if "status" not in columns:
|
if "status" not in columns:
|
||||||
cursor.execute('ALTER TABLE accounts ADD COLUMN status TEXT DEFAULT "active"')
|
cursor.execute('ALTER TABLE accounts ADD COLUMN status TEXT DEFAULT "active"')
|
||||||
print(" ✓ 添加 accounts.status 字段 (账号状态)")
|
print(" [OK] 添加 accounts.status 字段 (账号状态)")
|
||||||
|
|
||||||
if "login_fail_count" not in columns:
|
if "login_fail_count" not in columns:
|
||||||
cursor.execute("ALTER TABLE accounts ADD COLUMN login_fail_count INTEGER DEFAULT 0")
|
cursor.execute("ALTER TABLE accounts ADD COLUMN login_fail_count INTEGER DEFAULT 0")
|
||||||
print(" ✓ 添加 accounts.login_fail_count 字段 (登录失败计数)")
|
print(" [OK] 添加 accounts.login_fail_count 字段 (登录失败计数)")
|
||||||
|
|
||||||
if "last_login_error" not in columns:
|
if "last_login_error" not in columns:
|
||||||
cursor.execute("ALTER TABLE accounts ADD COLUMN last_login_error TEXT")
|
cursor.execute("ALTER TABLE accounts ADD COLUMN last_login_error TEXT")
|
||||||
print(" ✓ 添加 accounts.last_login_error 字段 (最后登录错误)")
|
print(" [OK] 添加 accounts.last_login_error 字段 (最后登录错误)")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -179,7 +188,7 @@ def _migrate_to_v4(conn):
|
|||||||
|
|
||||||
if "source" not in columns:
|
if "source" not in columns:
|
||||||
cursor.execute('ALTER TABLE task_logs ADD COLUMN source TEXT DEFAULT "manual"')
|
cursor.execute('ALTER TABLE task_logs ADD COLUMN source TEXT DEFAULT "manual"')
|
||||||
print(" ✓ 添加 task_logs.source 字段 (任务来源: manual/scheduled/immediate)")
|
print(" [OK] 添加 task_logs.source 字段 (任务来源: manual/scheduled/immediate)")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -210,7 +219,7 @@ def _migrate_to_v5(conn):
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
print(" ✓ 创建 user_schedules 表 (用户定时任务)")
|
print(" [OK] 创建 user_schedules 表 (用户定时任务)")
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
@@ -234,12 +243,12 @@ def _migrate_to_v5(conn):
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
print(" ✓ 创建 schedule_execution_logs 表 (定时任务执行日志)")
|
print(" [OK] 创建 schedule_execution_logs 表 (定时任务执行日志)")
|
||||||
|
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_user_id ON user_schedules(user_id)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_user_id ON user_schedules(user_id)")
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_enabled ON user_schedules(enabled)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_enabled ON user_schedules(enabled)")
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_next_run ON user_schedules(next_run_at)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_next_run ON user_schedules(next_run_at)")
|
||||||
print(" ✓ 创建 user_schedules 表索引")
|
print(" [OK] 创建 user_schedules 表索引")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -262,10 +271,10 @@ def _migrate_to_v6(conn):
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
print(" ✓ 创建 announcements 表 (公告)")
|
print(" [OK] 创建 announcements 表 (公告)")
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcements_active ON announcements(is_active)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcements_active ON announcements(is_active)")
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcements_created_at ON announcements(created_at)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcements_created_at ON announcements(created_at)")
|
||||||
print(" ✓ 创建 announcements 表索引")
|
print(" [OK] 创建 announcements 表索引")
|
||||||
|
|
||||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='announcement_dismissals'")
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='announcement_dismissals'")
|
||||||
if not cursor.fetchone():
|
if not cursor.fetchone():
|
||||||
@@ -281,9 +290,9 @@ def _migrate_to_v6(conn):
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
print(" ✓ 创建 announcement_dismissals 表 (公告永久关闭记录)")
|
print(" [OK] 创建 announcement_dismissals 表 (公告永久关闭记录)")
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcement_dismissals_user ON announcement_dismissals(user_id)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcement_dismissals_user ON announcement_dismissals(user_id)")
|
||||||
print(" ✓ 创建 announcement_dismissals 表索引")
|
print(" [OK] 创建 announcement_dismissals 表索引")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@@ -342,7 +351,7 @@ def _migrate_to_v7(conn):
|
|||||||
shift_utc_to_cst(table, col)
|
shift_utc_to_cst(table, col)
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
print(" ✓ 时区迁移:历史UTC时间已转换为北京时间")
|
print(" [OK] 时区迁移:历史UTC时间已转换为北京时间")
|
||||||
|
|
||||||
|
|
||||||
def _migrate_to_v8(conn):
|
def _migrate_to_v8(conn):
|
||||||
@@ -354,11 +363,11 @@ def _migrate_to_v8(conn):
|
|||||||
columns = [col[1] for col in cursor.fetchall()]
|
columns = [col[1] for col in cursor.fetchall()]
|
||||||
if "random_delay" not in columns:
|
if "random_delay" not in columns:
|
||||||
cursor.execute("ALTER TABLE user_schedules ADD COLUMN random_delay INTEGER DEFAULT 0")
|
cursor.execute("ALTER TABLE user_schedules ADD COLUMN random_delay INTEGER DEFAULT 0")
|
||||||
print(" ✓ 添加 user_schedules.random_delay 字段")
|
print(" [OK] 添加 user_schedules.random_delay 字段")
|
||||||
|
|
||||||
if "next_run_at" not in columns:
|
if "next_run_at" not in columns:
|
||||||
cursor.execute("ALTER TABLE user_schedules ADD COLUMN next_run_at TIMESTAMP")
|
cursor.execute("ALTER TABLE user_schedules ADD COLUMN next_run_at TIMESTAMP")
|
||||||
print(" ✓ 添加 user_schedules.next_run_at 字段")
|
print(" [OK] 添加 user_schedules.next_run_at 字段")
|
||||||
|
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_next_run ON user_schedules(next_run_at)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_next_run ON user_schedules(next_run_at)")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@@ -411,7 +420,7 @@ def _migrate_to_v8(conn):
|
|||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
if fixed:
|
if fixed:
|
||||||
print(f" ✓ 已为 {fixed} 条启用定时任务补算 next_run_at")
|
print(f" [OK] 已为 {fixed} 条启用定时任务补算 next_run_at")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 迁移过程中不阻断主流程;上线后由 worker 兜底补算
|
# 迁移过程中不阻断主流程;上线后由 worker 兜底补算
|
||||||
print(f" ⚠ v8 迁移补算 next_run_at 失败: {e}")
|
print(f" ⚠ v8 迁移补算 next_run_at 失败: {e}")
|
||||||
@@ -432,15 +441,15 @@ def _migrate_to_v9(conn):
|
|||||||
changed = False
|
changed = False
|
||||||
if "register_verify_enabled" not in columns:
|
if "register_verify_enabled" not in columns:
|
||||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN register_verify_enabled INTEGER DEFAULT 0")
|
cursor.execute("ALTER TABLE email_settings ADD COLUMN register_verify_enabled INTEGER DEFAULT 0")
|
||||||
print(" ✓ 添加 email_settings.register_verify_enabled 字段")
|
print(" [OK] 添加 email_settings.register_verify_enabled 字段")
|
||||||
changed = True
|
changed = True
|
||||||
if "base_url" not in columns:
|
if "base_url" not in columns:
|
||||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN base_url TEXT DEFAULT ''")
|
cursor.execute("ALTER TABLE email_settings ADD COLUMN base_url TEXT DEFAULT ''")
|
||||||
print(" ✓ 添加 email_settings.base_url 字段")
|
print(" [OK] 添加 email_settings.base_url 字段")
|
||||||
changed = True
|
changed = True
|
||||||
if "task_notify_enabled" not in columns:
|
if "task_notify_enabled" not in columns:
|
||||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN task_notify_enabled INTEGER DEFAULT 0")
|
cursor.execute("ALTER TABLE email_settings ADD COLUMN task_notify_enabled INTEGER DEFAULT 0")
|
||||||
print(" ✓ 添加 email_settings.task_notify_enabled 字段")
|
print(" [OK] 添加 email_settings.task_notify_enabled 字段")
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
@@ -456,11 +465,11 @@ def _migrate_to_v10(conn):
|
|||||||
changed = False
|
changed = False
|
||||||
if "email_verified" not in columns:
|
if "email_verified" not in columns:
|
||||||
cursor.execute("ALTER TABLE users ADD COLUMN email_verified INTEGER DEFAULT 0")
|
cursor.execute("ALTER TABLE users ADD COLUMN email_verified INTEGER DEFAULT 0")
|
||||||
print(" ✓ 添加 users.email_verified 字段")
|
print(" [OK] 添加 users.email_verified 字段")
|
||||||
changed = True
|
changed = True
|
||||||
if "email_notify_enabled" not in columns:
|
if "email_notify_enabled" not in columns:
|
||||||
cursor.execute("ALTER TABLE users ADD COLUMN email_notify_enabled INTEGER DEFAULT 1")
|
cursor.execute("ALTER TABLE users ADD COLUMN email_notify_enabled INTEGER DEFAULT 1")
|
||||||
print(" ✓ 添加 users.email_notify_enabled 字段")
|
print(" [OK] 添加 users.email_notify_enabled 字段")
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
@@ -486,7 +495,7 @@ def _migrate_to_v11(conn):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
if updated:
|
if updated:
|
||||||
print(f" ✓ 已将 {updated} 个 pending 用户迁移为 approved")
|
print(f" [OK] 已将 {updated} 个 pending 用户迁移为 approved")
|
||||||
except sqlite3.OperationalError as e:
|
except sqlite3.OperationalError as e:
|
||||||
print(f" ⚠️ v11 迁移跳过: {e}")
|
print(f" ⚠️ v11 迁移跳过: {e}")
|
||||||
|
|
||||||
@@ -659,7 +668,7 @@ def _migrate_to_v15(conn):
|
|||||||
changed = False
|
changed = False
|
||||||
if "login_alert_enabled" not in columns:
|
if "login_alert_enabled" not in columns:
|
||||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN login_alert_enabled INTEGER DEFAULT 1")
|
cursor.execute("ALTER TABLE email_settings ADD COLUMN login_alert_enabled INTEGER DEFAULT 1")
|
||||||
print(" ✓ 添加 email_settings.login_alert_enabled 字段")
|
print(" [OK] 添加 email_settings.login_alert_enabled 字段")
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -672,3 +681,71 @@ def _migrate_to_v15(conn):
|
|||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def _migrate_to_v16(conn):
|
||||||
|
"""迁移到版本16 - 公告支持图片字段"""
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("PRAGMA table_info(announcements)")
|
||||||
|
columns = [col[1] for col in cursor.fetchall()]
|
||||||
|
|
||||||
|
if "image_url" not in columns:
|
||||||
|
cursor.execute("ALTER TABLE announcements ADD COLUMN image_url TEXT")
|
||||||
|
conn.commit()
|
||||||
|
print(" [OK] 添加 announcements.image_url 字段")
|
||||||
|
|
||||||
|
|
||||||
|
def _migrate_to_v17(conn):
|
||||||
|
"""迁移到版本17 - 金山文档上传配置与用户开关"""
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("PRAGMA table_info(system_config)")
|
||||||
|
columns = [col[1] for col in cursor.fetchall()]
|
||||||
|
|
||||||
|
system_fields = [
|
||||||
|
("kdocs_enabled", "INTEGER DEFAULT 0"),
|
||||||
|
("kdocs_doc_url", "TEXT DEFAULT ''"),
|
||||||
|
("kdocs_default_unit", "TEXT DEFAULT ''"),
|
||||||
|
("kdocs_sheet_name", "TEXT DEFAULT ''"),
|
||||||
|
("kdocs_sheet_index", "INTEGER DEFAULT 0"),
|
||||||
|
("kdocs_unit_column", "TEXT DEFAULT 'A'"),
|
||||||
|
("kdocs_image_column", "TEXT DEFAULT 'D'"),
|
||||||
|
("kdocs_admin_notify_enabled", "INTEGER DEFAULT 0"),
|
||||||
|
("kdocs_admin_notify_email", "TEXT DEFAULT ''"),
|
||||||
|
]
|
||||||
|
for field, ddl in system_fields:
|
||||||
|
if field not in columns:
|
||||||
|
cursor.execute(f"ALTER TABLE system_config ADD COLUMN {field} {ddl}")
|
||||||
|
print(f" [OK] 添加 system_config.{field} 字段")
|
||||||
|
|
||||||
|
cursor.execute("PRAGMA table_info(users)")
|
||||||
|
columns = [col[1] for col in cursor.fetchall()]
|
||||||
|
|
||||||
|
user_fields = [
|
||||||
|
("kdocs_unit", "TEXT DEFAULT ''"),
|
||||||
|
("kdocs_auto_upload", "INTEGER DEFAULT 0"),
|
||||||
|
]
|
||||||
|
for field, ddl in user_fields:
|
||||||
|
if field not in columns:
|
||||||
|
cursor.execute(f"ALTER TABLE users ADD COLUMN {field} {ddl}")
|
||||||
|
print(f" [OK] 添加 users.{field} 字段")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def _migrate_to_v18(conn):
|
||||||
|
"""迁移到版本18 - 金山文档上传:有效行范围配置"""
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("PRAGMA table_info(system_config)")
|
||||||
|
columns = [col[1] for col in cursor.fetchall()]
|
||||||
|
|
||||||
|
if "kdocs_row_start" not in columns:
|
||||||
|
cursor.execute("ALTER TABLE system_config ADD COLUMN kdocs_row_start INTEGER DEFAULT 0")
|
||||||
|
print(" [OK] 添加 system_config.kdocs_row_start 字段")
|
||||||
|
|
||||||
|
if "kdocs_row_end" not in columns:
|
||||||
|
cursor.execute("ALTER TABLE system_config ADD COLUMN kdocs_row_end INTEGER DEFAULT 0")
|
||||||
|
print(" [OK] 添加 system_config.kdocs_row_end 字段")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|||||||
14
db/schema.py
14
db/schema.py
@@ -33,6 +33,8 @@ def ensure_schema(conn) -> None:
|
|||||||
email TEXT,
|
email TEXT,
|
||||||
email_verified INTEGER DEFAULT 0,
|
email_verified INTEGER DEFAULT 0,
|
||||||
email_notify_enabled INTEGER DEFAULT 1,
|
email_notify_enabled INTEGER DEFAULT 1,
|
||||||
|
kdocs_unit TEXT DEFAULT '',
|
||||||
|
kdocs_auto_upload INTEGER DEFAULT 0,
|
||||||
status TEXT DEFAULT 'approved',
|
status TEXT DEFAULT 'approved',
|
||||||
vip_expire_time TIMESTAMP,
|
vip_expire_time TIMESTAMP,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
@@ -213,6 +215,17 @@ def ensure_schema(conn) -> None:
|
|||||||
auto_approve_enabled INTEGER DEFAULT 0,
|
auto_approve_enabled INTEGER DEFAULT 0,
|
||||||
auto_approve_hourly_limit INTEGER DEFAULT 10,
|
auto_approve_hourly_limit INTEGER DEFAULT 10,
|
||||||
auto_approve_vip_days INTEGER DEFAULT 7,
|
auto_approve_vip_days INTEGER DEFAULT 7,
|
||||||
|
kdocs_enabled INTEGER DEFAULT 0,
|
||||||
|
kdocs_doc_url TEXT DEFAULT '',
|
||||||
|
kdocs_default_unit TEXT DEFAULT '',
|
||||||
|
kdocs_sheet_name TEXT DEFAULT '',
|
||||||
|
kdocs_sheet_index INTEGER DEFAULT 0,
|
||||||
|
kdocs_unit_column TEXT DEFAULT 'A',
|
||||||
|
kdocs_image_column TEXT DEFAULT 'D',
|
||||||
|
kdocs_admin_notify_enabled INTEGER DEFAULT 0,
|
||||||
|
kdocs_admin_notify_email TEXT DEFAULT '',
|
||||||
|
kdocs_row_start INTEGER DEFAULT 0,
|
||||||
|
kdocs_row_end INTEGER DEFAULT 0,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
@@ -276,6 +289,7 @@ def ensure_schema(conn) -> None:
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
content TEXT NOT NULL,
|
content TEXT NOT NULL,
|
||||||
|
image_url TEXT,
|
||||||
is_active INTEGER DEFAULT 1,
|
is_active INTEGER DEFAULT 1,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
|||||||
33
db/users.py
33
db/users.py
@@ -217,6 +217,39 @@ def get_user_by_id(user_id):
|
|||||||
return dict(user) if user else None
|
return dict(user) if user else None
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_kdocs_settings(user_id):
|
||||||
|
"""获取用户的金山文档配置"""
|
||||||
|
user = get_user_by_id(user_id)
|
||||||
|
if not user:
|
||||||
|
return None
|
||||||
|
return {
|
||||||
|
"kdocs_unit": user.get("kdocs_unit") or "",
|
||||||
|
"kdocs_auto_upload": 1 if user.get("kdocs_auto_upload") else 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def update_user_kdocs_settings(user_id, *, kdocs_unit=None, kdocs_auto_upload=None) -> bool:
|
||||||
|
"""更新用户的金山文档配置"""
|
||||||
|
updates = []
|
||||||
|
params = []
|
||||||
|
if kdocs_unit is not None:
|
||||||
|
updates.append("kdocs_unit = ?")
|
||||||
|
params.append(kdocs_unit)
|
||||||
|
if kdocs_auto_upload is not None:
|
||||||
|
updates.append("kdocs_auto_upload = ?")
|
||||||
|
params.append(kdocs_auto_upload)
|
||||||
|
|
||||||
|
if not updates:
|
||||||
|
return False
|
||||||
|
|
||||||
|
params.append(user_id)
|
||||||
|
with db_pool.get_db() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(f"UPDATE users SET {', '.join(updates)} WHERE id = ?", params)
|
||||||
|
conn.commit()
|
||||||
|
return cursor.rowcount > 0
|
||||||
|
|
||||||
|
|
||||||
def get_user_by_username(username):
|
def get_user_by_username(username):
|
||||||
"""根据用户名获取用户"""
|
"""根据用户名获取用户"""
|
||||||
with db_pool.get_db() as conn:
|
with db_pool.get_db() as conn:
|
||||||
|
|||||||
33
db_pool.py
33
db_pool.py
@@ -45,9 +45,9 @@ class ConnectionPool:
|
|||||||
conn = sqlite3.connect(self.database, check_same_thread=False)
|
conn = sqlite3.connect(self.database, check_same_thread=False)
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
# 设置WAL模式提高并发性能
|
# 设置WAL模式提高并发性能
|
||||||
conn.execute('PRAGMA journal_mode=WAL')
|
conn.execute("PRAGMA journal_mode=WAL")
|
||||||
# 设置合理的超时时间
|
# 设置合理的超时时间
|
||||||
conn.execute('PRAGMA busy_timeout=5000')
|
conn.execute("PRAGMA busy_timeout=5000")
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
@@ -109,17 +109,26 @@ class ConnectionPool:
|
|||||||
with self._lock:
|
with self._lock:
|
||||||
# 双重检查:确保池确实需要补充
|
# 双重检查:确保池确实需要补充
|
||||||
if self._pool.qsize() < self.pool_size:
|
if self._pool.qsize() < self.pool_size:
|
||||||
|
new_conn = None
|
||||||
try:
|
try:
|
||||||
new_conn = self._create_connection()
|
new_conn = self._create_connection()
|
||||||
self._created_connections += 1
|
|
||||||
self._pool.put(new_conn, block=False)
|
self._pool.put(new_conn, block=False)
|
||||||
|
# 只有成功放入池后才增加计数
|
||||||
|
self._created_connections += 1
|
||||||
except Full:
|
except Full:
|
||||||
# 在获取锁期间池被填满了,关闭新建的连接
|
# 在获取锁期间池被填满了,关闭新建的连接
|
||||||
try:
|
if new_conn:
|
||||||
new_conn.close()
|
try:
|
||||||
except Exception:
|
new_conn.close()
|
||||||
pass
|
except Exception:
|
||||||
|
pass
|
||||||
except Exception as create_error:
|
except Exception as create_error:
|
||||||
|
# 创建连接失败,确保关闭已创建的连接
|
||||||
|
if new_conn:
|
||||||
|
try:
|
||||||
|
new_conn.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
print(f"重建连接失败: {create_error}")
|
print(f"重建连接失败: {create_error}")
|
||||||
|
|
||||||
def close_all(self):
|
def close_all(self):
|
||||||
@@ -134,10 +143,10 @@ class ConnectionPool:
|
|||||||
def get_stats(self):
|
def get_stats(self):
|
||||||
"""获取连接池统计信息"""
|
"""获取连接池统计信息"""
|
||||||
return {
|
return {
|
||||||
'pool_size': self.pool_size,
|
"pool_size": self.pool_size,
|
||||||
'available': self._pool.qsize(),
|
"available": self._pool.qsize(),
|
||||||
'in_use': self.pool_size - self._pool.qsize(),
|
"in_use": self.pool_size - self._pool.qsize(),
|
||||||
'total_created': self._created_connections
|
"total_created": self._created_connections,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -245,7 +254,7 @@ def init_pool(database, pool_size=5):
|
|||||||
with _pool_lock:
|
with _pool_lock:
|
||||||
if _pool is None:
|
if _pool is None:
|
||||||
_pool = ConnectionPool(database, pool_size)
|
_pool = ConnectionPool(database, pool_size)
|
||||||
print(f"✓ 数据库连接池已初始化 (大小: {pool_size})")
|
print(f"[OK] 数据库连接池已初始化 (大小: {pool_size})")
|
||||||
|
|
||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ services:
|
|||||||
- ./data:/app/data # 数据库持久化
|
- ./data:/app/data # 数据库持久化
|
||||||
- ./logs:/app/logs # 日志持久化
|
- ./logs:/app/logs # 日志持久化
|
||||||
- ./截图:/app/截图 # 截图持久化
|
- ./截图:/app/截图 # 截图持久化
|
||||||
- ./playwright:/ms-playwright # Playwright浏览器持久化(避免重复下载)
|
|
||||||
- /etc/localtime:/etc/localtime:ro # 时区同步
|
- /etc/localtime:/etc/localtime:ro # 时区同步
|
||||||
- ./static:/app/static # 静态文件(实时更新)
|
- ./static:/app/static # 静态文件(实时更新)
|
||||||
- ./templates:/app/templates # 模板文件(实时更新)
|
- ./templates:/app/templates # 模板文件(实时更新)
|
||||||
- ./app.py:/app/app.py # 主程序(实时更新)
|
- ./app.py:/app/app.py # 主程序(实时更新)
|
||||||
- ./database.py:/app/database.py # 数据库模块(实时更新)
|
- ./database.py:/app/database.py # 数据库模块(实时更新)
|
||||||
|
- ./crypto_utils.py:/app/crypto_utils.py # 加密工具(实时更新)
|
||||||
dns:
|
dns:
|
||||||
- 223.5.5.5
|
- 223.5.5.5
|
||||||
- 114.114.114.114
|
- 114.114.114.114
|
||||||
@@ -23,8 +23,6 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- TZ=Asia/Shanghai
|
- TZ=Asia/Shanghai
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
- PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
|
||||||
- PLAYWRIGHT_DOWNLOAD_HOST=https://npmmirror.com/mirrors/playwright
|
|
||||||
# Flask 配置
|
# Flask 配置
|
||||||
- FLASK_ENV=production
|
- FLASK_ENV=production
|
||||||
- FLASK_DEBUG=false
|
- FLASK_DEBUG=false
|
||||||
@@ -34,11 +32,14 @@ services:
|
|||||||
# 数据库配置
|
# 数据库配置
|
||||||
- DB_FILE=data/app_data.db
|
- DB_FILE=data/app_data.db
|
||||||
- DB_POOL_SIZE=5
|
- DB_POOL_SIZE=5
|
||||||
|
- SYSTEM_CONFIG_CACHE_TTL_SECONDS=30
|
||||||
# 并发控制配置
|
# 并发控制配置
|
||||||
- MAX_CONCURRENT_GLOBAL=2
|
- MAX_CONCURRENT_GLOBAL=2
|
||||||
- MAX_CONCURRENT_PER_ACCOUNT=1
|
- MAX_CONCURRENT_PER_ACCOUNT=1
|
||||||
- MAX_CONCURRENT_CONTEXTS=100
|
- MAX_CONCURRENT_CONTEXTS=100
|
||||||
# 安全配置
|
# 安全配置
|
||||||
|
# 加密密钥配置(重要!防止容器重建时丢失密钥)
|
||||||
|
- ENCRYPTION_KEY_RAW=${ENCRYPTION_KEY_RAW}
|
||||||
- SESSION_LIFETIME_HOURS=24
|
- SESSION_LIFETIME_HOURS=24
|
||||||
- SESSION_COOKIE_SECURE=false
|
- SESSION_COOKIE_SECURE=false
|
||||||
- MAX_CAPTCHA_ATTEMPTS=5
|
- MAX_CAPTCHA_ATTEMPTS=5
|
||||||
@@ -48,6 +49,10 @@ services:
|
|||||||
- LOG_FILE=logs/app.log
|
- LOG_FILE=logs/app.log
|
||||||
- API_DIAGNOSTIC_LOG=0
|
- API_DIAGNOSTIC_LOG=0
|
||||||
- API_DIAGNOSTIC_SLOW_MS=0
|
- API_DIAGNOSTIC_SLOW_MS=0
|
||||||
|
# 状态推送节流(秒)
|
||||||
|
- STATUS_PUSH_INTERVAL_SECONDS=2
|
||||||
|
# wkhtmltoimage 截图配置
|
||||||
|
- WKHTMLTOIMAGE_FULL_PAGE=0
|
||||||
# 知识管理平台配置
|
# 知识管理平台配置
|
||||||
- ZSGL_LOGIN_URL=https://postoa.aidunsoft.com/admin/login.aspx
|
- ZSGL_LOGIN_URL=https://postoa.aidunsoft.com/admin/login.aspx
|
||||||
- ZSGL_INDEX_URL_PATTERN=index.aspx
|
- ZSGL_INDEX_URL_PATTERN=index.aspx
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ flask==3.0.0
|
|||||||
flask-socketio==5.3.5
|
flask-socketio==5.3.5
|
||||||
flask-login==0.6.3
|
flask-login==0.6.3
|
||||||
python-socketio==5.10.0
|
python-socketio==5.10.0
|
||||||
playwright==1.40.0
|
|
||||||
schedule==1.2.0
|
schedule==1.2.0
|
||||||
psutil==5.9.6
|
psutil==5.9.6
|
||||||
pytz==2024.1
|
pytz==2024.1
|
||||||
@@ -10,6 +9,6 @@ bcrypt==4.0.1
|
|||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
python-dotenv==1.0.0
|
python-dotenv==1.0.0
|
||||||
beautifulsoup4==4.12.2
|
beautifulsoup4==4.12.2
|
||||||
nest_asyncio
|
|
||||||
cryptography>=41.0.0
|
cryptography>=41.0.0
|
||||||
Pillow>=10.0.0
|
Pillow>=10.0.0
|
||||||
|
playwright==1.42.0
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ admin_api_bp = Blueprint("admin_api", __name__, url_prefix="/yuyx/api")
|
|||||||
|
|
||||||
# Import side effects: register routes on blueprint
|
# Import side effects: register routes on blueprint
|
||||||
from routes.admin_api import core as _core # noqa: F401
|
from routes.admin_api import core as _core # noqa: F401
|
||||||
from routes.admin_api import update as _update # noqa: F401
|
|
||||||
|
|
||||||
# Export security blueprint for app registration
|
# Export security blueprint for app registration
|
||||||
from routes.admin_api.security import security_bp # noqa: F401
|
from routes.admin_api.security import security_bp # noqa: F401
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import posixpath
|
||||||
|
import secrets
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -15,7 +17,9 @@ from app_logger import get_logger
|
|||||||
from app_security import (
|
from app_security import (
|
||||||
get_rate_limit_ip,
|
get_rate_limit_ip,
|
||||||
is_safe_outbound_url,
|
is_safe_outbound_url,
|
||||||
|
is_safe_path,
|
||||||
require_ip_not_locked,
|
require_ip_not_locked,
|
||||||
|
sanitize_filename,
|
||||||
validate_email,
|
validate_email,
|
||||||
validate_password,
|
validate_password,
|
||||||
)
|
)
|
||||||
@@ -48,6 +52,36 @@ from services.time_utils import BEIJING_TZ, get_beijing_now
|
|||||||
logger = get_logger("app")
|
logger = get_logger("app")
|
||||||
config = get_config()
|
config = get_config()
|
||||||
|
|
||||||
|
_server_cpu_percent_lock = threading.Lock()
|
||||||
|
_server_cpu_percent_last: float | None = None
|
||||||
|
_server_cpu_percent_last_ts = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
def _get_server_cpu_percent() -> float:
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
global _server_cpu_percent_last, _server_cpu_percent_last_ts
|
||||||
|
|
||||||
|
now = time.time()
|
||||||
|
with _server_cpu_percent_lock:
|
||||||
|
if _server_cpu_percent_last is not None and (now - _server_cpu_percent_last_ts) < 0.5:
|
||||||
|
return _server_cpu_percent_last
|
||||||
|
|
||||||
|
try:
|
||||||
|
if _server_cpu_percent_last is None:
|
||||||
|
cpu_percent = float(psutil.cpu_percent(interval=0.1))
|
||||||
|
else:
|
||||||
|
cpu_percent = float(psutil.cpu_percent(interval=None))
|
||||||
|
except Exception:
|
||||||
|
cpu_percent = float(_server_cpu_percent_last or 0.0)
|
||||||
|
|
||||||
|
if cpu_percent < 0:
|
||||||
|
cpu_percent = 0.0
|
||||||
|
|
||||||
|
_server_cpu_percent_last = cpu_percent
|
||||||
|
_server_cpu_percent_last_ts = now
|
||||||
|
return cpu_percent
|
||||||
|
|
||||||
|
|
||||||
def _admin_reauth_required() -> bool:
|
def _admin_reauth_required() -> bool:
|
||||||
try:
|
try:
|
||||||
@@ -61,6 +95,24 @@ def _require_admin_reauth():
|
|||||||
return jsonify({"error": "需要二次确认", "code": "reauth_required"}), 401
|
return jsonify({"error": "需要二次确认", "code": "reauth_required"}), 401
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _get_upload_dir():
|
||||||
|
rel_dir = getattr(config, "ANNOUNCEMENT_IMAGE_DIR", "static/announcements")
|
||||||
|
if not is_safe_path(current_app.root_path, rel_dir):
|
||||||
|
rel_dir = "static/announcements"
|
||||||
|
abs_dir = os.path.join(current_app.root_path, rel_dir)
|
||||||
|
os.makedirs(abs_dir, exist_ok=True)
|
||||||
|
return abs_dir, rel_dir
|
||||||
|
|
||||||
|
|
||||||
|
def _get_file_size(file_storage):
|
||||||
|
try:
|
||||||
|
file_storage.stream.seek(0, os.SEEK_END)
|
||||||
|
size = file_storage.stream.tell()
|
||||||
|
file_storage.stream.seek(0)
|
||||||
|
return size
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/debug-config", methods=["GET"])
|
@admin_api_bp.route("/debug-config", methods=["GET"])
|
||||||
@admin_required
|
@admin_required
|
||||||
@@ -199,6 +251,42 @@ def admin_reauth():
|
|||||||
# ==================== 公告管理API(管理员) ====================
|
# ==================== 公告管理API(管理员) ====================
|
||||||
|
|
||||||
|
|
||||||
|
@admin_api_bp.route("/announcements/upload_image", methods=["POST"])
|
||||||
|
@admin_required
|
||||||
|
def admin_upload_announcement_image():
|
||||||
|
"""上传公告图片(返回可访问URL)"""
|
||||||
|
file = request.files.get("file")
|
||||||
|
if not file or not file.filename:
|
||||||
|
return jsonify({"error": "请选择图片"}), 400
|
||||||
|
|
||||||
|
filename = sanitize_filename(file.filename)
|
||||||
|
ext = os.path.splitext(filename)[1].lower()
|
||||||
|
allowed_exts = getattr(config, "ALLOWED_ANNOUNCEMENT_IMAGE_EXTENSIONS", {".png", ".jpg", ".jpeg"})
|
||||||
|
if not ext or ext not in allowed_exts:
|
||||||
|
return jsonify({"error": "不支持的图片格式"}), 400
|
||||||
|
if file.mimetype and not str(file.mimetype).startswith("image/"):
|
||||||
|
return jsonify({"error": "文件类型无效"}), 400
|
||||||
|
|
||||||
|
size = _get_file_size(file)
|
||||||
|
max_size = int(getattr(config, "MAX_ANNOUNCEMENT_IMAGE_SIZE", 5 * 1024 * 1024))
|
||||||
|
if size is not None and size > max_size:
|
||||||
|
max_mb = max_size // 1024 // 1024
|
||||||
|
return jsonify({"error": f"图片大小不能超过{max_mb}MB"}), 400
|
||||||
|
|
||||||
|
abs_dir, rel_dir = _get_upload_dir()
|
||||||
|
token = secrets.token_hex(6)
|
||||||
|
name = f"announcement_{int(time.time())}_{token}{ext}"
|
||||||
|
save_path = os.path.join(abs_dir, name)
|
||||||
|
file.save(save_path)
|
||||||
|
|
||||||
|
static_root = os.path.join(current_app.root_path, "static")
|
||||||
|
rel_to_static = os.path.relpath(abs_dir, static_root)
|
||||||
|
if rel_to_static.startswith(".."):
|
||||||
|
rel_to_static = "announcements"
|
||||||
|
url_path = posixpath.join(rel_to_static.replace(os.sep, "/"), name)
|
||||||
|
return jsonify({"success": True, "url": url_for("serve_static", filename=url_path)})
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/announcements", methods=["GET"])
|
@admin_api_bp.route("/announcements", methods=["GET"])
|
||||||
@admin_required
|
@admin_required
|
||||||
def admin_get_announcements():
|
def admin_get_announcements():
|
||||||
@@ -221,9 +309,13 @@ def admin_create_announcement():
|
|||||||
data = request.json or {}
|
data = request.json or {}
|
||||||
title = (data.get("title") or "").strip()
|
title = (data.get("title") or "").strip()
|
||||||
content = (data.get("content") or "").strip()
|
content = (data.get("content") or "").strip()
|
||||||
|
image_url = (data.get("image_url") or "").strip()
|
||||||
is_active = bool(data.get("is_active", True))
|
is_active = bool(data.get("is_active", True))
|
||||||
|
|
||||||
announcement_id = database.create_announcement(title, content, is_active=is_active)
|
if image_url and len(image_url) > 1000:
|
||||||
|
return jsonify({"error": "图片地址过长"}), 400
|
||||||
|
|
||||||
|
announcement_id = database.create_announcement(title, content, image_url=image_url, is_active=is_active)
|
||||||
if not announcement_id:
|
if not announcement_id:
|
||||||
return jsonify({"error": "标题和内容不能为空"}), 400
|
return jsonify({"error": "标题和内容不能为空"}), 400
|
||||||
|
|
||||||
@@ -317,6 +409,71 @@ def get_system_stats():
|
|||||||
return jsonify(stats)
|
return jsonify(stats)
|
||||||
|
|
||||||
|
|
||||||
|
@admin_api_bp.route("/browser_pool/stats", methods=["GET"])
|
||||||
|
@admin_required
|
||||||
|
def get_browser_pool_stats():
|
||||||
|
"""获取截图线程池状态"""
|
||||||
|
try:
|
||||||
|
from browser_pool_worker import get_browser_worker_pool
|
||||||
|
|
||||||
|
pool = get_browser_worker_pool()
|
||||||
|
stats = pool.get_stats() or {}
|
||||||
|
|
||||||
|
worker_details = []
|
||||||
|
for w in stats.get("workers") or []:
|
||||||
|
last_ts = float(w.get("last_active_ts") or 0)
|
||||||
|
last_active_at = None
|
||||||
|
if last_ts > 0:
|
||||||
|
try:
|
||||||
|
last_active_at = datetime.fromtimestamp(last_ts, tz=BEIJING_TZ).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
except Exception:
|
||||||
|
last_active_at = None
|
||||||
|
|
||||||
|
created_ts = w.get("browser_created_at")
|
||||||
|
created_at = None
|
||||||
|
if created_ts:
|
||||||
|
try:
|
||||||
|
created_at = datetime.fromtimestamp(float(created_ts), tz=BEIJING_TZ).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
except Exception:
|
||||||
|
created_at = None
|
||||||
|
|
||||||
|
worker_details.append(
|
||||||
|
{
|
||||||
|
"worker_id": w.get("worker_id"),
|
||||||
|
"idle": bool(w.get("idle")),
|
||||||
|
"has_browser": bool(w.get("has_browser")),
|
||||||
|
"total_tasks": int(w.get("total_tasks") or 0),
|
||||||
|
"failed_tasks": int(w.get("failed_tasks") or 0),
|
||||||
|
"browser_use_count": int(w.get("browser_use_count") or 0),
|
||||||
|
"browser_created_at": created_at,
|
||||||
|
"browser_created_ts": created_ts,
|
||||||
|
"last_active_at": last_active_at,
|
||||||
|
"last_active_ts": last_ts,
|
||||||
|
"thread_alive": bool(w.get("thread_alive")),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
total_workers = len(worker_details) if worker_details else int(stats.get("pool_size") or 0)
|
||||||
|
return jsonify(
|
||||||
|
{
|
||||||
|
"total_workers": total_workers,
|
||||||
|
"active_workers": int(stats.get("busy_workers") or 0),
|
||||||
|
"idle_workers": int(stats.get("idle_workers") or 0),
|
||||||
|
"queue_size": int(stats.get("queue_size") or 0),
|
||||||
|
"workers": worker_details,
|
||||||
|
"summary": {
|
||||||
|
"total_tasks": int(stats.get("total_tasks") or 0),
|
||||||
|
"failed_tasks": int(stats.get("failed_tasks") or 0),
|
||||||
|
"success_rate": stats.get("success_rate"),
|
||||||
|
},
|
||||||
|
"server_time_cst": get_beijing_now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(f"[AdminAPI] 获取截图线程池状态失败: {e}")
|
||||||
|
return jsonify({"error": "获取截图线程池状态失败"}), 500
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/docker_stats", methods=["GET"])
|
@admin_api_bp.route("/docker_stats", methods=["GET"])
|
||||||
@admin_required
|
@admin_required
|
||||||
def get_docker_stats():
|
def get_docker_stats():
|
||||||
@@ -413,10 +570,34 @@ def get_docker_stats():
|
|||||||
logger.debug(f"读取CPU信息失败: {e}")
|
logger.debug(f"读取CPU信息失败: {e}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = subprocess.check_output(["uptime", "-p"]).decode("utf-8").strip()
|
# 读取系统运行时间
|
||||||
docker_status["uptime"] = result.replace("up ", "")
|
with open('/proc/uptime', 'r') as f:
|
||||||
|
system_uptime = float(f.read().split()[0])
|
||||||
|
|
||||||
|
# 读取 PID 1 的启动时间 (jiffies)
|
||||||
|
with open('/proc/1/stat', 'r') as f:
|
||||||
|
stat = f.read().split()
|
||||||
|
starttime_jiffies = int(stat[21])
|
||||||
|
|
||||||
|
# 获取 CLK_TCK (通常是 100)
|
||||||
|
clk_tck = os.sysconf(os.sysconf_names['SC_CLK_TCK'])
|
||||||
|
|
||||||
|
# 计算容器运行时长(秒)
|
||||||
|
container_uptime_seconds = system_uptime - (starttime_jiffies / clk_tck)
|
||||||
|
|
||||||
|
# 格式化为可读字符串
|
||||||
|
days = int(container_uptime_seconds // 86400)
|
||||||
|
hours = int((container_uptime_seconds % 86400) // 3600)
|
||||||
|
minutes = int((container_uptime_seconds % 3600) // 60)
|
||||||
|
|
||||||
|
if days > 0:
|
||||||
|
docker_status["uptime"] = f"{days}天{hours}小时{minutes}分钟"
|
||||||
|
elif hours > 0:
|
||||||
|
docker_status["uptime"] = f"{hours}小时{minutes}分钟"
|
||||||
|
else:
|
||||||
|
docker_status["uptime"] = f"{minutes}分钟"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"获取运行时间失败: {e}")
|
logger.debug(f"获取容器运行时间失败: {e}")
|
||||||
|
|
||||||
docker_status["status"] = "Running"
|
docker_status["status"] = "Running"
|
||||||
|
|
||||||
@@ -510,9 +691,21 @@ def update_system_config_api():
|
|||||||
schedule_weekdays = data.get("schedule_weekdays")
|
schedule_weekdays = data.get("schedule_weekdays")
|
||||||
new_max_concurrent_per_account = data.get("max_concurrent_per_account")
|
new_max_concurrent_per_account = data.get("max_concurrent_per_account")
|
||||||
new_max_screenshot_concurrent = data.get("max_screenshot_concurrent")
|
new_max_screenshot_concurrent = data.get("max_screenshot_concurrent")
|
||||||
|
enable_screenshot = data.get("enable_screenshot")
|
||||||
auto_approve_enabled = data.get("auto_approve_enabled")
|
auto_approve_enabled = data.get("auto_approve_enabled")
|
||||||
auto_approve_hourly_limit = data.get("auto_approve_hourly_limit")
|
auto_approve_hourly_limit = data.get("auto_approve_hourly_limit")
|
||||||
auto_approve_vip_days = data.get("auto_approve_vip_days")
|
auto_approve_vip_days = data.get("auto_approve_vip_days")
|
||||||
|
kdocs_enabled = data.get("kdocs_enabled")
|
||||||
|
kdocs_doc_url = data.get("kdocs_doc_url")
|
||||||
|
kdocs_default_unit = data.get("kdocs_default_unit")
|
||||||
|
kdocs_sheet_name = data.get("kdocs_sheet_name")
|
||||||
|
kdocs_sheet_index = data.get("kdocs_sheet_index")
|
||||||
|
kdocs_unit_column = data.get("kdocs_unit_column")
|
||||||
|
kdocs_image_column = data.get("kdocs_image_column")
|
||||||
|
kdocs_admin_notify_enabled = data.get("kdocs_admin_notify_enabled")
|
||||||
|
kdocs_admin_notify_email = data.get("kdocs_admin_notify_email")
|
||||||
|
kdocs_row_start = data.get("kdocs_row_start")
|
||||||
|
kdocs_row_end = data.get("kdocs_row_end")
|
||||||
|
|
||||||
if max_concurrent is not None:
|
if max_concurrent is not None:
|
||||||
if not isinstance(max_concurrent, int) or max_concurrent < 1:
|
if not isinstance(max_concurrent, int) or max_concurrent < 1:
|
||||||
@@ -524,7 +717,13 @@ def update_system_config_api():
|
|||||||
|
|
||||||
if new_max_screenshot_concurrent is not None:
|
if new_max_screenshot_concurrent is not None:
|
||||||
if not isinstance(new_max_screenshot_concurrent, int) or new_max_screenshot_concurrent < 1:
|
if not isinstance(new_max_screenshot_concurrent, int) or new_max_screenshot_concurrent < 1:
|
||||||
return jsonify({"error": "截图并发数必须大于0(建议根据服务器配置设置,每个浏览器约占用200MB内存)"}), 400
|
return jsonify({"error": "截图并发数必须大于0(建议根据服务器配置设置,wkhtmltoimage 资源占用较低)"}), 400
|
||||||
|
|
||||||
|
if enable_screenshot is not None:
|
||||||
|
if isinstance(enable_screenshot, bool):
|
||||||
|
enable_screenshot = 1 if enable_screenshot else 0
|
||||||
|
if enable_screenshot not in (0, 1):
|
||||||
|
return jsonify({"error": "截图开关必须是0或1"}), 400
|
||||||
|
|
||||||
if schedule_time is not None:
|
if schedule_time is not None:
|
||||||
import re
|
import re
|
||||||
@@ -554,6 +753,82 @@ def update_system_config_api():
|
|||||||
if not isinstance(auto_approve_vip_days, int) or auto_approve_vip_days < 0:
|
if not isinstance(auto_approve_vip_days, int) or auto_approve_vip_days < 0:
|
||||||
return jsonify({"error": "注册赠送VIP天数不能为负数"}), 400
|
return jsonify({"error": "注册赠送VIP天数不能为负数"}), 400
|
||||||
|
|
||||||
|
if kdocs_enabled is not None:
|
||||||
|
if isinstance(kdocs_enabled, bool):
|
||||||
|
kdocs_enabled = 1 if kdocs_enabled else 0
|
||||||
|
if kdocs_enabled not in (0, 1):
|
||||||
|
return jsonify({"error": "表格上传开关必须是0或1"}), 400
|
||||||
|
|
||||||
|
if kdocs_doc_url is not None:
|
||||||
|
kdocs_doc_url = str(kdocs_doc_url or "").strip()
|
||||||
|
if kdocs_doc_url and not is_safe_outbound_url(kdocs_doc_url):
|
||||||
|
return jsonify({"error": "文档链接格式不正确"}), 400
|
||||||
|
|
||||||
|
if kdocs_default_unit is not None:
|
||||||
|
kdocs_default_unit = str(kdocs_default_unit or "").strip()
|
||||||
|
if len(kdocs_default_unit) > 50:
|
||||||
|
return jsonify({"error": "默认县区长度不能超过50"}), 400
|
||||||
|
|
||||||
|
if kdocs_sheet_name is not None:
|
||||||
|
kdocs_sheet_name = str(kdocs_sheet_name or "").strip()
|
||||||
|
if len(kdocs_sheet_name) > 50:
|
||||||
|
return jsonify({"error": "Sheet名称长度不能超过50"}), 400
|
||||||
|
|
||||||
|
if kdocs_sheet_index is not None:
|
||||||
|
try:
|
||||||
|
kdocs_sheet_index = int(kdocs_sheet_index)
|
||||||
|
except Exception:
|
||||||
|
return jsonify({"error": "Sheet序号必须是数字"}), 400
|
||||||
|
if kdocs_sheet_index < 0:
|
||||||
|
return jsonify({"error": "Sheet序号不能为负数"}), 400
|
||||||
|
|
||||||
|
if kdocs_unit_column is not None:
|
||||||
|
kdocs_unit_column = str(kdocs_unit_column or "").strip().upper()
|
||||||
|
if not kdocs_unit_column:
|
||||||
|
return jsonify({"error": "县区列不能为空"}), 400
|
||||||
|
import re
|
||||||
|
|
||||||
|
if not re.match(r"^[A-Z]{1,3}$", kdocs_unit_column):
|
||||||
|
return jsonify({"error": "县区列格式错误"}), 400
|
||||||
|
|
||||||
|
if kdocs_image_column is not None:
|
||||||
|
kdocs_image_column = str(kdocs_image_column or "").strip().upper()
|
||||||
|
if not kdocs_image_column:
|
||||||
|
return jsonify({"error": "图片列不能为空"}), 400
|
||||||
|
import re
|
||||||
|
|
||||||
|
if not re.match(r"^[A-Z]{1,3}$", kdocs_image_column):
|
||||||
|
return jsonify({"error": "图片列格式错误"}), 400
|
||||||
|
|
||||||
|
if kdocs_admin_notify_enabled is not None:
|
||||||
|
if isinstance(kdocs_admin_notify_enabled, bool):
|
||||||
|
kdocs_admin_notify_enabled = 1 if kdocs_admin_notify_enabled else 0
|
||||||
|
if kdocs_admin_notify_enabled not in (0, 1):
|
||||||
|
return jsonify({"error": "管理员通知开关必须是0或1"}), 400
|
||||||
|
|
||||||
|
if kdocs_admin_notify_email is not None:
|
||||||
|
kdocs_admin_notify_email = str(kdocs_admin_notify_email or "").strip()
|
||||||
|
if kdocs_admin_notify_email:
|
||||||
|
is_valid, error_msg = validate_email(kdocs_admin_notify_email)
|
||||||
|
if not is_valid:
|
||||||
|
return jsonify({"error": error_msg}), 400
|
||||||
|
|
||||||
|
if kdocs_row_start is not None:
|
||||||
|
try:
|
||||||
|
kdocs_row_start = int(kdocs_row_start)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return jsonify({"error": "起始行必须是数字"}), 400
|
||||||
|
if kdocs_row_start < 0:
|
||||||
|
return jsonify({"error": "起始行不能为负数"}), 400
|
||||||
|
|
||||||
|
if kdocs_row_end is not None:
|
||||||
|
try:
|
||||||
|
kdocs_row_end = int(kdocs_row_end)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return jsonify({"error": "结束行必须是数字"}), 400
|
||||||
|
if kdocs_row_end < 0:
|
||||||
|
return jsonify({"error": "结束行不能为负数"}), 400
|
||||||
|
|
||||||
old_config = database.get_system_config() or {}
|
old_config = database.get_system_config() or {}
|
||||||
|
|
||||||
if not database.update_system_config(
|
if not database.update_system_config(
|
||||||
@@ -564,9 +839,21 @@ def update_system_config_api():
|
|||||||
schedule_weekdays=schedule_weekdays,
|
schedule_weekdays=schedule_weekdays,
|
||||||
max_concurrent_per_account=new_max_concurrent_per_account,
|
max_concurrent_per_account=new_max_concurrent_per_account,
|
||||||
max_screenshot_concurrent=new_max_screenshot_concurrent,
|
max_screenshot_concurrent=new_max_screenshot_concurrent,
|
||||||
|
enable_screenshot=enable_screenshot,
|
||||||
auto_approve_enabled=auto_approve_enabled,
|
auto_approve_enabled=auto_approve_enabled,
|
||||||
auto_approve_hourly_limit=auto_approve_hourly_limit,
|
auto_approve_hourly_limit=auto_approve_hourly_limit,
|
||||||
auto_approve_vip_days=auto_approve_vip_days,
|
auto_approve_vip_days=auto_approve_vip_days,
|
||||||
|
kdocs_enabled=kdocs_enabled,
|
||||||
|
kdocs_doc_url=kdocs_doc_url,
|
||||||
|
kdocs_default_unit=kdocs_default_unit,
|
||||||
|
kdocs_sheet_name=kdocs_sheet_name,
|
||||||
|
kdocs_sheet_index=kdocs_sheet_index,
|
||||||
|
kdocs_unit_column=kdocs_unit_column,
|
||||||
|
kdocs_image_column=kdocs_image_column,
|
||||||
|
kdocs_admin_notify_enabled=kdocs_admin_notify_enabled,
|
||||||
|
kdocs_admin_notify_email=kdocs_admin_notify_email,
|
||||||
|
kdocs_row_start=kdocs_row_start,
|
||||||
|
kdocs_row_end=kdocs_row_end,
|
||||||
):
|
):
|
||||||
return jsonify({"error": "更新失败"}), 400
|
return jsonify({"error": "更新失败"}), 400
|
||||||
|
|
||||||
@@ -577,6 +864,14 @@ def update_system_config_api():
|
|||||||
max_global=int(new_config.get("max_concurrent_global", old_config.get("max_concurrent_global", 2))),
|
max_global=int(new_config.get("max_concurrent_global", old_config.get("max_concurrent_global", 2))),
|
||||||
max_per_user=int(new_config.get("max_concurrent_per_account", old_config.get("max_concurrent_per_account", 1))),
|
max_per_user=int(new_config.get("max_concurrent_per_account", old_config.get("max_concurrent_per_account", 1))),
|
||||||
)
|
)
|
||||||
|
if new_max_screenshot_concurrent is not None:
|
||||||
|
try:
|
||||||
|
from browser_pool_worker import resize_browser_worker_pool
|
||||||
|
|
||||||
|
if resize_browser_worker_pool(int(new_config.get("max_screenshot_concurrent", new_max_screenshot_concurrent))):
|
||||||
|
logger.info(f"截图线程池并发已更新为: {new_config.get('max_screenshot_concurrent')}")
|
||||||
|
except Exception as pool_error:
|
||||||
|
logger.warning(f"截图线程池并发更新失败: {pool_error}")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -590,6 +885,70 @@ def update_system_config_api():
|
|||||||
return jsonify({"message": "系统配置已更新"})
|
return jsonify({"message": "系统配置已更新"})
|
||||||
|
|
||||||
|
|
||||||
|
@admin_api_bp.route("/kdocs/status", methods=["GET"])
|
||||||
|
@admin_required
|
||||||
|
def get_kdocs_status_api():
|
||||||
|
"""获取金山文档上传状态"""
|
||||||
|
try:
|
||||||
|
from services.kdocs_uploader import get_kdocs_uploader
|
||||||
|
|
||||||
|
uploader = get_kdocs_uploader()
|
||||||
|
status = uploader.get_status()
|
||||||
|
live = str(request.args.get("live", "")).lower() in ("1", "true", "yes")
|
||||||
|
if live:
|
||||||
|
live_status = uploader.refresh_login_status()
|
||||||
|
if live_status.get("success"):
|
||||||
|
logged_in = bool(live_status.get("logged_in"))
|
||||||
|
status["logged_in"] = logged_in
|
||||||
|
status["last_login_ok"] = logged_in
|
||||||
|
status["login_required"] = not logged_in
|
||||||
|
if live_status.get("error"):
|
||||||
|
status["last_error"] = live_status.get("error")
|
||||||
|
else:
|
||||||
|
status["logged_in"] = True if status.get("last_login_ok") else False if status.get("last_login_ok") is False else None
|
||||||
|
if status.get("last_login_ok") is True and status.get("last_error") == "操作超时":
|
||||||
|
status["last_error"] = None
|
||||||
|
return jsonify(status)
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": f"获取状态失败: {e}"}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@admin_api_bp.route("/kdocs/qr", methods=["POST"])
|
||||||
|
@admin_required
|
||||||
|
def get_kdocs_qr_api():
|
||||||
|
"""获取金山文档登录二维码"""
|
||||||
|
try:
|
||||||
|
from services.kdocs_uploader import get_kdocs_uploader
|
||||||
|
|
||||||
|
uploader = get_kdocs_uploader()
|
||||||
|
data = request.get_json(silent=True) or {}
|
||||||
|
force = bool(data.get("force"))
|
||||||
|
if not force:
|
||||||
|
force = str(request.args.get("force", "")).lower() in ("1", "true", "yes")
|
||||||
|
result = uploader.request_qr(force=force)
|
||||||
|
if not result.get("success"):
|
||||||
|
return jsonify({"error": result.get("error", "获取二维码失败")}), 400
|
||||||
|
return jsonify(result)
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": f"获取二维码失败: {e}"}), 500
|
||||||
|
|
||||||
|
|
||||||
|
@admin_api_bp.route("/kdocs/clear-login", methods=["POST"])
|
||||||
|
@admin_required
|
||||||
|
def clear_kdocs_login_api():
|
||||||
|
"""清除金山文档登录态"""
|
||||||
|
try:
|
||||||
|
from services.kdocs_uploader import get_kdocs_uploader
|
||||||
|
|
||||||
|
uploader = get_kdocs_uploader()
|
||||||
|
result = uploader.clear_login()
|
||||||
|
if not result.get("success"):
|
||||||
|
return jsonify({"error": result.get("error", "清除失败")}), 400
|
||||||
|
return jsonify({"success": True})
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": f"清除失败: {e}"}), 500
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/schedule/execute", methods=["POST"])
|
@admin_api_bp.route("/schedule/execute", methods=["POST"])
|
||||||
@admin_required
|
@admin_required
|
||||||
def execute_schedule_now():
|
def execute_schedule_now():
|
||||||
@@ -673,7 +1032,7 @@ def get_server_info_api():
|
|||||||
"""获取服务器信息"""
|
"""获取服务器信息"""
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
cpu_percent = psutil.cpu_percent(interval=1)
|
cpu_percent = _get_server_cpu_percent()
|
||||||
|
|
||||||
memory = psutil.virtual_memory()
|
memory = psutil.virtual_memory()
|
||||||
memory_total = f"{memory.total / (1024**3):.1f}GB"
|
memory_total = f"{memory.total / (1024**3):.1f}GB"
|
||||||
@@ -776,30 +1135,44 @@ def get_running_tasks_api():
|
|||||||
@admin_required
|
@admin_required
|
||||||
def get_task_logs_api():
|
def get_task_logs_api():
|
||||||
"""获取任务日志列表(支持分页和多种筛选)"""
|
"""获取任务日志列表(支持分页和多种筛选)"""
|
||||||
limit = int(request.args.get("limit", 20))
|
try:
|
||||||
offset = int(request.args.get("offset", 0))
|
limit = int(request.args.get("limit", 20))
|
||||||
|
limit = max(1, min(limit, 200)) # 限制 1-200 条
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
limit = 20
|
||||||
|
|
||||||
|
try:
|
||||||
|
offset = int(request.args.get("offset", 0))
|
||||||
|
offset = max(0, offset)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
offset = 0
|
||||||
|
|
||||||
date_filter = request.args.get("date")
|
date_filter = request.args.get("date")
|
||||||
status_filter = request.args.get("status")
|
status_filter = request.args.get("status")
|
||||||
source_filter = request.args.get("source")
|
source_filter = request.args.get("source")
|
||||||
user_id_filter = request.args.get("user_id")
|
user_id_filter = request.args.get("user_id")
|
||||||
account_filter = request.args.get("account")
|
account_filter = (request.args.get("account") or "").strip()
|
||||||
|
|
||||||
if user_id_filter:
|
if user_id_filter:
|
||||||
try:
|
try:
|
||||||
user_id_filter = int(user_id_filter)
|
user_id_filter = int(user_id_filter)
|
||||||
except ValueError:
|
except (ValueError, TypeError):
|
||||||
user_id_filter = None
|
user_id_filter = None
|
||||||
|
|
||||||
result = database.get_task_logs(
|
try:
|
||||||
limit=limit,
|
result = database.get_task_logs(
|
||||||
offset=offset,
|
limit=limit,
|
||||||
date_filter=date_filter,
|
offset=offset,
|
||||||
status_filter=status_filter,
|
date_filter=date_filter,
|
||||||
source_filter=source_filter,
|
status_filter=status_filter,
|
||||||
user_id_filter=user_id_filter,
|
source_filter=source_filter,
|
||||||
account_filter=account_filter,
|
user_id_filter=user_id_filter,
|
||||||
)
|
account_filter=account_filter if account_filter else None,
|
||||||
return jsonify(result)
|
)
|
||||||
|
return jsonify(result)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取任务日志失败: {e}")
|
||||||
|
return jsonify({"logs": [], "total": 0, "error": "查询失败"})
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/task/logs/clear", methods=["POST"])
|
@admin_api_bp.route("/task/logs/clear", methods=["POST"])
|
||||||
|
|||||||
@@ -295,6 +295,21 @@ def get_ip_risk(ip):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@security_bp.route("/api/admin/security/ip-risk/clear", methods=["POST"])
|
||||||
|
@admin_required
|
||||||
|
def clear_ip_risk():
|
||||||
|
"""清除指定IP的风险分"""
|
||||||
|
data = _parse_json()
|
||||||
|
ip_text = str(data.get("ip") or "").strip()
|
||||||
|
if not ip_text:
|
||||||
|
return jsonify({"error": "ip不能为空"}), 400
|
||||||
|
|
||||||
|
if not scorer.reset_ip_score(ip_text):
|
||||||
|
return jsonify({"error": "清理失败"}), 400
|
||||||
|
|
||||||
|
return jsonify({"success": True, "ip": _truncate(ip_text, 64), "risk_score": 0})
|
||||||
|
|
||||||
|
|
||||||
@security_bp.route("/api/admin/security/user-risk/<int:user_id>", methods=["GET"])
|
@security_bp.route("/api/admin/security/user-risk/<int:user_id>", methods=["GET"])
|
||||||
@admin_required
|
@admin_required
|
||||||
def get_user_risk(user_id):
|
def get_user_risk(user_id):
|
||||||
@@ -331,4 +346,3 @@ def cleanup_expired():
|
|||||||
pool_stats = None
|
pool_stats = None
|
||||||
|
|
||||||
return jsonify({"success": True, "pool_stats": pool_stats})
|
return jsonify({"success": True, "pool_stats": pool_stats})
|
||||||
|
|
||||||
|
|||||||
@@ -1,190 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import os
|
|
||||||
import time
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
from flask import jsonify, request, session
|
|
||||||
|
|
||||||
from routes.admin_api import admin_api_bp
|
|
||||||
from routes.decorators import admin_required
|
|
||||||
from services.time_utils import get_beijing_now
|
|
||||||
from services.update_files import (
|
|
||||||
ensure_update_dirs,
|
|
||||||
get_update_job_log_path,
|
|
||||||
get_update_request_path,
|
|
||||||
get_update_result_path,
|
|
||||||
get_update_status_path,
|
|
||||||
load_json_file,
|
|
||||||
sanitize_job_id,
|
|
||||||
tail_text_file,
|
|
||||||
write_json_atomic,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _request_ip() -> str:
|
|
||||||
try:
|
|
||||||
return request.headers.get("X-Forwarded-For", "").split(",")[0].strip() or request.remote_addr or ""
|
|
||||||
except Exception:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def _make_job_id(prefix: str = "upd") -> str:
|
|
||||||
now_str = get_beijing_now().strftime("%Y%m%d_%H%M%S")
|
|
||||||
rand = uuid.uuid4().hex[:8]
|
|
||||||
return f"{prefix}_{now_str}_{rand}"
|
|
||||||
|
|
||||||
|
|
||||||
def _has_pending_request() -> bool:
|
|
||||||
try:
|
|
||||||
return os.path.exists(get_update_request_path())
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _parse_bool_field(data: dict, key: str) -> bool | None:
|
|
||||||
if not isinstance(data, dict) or key not in data:
|
|
||||||
return None
|
|
||||||
value = data.get(key)
|
|
||||||
if isinstance(value, bool):
|
|
||||||
return value
|
|
||||||
if isinstance(value, int):
|
|
||||||
if value in (0, 1):
|
|
||||||
return bool(value)
|
|
||||||
raise ValueError(f"{key} 必须是 0/1 或 true/false")
|
|
||||||
if isinstance(value, str):
|
|
||||||
text = value.strip().lower()
|
|
||||||
if text in ("1", "true", "yes", "y", "on"):
|
|
||||||
return True
|
|
||||||
if text in ("0", "false", "no", "n", "off", ""):
|
|
||||||
return False
|
|
||||||
raise ValueError(f"{key} 必须是 0/1 或 true/false")
|
|
||||||
if value is None:
|
|
||||||
return None
|
|
||||||
raise ValueError(f"{key} 必须是 0/1 或 true/false")
|
|
||||||
|
|
||||||
|
|
||||||
def _admin_reauth_required() -> bool:
|
|
||||||
try:
|
|
||||||
return time.time() > float(session.get("admin_reauth_until", 0) or 0)
|
|
||||||
except Exception:
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/update/status", methods=["GET"])
|
|
||||||
@admin_required
|
|
||||||
def get_update_status_api():
|
|
||||||
"""读取宿主机 Update-Agent 写入的 update/status.json。"""
|
|
||||||
ensure_update_dirs()
|
|
||||||
status_path = get_update_status_path()
|
|
||||||
data, err = load_json_file(status_path)
|
|
||||||
if err:
|
|
||||||
return jsonify({"ok": False, "error": f"读取 status 失败: {err}", "data": data}), 200
|
|
||||||
if not data:
|
|
||||||
return jsonify({"ok": False, "error": "未发现更新状态(Update-Agent 可能未运行)"}), 200
|
|
||||||
data.setdefault("update_available", False)
|
|
||||||
return jsonify({"ok": True, "data": data}), 200
|
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/update/result", methods=["GET"])
|
|
||||||
@admin_required
|
|
||||||
def get_update_result_api():
|
|
||||||
"""读取 update/result.json(最近一次更新执行结果)。"""
|
|
||||||
ensure_update_dirs()
|
|
||||||
result_path = get_update_result_path()
|
|
||||||
data, err = load_json_file(result_path)
|
|
||||||
if err:
|
|
||||||
return jsonify({"ok": False, "error": f"读取 result 失败: {err}", "data": data}), 200
|
|
||||||
if not data:
|
|
||||||
return jsonify({"ok": True, "data": None}), 200
|
|
||||||
return jsonify({"ok": True, "data": data}), 200
|
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/update/log", methods=["GET"])
|
|
||||||
@admin_required
|
|
||||||
def get_update_log_api():
|
|
||||||
"""读取 update/jobs/<job_id>.log 的末尾内容(用于后台展示进度)。"""
|
|
||||||
ensure_update_dirs()
|
|
||||||
|
|
||||||
job_id = sanitize_job_id(request.args.get("job_id"))
|
|
||||||
if not job_id:
|
|
||||||
# 若未指定,则尝试用 result.json 的 job_id
|
|
||||||
result_data, _ = load_json_file(get_update_result_path())
|
|
||||||
job_id = sanitize_job_id(result_data.get("job_id") if isinstance(result_data, dict) else None)
|
|
||||||
|
|
||||||
if not job_id:
|
|
||||||
return jsonify({"ok": True, "job_id": None, "log": "", "truncated": False}), 200
|
|
||||||
|
|
||||||
max_bytes = request.args.get("max_bytes", "200000")
|
|
||||||
try:
|
|
||||||
max_bytes_i = int(max_bytes)
|
|
||||||
except Exception:
|
|
||||||
max_bytes_i = 200_000
|
|
||||||
max_bytes_i = max(10_000, min(2_000_000, max_bytes_i))
|
|
||||||
|
|
||||||
log_path = get_update_job_log_path(job_id)
|
|
||||||
text, truncated = tail_text_file(log_path, max_bytes=max_bytes_i)
|
|
||||||
return jsonify({"ok": True, "job_id": job_id, "log": text, "truncated": truncated}), 200
|
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/update/check", methods=["POST"])
|
|
||||||
@admin_required
|
|
||||||
def request_update_check_api():
|
|
||||||
"""请求宿主机 Update-Agent 立刻执行一次检查更新。"""
|
|
||||||
ensure_update_dirs()
|
|
||||||
if _has_pending_request():
|
|
||||||
return jsonify({"error": "已有更新请求正在处理中,请稍后再试"}), 409
|
|
||||||
|
|
||||||
job_id = _make_job_id(prefix="chk")
|
|
||||||
payload = {
|
|
||||||
"job_id": job_id,
|
|
||||||
"action": "check",
|
|
||||||
"requested_at": get_beijing_now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
||||||
"requested_by": session.get("admin_username") or "",
|
|
||||||
"requested_ip": _request_ip(),
|
|
||||||
}
|
|
||||||
write_json_atomic(get_update_request_path(), payload)
|
|
||||||
return jsonify({"success": True, "job_id": job_id}), 200
|
|
||||||
|
|
||||||
|
|
||||||
@admin_api_bp.route("/update/run", methods=["POST"])
|
|
||||||
@admin_required
|
|
||||||
def request_update_run_api():
|
|
||||||
"""请求宿主机 Update-Agent 执行一键更新并重启服务。"""
|
|
||||||
ensure_update_dirs()
|
|
||||||
if _admin_reauth_required():
|
|
||||||
return jsonify({"error": "需要二次确认", "code": "reauth_required"}), 401
|
|
||||||
if _has_pending_request():
|
|
||||||
return jsonify({"error": "已有更新请求正在处理中,请稍后再试"}), 409
|
|
||||||
|
|
||||||
data = request.json or {}
|
|
||||||
try:
|
|
||||||
build_no_cache = _parse_bool_field(data, "build_no_cache")
|
|
||||||
if build_no_cache is None:
|
|
||||||
build_no_cache = _parse_bool_field(data, "no_cache")
|
|
||||||
build_pull = _parse_bool_field(data, "build_pull")
|
|
||||||
if build_pull is None:
|
|
||||||
build_pull = _parse_bool_field(data, "pull")
|
|
||||||
except ValueError as e:
|
|
||||||
return jsonify({"error": str(e)}), 400
|
|
||||||
|
|
||||||
job_id = _make_job_id(prefix="upd")
|
|
||||||
payload = {
|
|
||||||
"job_id": job_id,
|
|
||||||
"action": "update",
|
|
||||||
"requested_at": get_beijing_now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
||||||
"requested_by": session.get("admin_username") or "",
|
|
||||||
"requested_ip": _request_ip(),
|
|
||||||
"build_no_cache": bool(build_no_cache) if build_no_cache is not None else False,
|
|
||||||
"build_pull": bool(build_pull) if build_pull is not None else False,
|
|
||||||
}
|
|
||||||
write_json_atomic(get_update_request_path(), payload)
|
|
||||||
return jsonify(
|
|
||||||
{
|
|
||||||
"success": True,
|
|
||||||
"job_id": job_id,
|
|
||||||
"message": "已提交更新请求,服务将重启(页面可能短暂不可用),请等待1-2分钟后刷新",
|
|
||||||
}
|
|
||||||
), 200
|
|
||||||
@@ -11,7 +11,6 @@ from crypto_utils import encrypt_password as encrypt_account_password
|
|||||||
from flask import Blueprint, jsonify, request
|
from flask import Blueprint, jsonify, request
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from services.accounts_service import load_user_accounts
|
from services.accounts_service import load_user_accounts
|
||||||
from services.browser_manager import init_browser_manager_async
|
|
||||||
from services.browse_types import BROWSE_TYPE_SHOULD_READ, normalize_browse_type, validate_browse_type
|
from services.browse_types import BROWSE_TYPE_SHOULD_READ, normalize_browse_type, validate_browse_type
|
||||||
from services.client_log import log_to_client
|
from services.client_log import log_to_client
|
||||||
from services.models import Account
|
from services.models import Account
|
||||||
@@ -230,10 +229,6 @@ def start_account(account_id):
|
|||||||
if not browse_type:
|
if not browse_type:
|
||||||
return jsonify({"error": "浏览类型无效"}), 400
|
return jsonify({"error": "浏览类型无效"}), 400
|
||||||
enable_screenshot = data.get("enable_screenshot", True)
|
enable_screenshot = data.get("enable_screenshot", True)
|
||||||
if enable_screenshot:
|
|
||||||
# 异步初始化浏览器环境,避免首次下载/安装 Chromium 阻塞请求导致“网页无响应”
|
|
||||||
init_browser_manager_async()
|
|
||||||
|
|
||||||
ok, message = submit_account_task(
|
ok, message = submit_account_task(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
account_id=account_id,
|
account_id=account_id,
|
||||||
@@ -308,9 +303,6 @@ def manual_screenshot(account_id):
|
|||||||
|
|
||||||
account.last_browse_type = browse_type
|
account.last_browse_type = browse_type
|
||||||
|
|
||||||
# 异步初始化浏览器环境,避免首次下载/安装 Chromium 阻塞请求
|
|
||||||
init_browser_manager_async()
|
|
||||||
|
|
||||||
threading.Thread(
|
threading.Thread(
|
||||||
target=take_screenshot_for_account,
|
target=take_screenshot_for_account,
|
||||||
args=(user_id, account_id, browse_type, "manual_screenshot"),
|
args=(user_id, account_id, browse_type, "manual_screenshot"),
|
||||||
@@ -336,10 +328,6 @@ def batch_start_accounts():
|
|||||||
if not account_ids:
|
if not account_ids:
|
||||||
return jsonify({"error": "请选择要启动的账号"}), 400
|
return jsonify({"error": "请选择要启动的账号"}), 400
|
||||||
|
|
||||||
if enable_screenshot:
|
|
||||||
# 异步初始化浏览器环境,避免首次下载/安装 Chromium 阻塞请求
|
|
||||||
init_browser_manager_async()
|
|
||||||
|
|
||||||
started = []
|
started = []
|
||||||
failed = []
|
failed = []
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ def get_active_announcement():
|
|||||||
"id": announcement.get("id"),
|
"id": announcement.get("id"),
|
||||||
"title": announcement.get("title", ""),
|
"title": announcement.get("title", ""),
|
||||||
"content": announcement.get("content", ""),
|
"content": announcement.get("content", ""),
|
||||||
|
"image_url": announcement.get("image_url") or "",
|
||||||
"created_at": announcement.get("created_at"),
|
"created_at": announcement.get("created_at"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,6 +148,50 @@ def get_user_email():
|
|||||||
return jsonify({"email": user.get("email", ""), "email_verified": user.get("email_verified", False)})
|
return jsonify({"email": user.get("email", ""), "email_verified": user.get("email_verified", False)})
|
||||||
|
|
||||||
|
|
||||||
|
@api_user_bp.route("/api/user/kdocs", methods=["GET"])
|
||||||
|
@login_required
|
||||||
|
def get_user_kdocs_settings():
|
||||||
|
"""获取当前用户的金山文档设置"""
|
||||||
|
settings = database.get_user_kdocs_settings(current_user.id)
|
||||||
|
if not settings:
|
||||||
|
return jsonify({"kdocs_unit": "", "kdocs_auto_upload": 0})
|
||||||
|
return jsonify(settings)
|
||||||
|
|
||||||
|
|
||||||
|
@api_user_bp.route("/api/user/kdocs", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
def update_user_kdocs_settings():
|
||||||
|
"""更新当前用户的金山文档设置"""
|
||||||
|
data = request.get_json() or {}
|
||||||
|
kdocs_unit = data.get("kdocs_unit")
|
||||||
|
kdocs_auto_upload = data.get("kdocs_auto_upload")
|
||||||
|
|
||||||
|
if kdocs_unit is not None:
|
||||||
|
kdocs_unit = str(kdocs_unit or "").strip()
|
||||||
|
if len(kdocs_unit) > 50:
|
||||||
|
return jsonify({"error": "县区长度不能超过50"}), 400
|
||||||
|
|
||||||
|
if kdocs_auto_upload is not None:
|
||||||
|
if isinstance(kdocs_auto_upload, bool):
|
||||||
|
kdocs_auto_upload = 1 if kdocs_auto_upload else 0
|
||||||
|
try:
|
||||||
|
kdocs_auto_upload = int(kdocs_auto_upload)
|
||||||
|
except Exception:
|
||||||
|
return jsonify({"error": "自动上传开关必须是0或1"}), 400
|
||||||
|
if kdocs_auto_upload not in (0, 1):
|
||||||
|
return jsonify({"error": "自动上传开关必须是0或1"}), 400
|
||||||
|
|
||||||
|
if not database.update_user_kdocs_settings(
|
||||||
|
current_user.id,
|
||||||
|
kdocs_unit=kdocs_unit,
|
||||||
|
kdocs_auto_upload=kdocs_auto_upload,
|
||||||
|
):
|
||||||
|
return jsonify({"error": "更新失败"}), 400
|
||||||
|
|
||||||
|
settings = database.get_user_kdocs_settings(current_user.id) or {"kdocs_unit": "", "kdocs_auto_upload": 0}
|
||||||
|
return jsonify({"success": True, "settings": settings})
|
||||||
|
|
||||||
|
|
||||||
@api_user_bp.route("/api/user/bind-email", methods=["POST"])
|
@api_user_bp.route("/api/user/bind-email", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@require_ip_not_locked
|
@require_ip_not_locked
|
||||||
@@ -303,3 +348,37 @@ def get_run_stats():
|
|||||||
"today_attachments": stats.get("total_attachments", 0),
|
"today_attachments": stats.get("total_attachments", 0),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_user_bp.route("/api/kdocs/status", methods=["GET"])
|
||||||
|
@login_required
|
||||||
|
def get_kdocs_status_for_user():
|
||||||
|
"""获取金山文档在线状态(用户端简化版)"""
|
||||||
|
try:
|
||||||
|
# 检查系统是否启用了金山文档功能
|
||||||
|
cfg = database.get_system_config() or {}
|
||||||
|
kdocs_enabled = int(cfg.get("kdocs_enabled") or 0)
|
||||||
|
|
||||||
|
if not kdocs_enabled:
|
||||||
|
return jsonify({"enabled": False, "online": False, "message": "未启用"})
|
||||||
|
|
||||||
|
# 获取金山文档状态
|
||||||
|
from services.kdocs_uploader import get_kdocs_uploader
|
||||||
|
|
||||||
|
kdocs = get_kdocs_uploader()
|
||||||
|
status = kdocs.get_status()
|
||||||
|
|
||||||
|
login_required_flag = status.get("login_required", False)
|
||||||
|
last_login_ok = status.get("last_login_ok")
|
||||||
|
|
||||||
|
# 判断是否在线
|
||||||
|
is_online = not login_required_flag and last_login_ok is True
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"enabled": True,
|
||||||
|
"online": is_online,
|
||||||
|
"message": "就绪" if is_online else "离线"
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"获取金山文档状态失败: {e}")
|
||||||
|
return jsonify({"enabled": False, "online": False, "message": "获取失败"})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from flask import Blueprint, current_app, redirect, render_template, session, url_for
|
from flask import Blueprint, current_app, redirect, render_template, request, session, url_for
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
|
|
||||||
from routes.decorators import admin_required
|
from routes.decorators import admin_required
|
||||||
@@ -36,10 +36,18 @@ def render_app_spa_or_legacy(
|
|||||||
logger.warning(f"[app_spa] manifest缺少入口文件: {manifest_path}")
|
logger.warning(f"[app_spa] manifest缺少入口文件: {manifest_path}")
|
||||||
return render_template(legacy_template_name, **legacy_context)
|
return render_template(legacy_template_name, **legacy_context)
|
||||||
|
|
||||||
|
app_spa_js_file = f"app/{js_file}"
|
||||||
|
app_spa_css_files = [f"app/{p}" for p in css_files]
|
||||||
|
app_spa_build_id = _get_asset_build_id(
|
||||||
|
os.path.join(current_app.root_path, "static"),
|
||||||
|
[app_spa_js_file, *app_spa_css_files],
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"app.html",
|
"app.html",
|
||||||
app_spa_js_file=f"app/{js_file}",
|
app_spa_js_file=app_spa_js_file,
|
||||||
app_spa_css_files=[f"app/{p}" for p in css_files],
|
app_spa_css_files=app_spa_css_files,
|
||||||
|
app_spa_build_id=app_spa_build_id,
|
||||||
app_spa_initial_state=spa_initial_state,
|
app_spa_initial_state=spa_initial_state,
|
||||||
)
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@@ -50,6 +58,27 @@ def render_app_spa_or_legacy(
|
|||||||
return render_template(legacy_template_name, **legacy_context)
|
return render_template(legacy_template_name, **legacy_context)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_asset_build_id(static_root: str, rel_paths: list[str]) -> Optional[str]:
|
||||||
|
mtimes = []
|
||||||
|
for rel_path in rel_paths:
|
||||||
|
if not rel_path:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
mtimes.append(os.path.getmtime(os.path.join(static_root, rel_path)))
|
||||||
|
except OSError:
|
||||||
|
continue
|
||||||
|
if not mtimes:
|
||||||
|
return None
|
||||||
|
return str(int(max(mtimes)))
|
||||||
|
|
||||||
|
|
||||||
|
def _is_legacy_admin_user_agent(user_agent: str) -> bool:
|
||||||
|
if not user_agent:
|
||||||
|
return False
|
||||||
|
ua = user_agent.lower()
|
||||||
|
return "msie" in ua or "trident/" in ua
|
||||||
|
|
||||||
|
|
||||||
@pages_bp.route("/")
|
@pages_bp.route("/")
|
||||||
def index():
|
def index():
|
||||||
"""主页 - 重定向到登录或应用"""
|
"""主页 - 重定向到登录或应用"""
|
||||||
@@ -96,6 +125,8 @@ def admin_login_page():
|
|||||||
@admin_required
|
@admin_required
|
||||||
def admin_page():
|
def admin_page():
|
||||||
"""后台管理页面"""
|
"""后台管理页面"""
|
||||||
|
if request.args.get("legacy") == "1" or _is_legacy_admin_user_agent(request.headers.get("User-Agent", "")):
|
||||||
|
return render_template("admin_legacy.html")
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
manifest_path = os.path.join(current_app.root_path, "static", "admin", ".vite", "manifest.json")
|
manifest_path = os.path.join(current_app.root_path, "static", "admin", ".vite", "manifest.json")
|
||||||
try:
|
try:
|
||||||
@@ -110,10 +141,18 @@ def admin_page():
|
|||||||
logger.warning(f"[admin_spa] manifest缺少入口文件: {manifest_path}")
|
logger.warning(f"[admin_spa] manifest缺少入口文件: {manifest_path}")
|
||||||
return render_template("admin_legacy.html")
|
return render_template("admin_legacy.html")
|
||||||
|
|
||||||
|
admin_spa_js_file = f"admin/{js_file}"
|
||||||
|
admin_spa_css_files = [f"admin/{p}" for p in css_files]
|
||||||
|
admin_spa_build_id = _get_asset_build_id(
|
||||||
|
os.path.join(current_app.root_path, "static"),
|
||||||
|
[admin_spa_js_file, *admin_spa_css_files],
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"admin.html",
|
"admin.html",
|
||||||
admin_spa_js_file=f"admin/{js_file}",
|
admin_spa_js_file=admin_spa_js_file,
|
||||||
admin_spa_css_files=[f"admin/{p}" for p in css_files],
|
admin_spa_css_files=admin_spa_css_files,
|
||||||
|
admin_spa_build_id=admin_spa_build_id,
|
||||||
)
|
)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.warning(f"[admin_spa] 未找到manifest: {manifest_path},回退旧版后台模板")
|
logger.warning(f"[admin_spa] 未找到manifest: {manifest_path},回退旧版后台模板")
|
||||||
|
|||||||
@@ -229,6 +229,33 @@ class RiskScorer:
|
|||||||
self._update_scores(cursor, "", user_id_int, delta, now_str)
|
self._update_scores(cursor, "", user_id_int, delta, now_str)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
def reset_ip_score(self, ip: str) -> bool:
|
||||||
|
"""清零指定IP的风险分"""
|
||||||
|
ip_text = str(ip or "").strip()[:64]
|
||||||
|
if not ip_text:
|
||||||
|
return False
|
||||||
|
|
||||||
|
now_str = get_cst_now_str()
|
||||||
|
with db_pool.get_db() as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT ip FROM ip_risk_scores WHERE ip = ?", (ip_text,))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if row:
|
||||||
|
cursor.execute(
|
||||||
|
"UPDATE ip_risk_scores SET risk_score = 0, last_seen = ?, updated_at = ? WHERE ip = ?",
|
||||||
|
(now_str, now_str, ip_text),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO ip_risk_scores (ip, risk_score, last_seen, created_at, updated_at)
|
||||||
|
VALUES (?, 0, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(ip_text, now_str, now_str, now_str),
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
def _update_scores(
|
def _update_scores(
|
||||||
self,
|
self,
|
||||||
cursor,
|
cursor,
|
||||||
|
|||||||
@@ -1,112 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from app_logger import get_logger
|
|
||||||
from browser_installer import check_and_install_browser
|
|
||||||
from playwright_automation import PlaywrightBrowserManager
|
|
||||||
|
|
||||||
logger = get_logger("browser_manager")
|
|
||||||
|
|
||||||
_browser_manager: Optional[PlaywrightBrowserManager] = None
|
|
||||||
_lock = threading.Lock()
|
|
||||||
_cond = threading.Condition(_lock)
|
|
||||||
_init_in_progress = False
|
|
||||||
_init_error: Optional[str] = None
|
|
||||||
_init_thread: Optional[threading.Thread] = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_browser_manager() -> Optional[PlaywrightBrowserManager]:
|
|
||||||
return _browser_manager
|
|
||||||
|
|
||||||
|
|
||||||
def is_browser_manager_ready() -> bool:
|
|
||||||
return _browser_manager is not None
|
|
||||||
|
|
||||||
|
|
||||||
def get_browser_manager_init_error() -> Optional[str]:
|
|
||||||
return _init_error
|
|
||||||
|
|
||||||
|
|
||||||
def init_browser_manager(*, block: bool = True, timeout: Optional[float] = None) -> bool:
|
|
||||||
global _browser_manager
|
|
||||||
global _init_in_progress, _init_error
|
|
||||||
|
|
||||||
deadline = time.monotonic() + float(timeout) if timeout is not None else None
|
|
||||||
|
|
||||||
with _cond:
|
|
||||||
if _browser_manager is not None:
|
|
||||||
return True
|
|
||||||
|
|
||||||
if _init_in_progress:
|
|
||||||
if not block:
|
|
||||||
return False
|
|
||||||
while _init_in_progress:
|
|
||||||
if deadline is None:
|
|
||||||
_cond.wait(timeout=0.5)
|
|
||||||
continue
|
|
||||||
remaining = deadline - time.monotonic()
|
|
||||||
if remaining <= 0:
|
|
||||||
break
|
|
||||||
_cond.wait(timeout=min(0.5, remaining))
|
|
||||||
return _browser_manager is not None
|
|
||||||
|
|
||||||
_init_in_progress = True
|
|
||||||
_init_error = None
|
|
||||||
|
|
||||||
ok = False
|
|
||||||
error: Optional[str] = None
|
|
||||||
manager: Optional[PlaywrightBrowserManager] = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
logger.info("正在初始化Playwright浏览器管理器...")
|
|
||||||
if not check_and_install_browser(log_callback=lambda msg, account_id=None: logger.info(str(msg))):
|
|
||||||
error = "浏览器环境检查失败"
|
|
||||||
logger.error("浏览器环境检查失败!")
|
|
||||||
ok = False
|
|
||||||
else:
|
|
||||||
manager = PlaywrightBrowserManager(
|
|
||||||
headless=True,
|
|
||||||
log_callback=lambda msg, account_id=None: logger.info(str(msg)),
|
|
||||||
)
|
|
||||||
ok = True
|
|
||||||
logger.info("Playwright浏览器管理器创建成功!")
|
|
||||||
except Exception as exc:
|
|
||||||
error = f"{type(exc).__name__}: {exc}"
|
|
||||||
logger.exception("初始化Playwright浏览器管理器时发生异常")
|
|
||||||
ok = False
|
|
||||||
|
|
||||||
with _cond:
|
|
||||||
if ok and manager is not None:
|
|
||||||
_browser_manager = manager
|
|
||||||
else:
|
|
||||||
_init_error = error or "初始化失败"
|
|
||||||
_init_in_progress = False
|
|
||||||
_cond.notify_all()
|
|
||||||
|
|
||||||
return ok
|
|
||||||
|
|
||||||
|
|
||||||
def init_browser_manager_async() -> None:
|
|
||||||
"""异步初始化浏览器环境,避免阻塞 Web 请求/服务启动。"""
|
|
||||||
global _init_thread
|
|
||||||
|
|
||||||
def _worker():
|
|
||||||
try:
|
|
||||||
init_browser_manager(block=True)
|
|
||||||
except Exception:
|
|
||||||
logger.exception("异步初始化浏览器管理器失败")
|
|
||||||
|
|
||||||
with _cond:
|
|
||||||
if _browser_manager is not None:
|
|
||||||
return
|
|
||||||
if _init_thread and _init_thread.is_alive():
|
|
||||||
return
|
|
||||||
if _init_in_progress:
|
|
||||||
return
|
|
||||||
_init_thread = threading.Thread(target=_worker, daemon=True, name="browser-manager-init")
|
|
||||||
_init_thread.start()
|
|
||||||
1573
services/kdocs_uploader.py
Normal file
1573
services/kdocs_uploader.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from app_config import get_config
|
from app_config import get_config
|
||||||
from app_logger import get_logger
|
from app_logger import get_logger
|
||||||
@@ -26,6 +27,9 @@ USER_ACCOUNTS_EXPIRE_SECONDS = int(getattr(config, "USER_ACCOUNTS_EXPIRE_SECONDS
|
|||||||
BATCH_TASK_EXPIRE_SECONDS = int(getattr(config, "BATCH_TASK_EXPIRE_SECONDS", 21600))
|
BATCH_TASK_EXPIRE_SECONDS = int(getattr(config, "BATCH_TASK_EXPIRE_SECONDS", 21600))
|
||||||
PENDING_RANDOM_EXPIRE_SECONDS = int(getattr(config, "PENDING_RANDOM_EXPIRE_SECONDS", 7200))
|
PENDING_RANDOM_EXPIRE_SECONDS = int(getattr(config, "PENDING_RANDOM_EXPIRE_SECONDS", 7200))
|
||||||
|
|
||||||
|
# 金山文档离线通知状态:每次掉线只通知一次,恢复在线后重置
|
||||||
|
_kdocs_offline_notified: bool = False
|
||||||
|
|
||||||
|
|
||||||
def cleanup_expired_data() -> None:
|
def cleanup_expired_data() -> None:
|
||||||
"""定期清理过期数据,防止内存泄漏(逻辑保持不变)。"""
|
"""定期清理过期数据,防止内存泄漏(逻辑保持不变)。"""
|
||||||
@@ -91,6 +95,87 @@ def cleanup_expired_data() -> None:
|
|||||||
logger.debug(f"已清理 {deleted_random} 个过期随机延迟任务")
|
logger.debug(f"已清理 {deleted_random} 个过期随机延迟任务")
|
||||||
|
|
||||||
|
|
||||||
|
def check_kdocs_online_status() -> None:
|
||||||
|
"""检测金山文档登录状态,如果离线则发送邮件通知管理员(每次掉线只通知一次)"""
|
||||||
|
global _kdocs_offline_notified
|
||||||
|
|
||||||
|
try:
|
||||||
|
import database
|
||||||
|
from services.kdocs_uploader import get_kdocs_uploader
|
||||||
|
|
||||||
|
# 获取系统配置
|
||||||
|
cfg = database.get_system_config()
|
||||||
|
if not cfg:
|
||||||
|
return
|
||||||
|
|
||||||
|
# 检查是否启用了金山文档功能
|
||||||
|
kdocs_enabled = int(cfg.get("kdocs_enabled") or 0)
|
||||||
|
if not kdocs_enabled:
|
||||||
|
return
|
||||||
|
|
||||||
|
# 检查是否启用了管理员通知
|
||||||
|
admin_notify_enabled = int(cfg.get("kdocs_admin_notify_enabled") or 0)
|
||||||
|
admin_notify_email = (cfg.get("kdocs_admin_notify_email") or "").strip()
|
||||||
|
if not admin_notify_enabled or not admin_notify_email:
|
||||||
|
return
|
||||||
|
|
||||||
|
# 获取金山文档状态
|
||||||
|
kdocs = get_kdocs_uploader()
|
||||||
|
status = kdocs.get_status()
|
||||||
|
login_required = status.get("login_required", False)
|
||||||
|
last_login_ok = status.get("last_login_ok")
|
||||||
|
|
||||||
|
# 如果需要登录或最后登录状态不是成功
|
||||||
|
is_offline = login_required or (last_login_ok is False)
|
||||||
|
|
||||||
|
if is_offline:
|
||||||
|
# 已经通知过了,不再重复通知
|
||||||
|
if _kdocs_offline_notified:
|
||||||
|
logger.debug("[KDocs监控] 金山文档离线,已通知过,跳过重复通知")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 发送邮件通知
|
||||||
|
try:
|
||||||
|
import email_service
|
||||||
|
|
||||||
|
now_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
subject = "【金山文档离线告警】需要重新登录"
|
||||||
|
body = f"""
|
||||||
|
您好,
|
||||||
|
|
||||||
|
系统检测到金山文档上传功能已离线,需要重新扫码登录。
|
||||||
|
|
||||||
|
检测时间:{now_str}
|
||||||
|
状态详情:
|
||||||
|
- 需要登录:{login_required}
|
||||||
|
- 上次登录状态:{last_login_ok}
|
||||||
|
|
||||||
|
请尽快登录后台,在"系统配置"→"金山文档上传"中点击"获取登录二维码"重新登录。
|
||||||
|
|
||||||
|
---
|
||||||
|
此邮件由系统自动发送,请勿直接回复。
|
||||||
|
"""
|
||||||
|
email_service.send_email_async(
|
||||||
|
to_email=admin_notify_email,
|
||||||
|
subject=subject,
|
||||||
|
body=body,
|
||||||
|
email_type="kdocs_offline_alert",
|
||||||
|
)
|
||||||
|
_kdocs_offline_notified = True # 标记为已通知
|
||||||
|
logger.warning(f"[KDocs监控] 金山文档离线,已发送通知邮件到 {admin_notify_email}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[KDocs监控] 发送离线通知邮件失败: {e}")
|
||||||
|
else:
|
||||||
|
# 恢复在线,重置通知状态
|
||||||
|
if _kdocs_offline_notified:
|
||||||
|
logger.info("[KDocs监控] 金山文档已恢复在线,重置通知状态")
|
||||||
|
_kdocs_offline_notified = False
|
||||||
|
logger.debug("[KDocs监控] 金山文档状态正常")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[KDocs监控] 检测失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
def start_cleanup_scheduler() -> None:
|
def start_cleanup_scheduler() -> None:
|
||||||
"""启动定期清理调度器"""
|
"""启动定期清理调度器"""
|
||||||
|
|
||||||
@@ -106,3 +191,22 @@ def start_cleanup_scheduler() -> None:
|
|||||||
cleanup_thread.start()
|
cleanup_thread.start()
|
||||||
logger.info("内存清理调度器已启动")
|
logger.info("内存清理调度器已启动")
|
||||||
|
|
||||||
|
|
||||||
|
def start_kdocs_monitor() -> None:
|
||||||
|
"""启动金山文档状态监控"""
|
||||||
|
|
||||||
|
def monitor_loop():
|
||||||
|
# 启动后等待 60 秒再开始检测(给系统初始化的时间)
|
||||||
|
time.sleep(60)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
check_kdocs_online_status()
|
||||||
|
time.sleep(300) # 每5分钟检测一次
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[KDocs监控] 监控任务执行失败: {e}")
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
|
monitor_thread = threading.Thread(target=monitor_loop, daemon=True, name="kdocs-monitor")
|
||||||
|
monitor_thread.start()
|
||||||
|
logger.info("[KDocs监控] 金山文档状态监控已启动(每5分钟检测一次)")
|
||||||
|
|
||||||
|
|||||||
@@ -87,19 +87,32 @@ def run_scheduled_task(skip_weekday_check: bool = False) -> None:
|
|||||||
cfg = database.get_system_config()
|
cfg = database.get_system_config()
|
||||||
enable_screenshot_scheduled = cfg.get("enable_screenshot", 0) == 1
|
enable_screenshot_scheduled = cfg.get("enable_screenshot", 0) == 1
|
||||||
|
|
||||||
|
user_accounts = {}
|
||||||
|
account_ids = []
|
||||||
for user in approved_users:
|
for user in approved_users:
|
||||||
user_id = user["id"]
|
user_id = user["id"]
|
||||||
accounts = safe_get_user_accounts_snapshot(user_id)
|
accounts = safe_get_user_accounts_snapshot(user_id)
|
||||||
if not accounts:
|
if not accounts:
|
||||||
load_user_accounts(user_id)
|
load_user_accounts(user_id)
|
||||||
accounts = safe_get_user_accounts_snapshot(user_id)
|
accounts = safe_get_user_accounts_snapshot(user_id)
|
||||||
|
if accounts:
|
||||||
|
user_accounts[user_id] = accounts
|
||||||
|
account_ids.extend(list(accounts.keys()))
|
||||||
|
|
||||||
|
account_statuses = database.get_account_status_batch(account_ids)
|
||||||
|
|
||||||
|
for user in approved_users:
|
||||||
|
user_id = user["id"]
|
||||||
|
accounts = user_accounts.get(user_id, {})
|
||||||
|
if not accounts:
|
||||||
|
continue
|
||||||
for account_id, account in accounts.items():
|
for account_id, account in accounts.items():
|
||||||
total_accounts += 1
|
total_accounts += 1
|
||||||
|
|
||||||
if account.is_running:
|
if account.is_running:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
account_status_info = database.get_account_status(account_id)
|
account_status_info = account_statuses.get(str(account_id))
|
||||||
if account_status_info:
|
if account_status_info:
|
||||||
status = account_status_info["status"] if "status" in account_status_info.keys() else "active"
|
status = account_status_info["status"] if "status" in account_status_info.keys() else "active"
|
||||||
if status == "suspended":
|
if status == "suspended":
|
||||||
@@ -150,6 +163,16 @@ def scheduled_task_worker() -> None:
|
|||||||
"""定时任务工作线程"""
|
"""定时任务工作线程"""
|
||||||
import schedule
|
import schedule
|
||||||
|
|
||||||
|
def decay_risk_scores():
|
||||||
|
"""风险分衰减:每天定时执行一次"""
|
||||||
|
try:
|
||||||
|
from security.risk_scorer import RiskScorer
|
||||||
|
|
||||||
|
RiskScorer().decay_scores()
|
||||||
|
logger.info("[定时任务] 风险分衰减已执行")
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(f"[定时任务] 风险分衰减执行失败: {e}")
|
||||||
|
|
||||||
def cleanup_expired_captcha():
|
def cleanup_expired_captcha():
|
||||||
try:
|
try:
|
||||||
deleted_count = safe_cleanup_expired_captcha()
|
deleted_count = safe_cleanup_expired_captcha()
|
||||||
@@ -362,7 +385,12 @@ def scheduled_task_worker() -> None:
|
|||||||
if schedule_time_cst != str(schedule_time_raw or "").strip():
|
if schedule_time_cst != str(schedule_time_raw or "").strip():
|
||||||
logger.warning(f"[定时任务] 系统定时时间格式无效,已回退到 {schedule_time_cst} (原值: {schedule_time_raw!r})")
|
logger.warning(f"[定时任务] 系统定时时间格式无效,已回退到 {schedule_time_cst} (原值: {schedule_time_raw!r})")
|
||||||
|
|
||||||
signature = (schedule_enabled, schedule_time_cst)
|
risk_decay_time_raw = os.environ.get("RISK_SCORE_DECAY_TIME_CST", "04:00")
|
||||||
|
risk_decay_time_cst = _normalize_hhmm(risk_decay_time_raw, default="04:00")
|
||||||
|
if risk_decay_time_cst != str(risk_decay_time_raw or "").strip():
|
||||||
|
logger.warning(f"[定时任务] 风险分衰减时间格式无效,已回退到 {risk_decay_time_cst} (原值: {risk_decay_time_raw!r})")
|
||||||
|
|
||||||
|
signature = (schedule_enabled, schedule_time_cst, risk_decay_time_cst)
|
||||||
config_changed = schedule_state.get("signature") != signature
|
config_changed = schedule_state.get("signature") != signature
|
||||||
is_first_run = schedule_state.get("signature") is None
|
is_first_run = schedule_state.get("signature") is None
|
||||||
if (not force) and (not config_changed):
|
if (not force) and (not config_changed):
|
||||||
@@ -374,6 +402,8 @@ def scheduled_task_worker() -> None:
|
|||||||
cleanup_time_cst = "03:00"
|
cleanup_time_cst = "03:00"
|
||||||
schedule.every().day.at(cleanup_time_cst).do(cleanup_old_data)
|
schedule.every().day.at(cleanup_time_cst).do(cleanup_old_data)
|
||||||
|
|
||||||
|
schedule.every().day.at(risk_decay_time_cst).do(decay_risk_scores)
|
||||||
|
|
||||||
schedule.every().hour.do(cleanup_expired_captcha)
|
schedule.every().hour.do(cleanup_expired_captcha)
|
||||||
|
|
||||||
quota_reset_time_cst = "00:00"
|
quota_reset_time_cst = "00:00"
|
||||||
@@ -381,6 +411,7 @@ def scheduled_task_worker() -> None:
|
|||||||
|
|
||||||
if is_first_run:
|
if is_first_run:
|
||||||
logger.info(f"[定时任务] 已设置数据清理任务: 每天 CST {cleanup_time_cst}")
|
logger.info(f"[定时任务] 已设置数据清理任务: 每天 CST {cleanup_time_cst}")
|
||||||
|
logger.info(f"[定时任务] 已设置风险分衰减: 每天 CST {risk_decay_time_cst}")
|
||||||
logger.info(f"[定时任务] 已设置验证码清理任务: 每小时执行一次")
|
logger.info(f"[定时任务] 已设置验证码清理任务: 每小时执行一次")
|
||||||
logger.info(f"[定时任务] 已设置SMTP配额重置: 每天 CST {quota_reset_time_cst}")
|
logger.info(f"[定时任务] 已设置SMTP配额重置: 每天 CST {quota_reset_time_cst}")
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,16 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import database
|
import database
|
||||||
import email_service
|
import email_service
|
||||||
|
from api_browser import APIBrowser, get_cookie_jar_path, is_cookie_jar_fresh
|
||||||
from app_config import get_config
|
from app_config import get_config
|
||||||
from app_logger import get_logger
|
from app_logger import get_logger
|
||||||
from browser_pool_worker import get_browser_worker_pool
|
from browser_pool_worker import get_browser_worker_pool
|
||||||
from playwright_automation import PlaywrightAutomation
|
|
||||||
from services.browser_manager import get_browser_manager
|
|
||||||
from services.client_log import log_to_client
|
from services.client_log import log_to_client
|
||||||
from services.runtime import get_socketio
|
from services.runtime import get_socketio
|
||||||
from services.state import safe_get_account, safe_remove_task_status, safe_update_task_status
|
from services.state import safe_get_account, safe_remove_task_status, safe_update_task_status
|
||||||
@@ -24,6 +25,165 @@ config = get_config()
|
|||||||
SCREENSHOTS_DIR = config.SCREENSHOTS_DIR
|
SCREENSHOTS_DIR = config.SCREENSHOTS_DIR
|
||||||
os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
|
os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
|
||||||
|
|
||||||
|
_WKHTMLTOIMAGE_TIMEOUT_SECONDS = int(os.environ.get("WKHTMLTOIMAGE_TIMEOUT_SECONDS", "60"))
|
||||||
|
_WKHTMLTOIMAGE_JS_DELAY_MS = int(os.environ.get("WKHTMLTOIMAGE_JS_DELAY_MS", "3000"))
|
||||||
|
_WKHTMLTOIMAGE_WIDTH = int(os.environ.get("WKHTMLTOIMAGE_WIDTH", "1920"))
|
||||||
|
_WKHTMLTOIMAGE_HEIGHT = int(os.environ.get("WKHTMLTOIMAGE_HEIGHT", "1080"))
|
||||||
|
_WKHTMLTOIMAGE_QUALITY = int(os.environ.get("WKHTMLTOIMAGE_QUALITY", "95"))
|
||||||
|
_WKHTMLTOIMAGE_ZOOM = float(os.environ.get("WKHTMLTOIMAGE_ZOOM", "1.0"))
|
||||||
|
_WKHTMLTOIMAGE_FULL_PAGE = str(os.environ.get("WKHTMLTOIMAGE_FULL_PAGE", "")).strip().lower() in (
|
||||||
|
"1",
|
||||||
|
"true",
|
||||||
|
"yes",
|
||||||
|
"on",
|
||||||
|
)
|
||||||
|
_env_crop_w = os.environ.get("WKHTMLTOIMAGE_CROP_WIDTH")
|
||||||
|
_env_crop_h = os.environ.get("WKHTMLTOIMAGE_CROP_HEIGHT")
|
||||||
|
_WKHTMLTOIMAGE_CROP_WIDTH = int(_env_crop_w) if _env_crop_w is not None else _WKHTMLTOIMAGE_WIDTH
|
||||||
|
_WKHTMLTOIMAGE_CROP_HEIGHT = (
|
||||||
|
int(_env_crop_h) if _env_crop_h is not None else (_WKHTMLTOIMAGE_HEIGHT if _WKHTMLTOIMAGE_HEIGHT > 0 else 0)
|
||||||
|
)
|
||||||
|
_WKHTMLTOIMAGE_CROP_X = int(os.environ.get("WKHTMLTOIMAGE_CROP_X", "0"))
|
||||||
|
_WKHTMLTOIMAGE_CROP_Y = int(os.environ.get("WKHTMLTOIMAGE_CROP_Y", "0"))
|
||||||
|
_WKHTMLTOIMAGE_UA = os.environ.get(
|
||||||
|
"WKHTMLTOIMAGE_USER_AGENT",
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_wkhtmltoimage_path() -> str | None:
|
||||||
|
return os.environ.get("WKHTMLTOIMAGE_PATH") or shutil.which("wkhtmltoimage")
|
||||||
|
|
||||||
|
|
||||||
|
def _read_cookie_pairs(cookies_path: str) -> list[tuple[str, str]]:
|
||||||
|
if not cookies_path or not os.path.exists(cookies_path):
|
||||||
|
return []
|
||||||
|
pairs = []
|
||||||
|
try:
|
||||||
|
with open(cookies_path, "r", encoding="utf-8", errors="ignore") as f:
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
if not line or line.startswith("#"):
|
||||||
|
continue
|
||||||
|
parts = line.split("\t")
|
||||||
|
if len(parts) < 7:
|
||||||
|
continue
|
||||||
|
name = parts[5].strip()
|
||||||
|
value = parts[6].strip()
|
||||||
|
if name:
|
||||||
|
pairs.append((name, value))
|
||||||
|
except Exception:
|
||||||
|
return []
|
||||||
|
return pairs
|
||||||
|
|
||||||
|
|
||||||
|
def _select_cookie_pairs(pairs: list[tuple[str, str]]) -> list[tuple[str, str]]:
|
||||||
|
preferred_names = {"ASP.NET_SessionId", ".ASPXAUTH"}
|
||||||
|
preferred = [(name, value) for name, value in pairs if name in preferred_names and value]
|
||||||
|
if preferred:
|
||||||
|
return preferred
|
||||||
|
return [(name, value) for name, value in pairs if name and value and name.isascii() and value.isascii()]
|
||||||
|
|
||||||
|
|
||||||
|
def _ensure_login_cookies(account, proxy_config, log_callback) -> bool:
|
||||||
|
"""确保有可用的登录 cookies(通过 API 登录刷新)"""
|
||||||
|
try:
|
||||||
|
with APIBrowser(log_callback=log_callback, proxy_config=proxy_config) as api_browser:
|
||||||
|
if not api_browser.login(account.username, account.password):
|
||||||
|
return False
|
||||||
|
return api_browser.save_cookies_for_screenshot(account.username)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def take_screenshot_wkhtmltoimage(
|
||||||
|
url: str,
|
||||||
|
output_path: str,
|
||||||
|
cookies_path: str | None = None,
|
||||||
|
proxy_server: str | None = None,
|
||||||
|
run_script: str | None = None,
|
||||||
|
window_status: str | None = None,
|
||||||
|
log_callback=None,
|
||||||
|
) -> bool:
|
||||||
|
wkhtmltoimage_path = _resolve_wkhtmltoimage_path()
|
||||||
|
if not wkhtmltoimage_path:
|
||||||
|
if log_callback:
|
||||||
|
log_callback("wkhtmltoimage 未安装或不在 PATH 中")
|
||||||
|
return False
|
||||||
|
|
||||||
|
ext = os.path.splitext(output_path)[1].lower()
|
||||||
|
image_format = "jpg" if ext in (".jpg", ".jpeg") else "png"
|
||||||
|
|
||||||
|
cmd = [
|
||||||
|
wkhtmltoimage_path,
|
||||||
|
"--format",
|
||||||
|
image_format,
|
||||||
|
"--width",
|
||||||
|
str(_WKHTMLTOIMAGE_WIDTH),
|
||||||
|
"--disable-smart-width",
|
||||||
|
"--javascript-delay",
|
||||||
|
str(_WKHTMLTOIMAGE_JS_DELAY_MS),
|
||||||
|
"--load-error-handling",
|
||||||
|
"ignore",
|
||||||
|
"--enable-local-file-access",
|
||||||
|
"--encoding",
|
||||||
|
"utf-8",
|
||||||
|
]
|
||||||
|
|
||||||
|
if _WKHTMLTOIMAGE_UA:
|
||||||
|
cmd.extend(["--custom-header", "User-Agent", _WKHTMLTOIMAGE_UA, "--custom-header-propagation"])
|
||||||
|
|
||||||
|
if image_format in ("jpg", "jpeg"):
|
||||||
|
cmd.extend(["--quality", str(_WKHTMLTOIMAGE_QUALITY)])
|
||||||
|
|
||||||
|
if _WKHTMLTOIMAGE_HEIGHT > 0 and not _WKHTMLTOIMAGE_FULL_PAGE:
|
||||||
|
cmd.extend(["--height", str(_WKHTMLTOIMAGE_HEIGHT)])
|
||||||
|
|
||||||
|
if abs(_WKHTMLTOIMAGE_ZOOM - 1.0) > 1e-6:
|
||||||
|
cmd.extend(["--zoom", str(_WKHTMLTOIMAGE_ZOOM)])
|
||||||
|
|
||||||
|
if not _WKHTMLTOIMAGE_FULL_PAGE and (_WKHTMLTOIMAGE_CROP_WIDTH > 0 or _WKHTMLTOIMAGE_CROP_HEIGHT > 0):
|
||||||
|
cmd.extend(["--crop-x", str(_WKHTMLTOIMAGE_CROP_X), "--crop-y", str(_WKHTMLTOIMAGE_CROP_Y)])
|
||||||
|
if _WKHTMLTOIMAGE_CROP_WIDTH > 0:
|
||||||
|
cmd.extend(["--crop-w", str(_WKHTMLTOIMAGE_CROP_WIDTH)])
|
||||||
|
if _WKHTMLTOIMAGE_CROP_HEIGHT > 0:
|
||||||
|
cmd.extend(["--crop-h", str(_WKHTMLTOIMAGE_CROP_HEIGHT)])
|
||||||
|
|
||||||
|
if run_script:
|
||||||
|
cmd.extend(["--run-script", run_script])
|
||||||
|
if window_status:
|
||||||
|
cmd.extend(["--window-status", window_status])
|
||||||
|
|
||||||
|
if cookies_path:
|
||||||
|
cookie_pairs = _select_cookie_pairs(_read_cookie_pairs(cookies_path))
|
||||||
|
if cookie_pairs:
|
||||||
|
for name, value in cookie_pairs:
|
||||||
|
cmd.extend(["--cookie", name, value])
|
||||||
|
else:
|
||||||
|
cmd.extend(["--cookie-jar", cookies_path])
|
||||||
|
|
||||||
|
if proxy_server:
|
||||||
|
cmd.extend(["--proxy", proxy_server])
|
||||||
|
|
||||||
|
cmd.extend([url, output_path])
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=_WKHTMLTOIMAGE_TIMEOUT_SECONDS)
|
||||||
|
if result.returncode != 0:
|
||||||
|
if log_callback:
|
||||||
|
err_msg = (result.stderr or result.stdout or "").strip()
|
||||||
|
log_callback(f"wkhtmltoimage 截图失败: {err_msg[:200]}")
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
if log_callback:
|
||||||
|
log_callback("wkhtmltoimage 截图超时")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
if log_callback:
|
||||||
|
log_callback(f"wkhtmltoimage 截图异常: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _emit(event: str, data: object, *, room: str | None = None) -> None:
|
def _emit(event: str, data: object, *, room: str | None = None) -> None:
|
||||||
try:
|
try:
|
||||||
@@ -42,7 +202,7 @@ def take_screenshot_for_account(
|
|||||||
task_start_time=None,
|
task_start_time=None,
|
||||||
browse_result=None,
|
browse_result=None,
|
||||||
):
|
):
|
||||||
"""为账号任务完成后截图(使用工作线程池,真正的浏览器复用)"""
|
"""为账号任务完成后截图(使用截图线程池并发执行)"""
|
||||||
account = safe_get_account(user_id, account_id)
|
account = safe_get_account(user_id, account_id)
|
||||||
if not account:
|
if not account:
|
||||||
return
|
return
|
||||||
@@ -53,7 +213,9 @@ def take_screenshot_for_account(
|
|||||||
# 标记账号正在截图(防止重复提交截图任务)
|
# 标记账号正在截图(防止重复提交截图任务)
|
||||||
account.is_running = True
|
account.is_running = True
|
||||||
|
|
||||||
def screenshot_task(browser_instance, user_id, account_id, account, browse_type, source, task_start_time, browse_result):
|
def screenshot_task(
|
||||||
|
browser_instance, user_id, account_id, account, browse_type, source, task_start_time, browse_result
|
||||||
|
):
|
||||||
"""在worker线程中执行的截图任务"""
|
"""在worker线程中执行的截图任务"""
|
||||||
# ✅ 获得worker后,立即更新状态为"截图中"
|
# ✅ 获得worker后,立即更新状态为"截图中"
|
||||||
acc = safe_get_account(user_id, account_id)
|
acc = safe_get_account(user_id, account_id)
|
||||||
@@ -63,9 +225,11 @@ def take_screenshot_for_account(
|
|||||||
_emit("account_update", acc.to_dict(), room=f"user_{user_id}")
|
_emit("account_update", acc.to_dict(), room=f"user_{user_id}")
|
||||||
|
|
||||||
max_retries = 3
|
max_retries = 3
|
||||||
|
proxy_config = account.proxy_config if hasattr(account, "proxy_config") else None
|
||||||
|
proxy_server = proxy_config.get("server") if proxy_config else None
|
||||||
|
cookie_path = get_cookie_jar_path(account.username)
|
||||||
|
|
||||||
for attempt in range(1, max_retries + 1):
|
for attempt in range(1, max_retries + 1):
|
||||||
automation = None
|
|
||||||
try:
|
try:
|
||||||
safe_update_task_status(
|
safe_update_task_status(
|
||||||
account_id,
|
account_id,
|
||||||
@@ -75,100 +239,79 @@ def take_screenshot_for_account(
|
|||||||
if attempt > 1:
|
if attempt > 1:
|
||||||
log_to_client(f"🔄 第 {attempt} 次截图尝试...", user_id, account_id)
|
log_to_client(f"🔄 第 {attempt} 次截图尝试...", user_id, account_id)
|
||||||
|
|
||||||
|
worker_id = browser_instance.get("worker_id", "?") if isinstance(browser_instance, dict) else "?"
|
||||||
|
use_count = browser_instance.get("use_count", 0) if isinstance(browser_instance, dict) else 0
|
||||||
log_to_client(
|
log_to_client(
|
||||||
f"使用Worker-{browser_instance['worker_id']}的浏览器(已使用{browser_instance['use_count']}次)",
|
f"使用Worker-{worker_id}执行截图(已执行{use_count}次)",
|
||||||
user_id,
|
user_id,
|
||||||
account_id,
|
account_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
proxy_config = account.proxy_config if hasattr(account, "proxy_config") else None
|
|
||||||
automation = PlaywrightAutomation(get_browser_manager(), account_id, proxy_config=proxy_config)
|
|
||||||
automation.playwright = browser_instance["playwright"]
|
|
||||||
automation.browser = browser_instance["browser"]
|
|
||||||
|
|
||||||
def custom_log(message: str):
|
def custom_log(message: str):
|
||||||
log_to_client(message, user_id, account_id)
|
log_to_client(message, user_id, account_id)
|
||||||
|
|
||||||
automation.log = custom_log
|
# 智能登录状态检查:只在必要时才刷新登录
|
||||||
|
should_refresh_login = not is_cookie_jar_fresh(cookie_path)
|
||||||
log_to_client("登录中...", user_id, account_id)
|
if should_refresh_login and attempt > 1:
|
||||||
login_result = automation.quick_login(account.username, account.password, account.remember)
|
# 重试时刷新登录(attempt > 1 表示第2次及以后的尝试)
|
||||||
if not login_result["success"]:
|
log_to_client("正在刷新登录态...", user_id, account_id)
|
||||||
error_message = login_result.get("message", "截图登录失败")
|
if not _ensure_login_cookies(account, proxy_config, custom_log):
|
||||||
log_to_client(f"截图登录失败: {error_message}", user_id, account_id)
|
log_to_client("截图登录失败", user_id, account_id)
|
||||||
if attempt < max_retries:
|
if attempt < max_retries:
|
||||||
log_to_client("将重试...", user_id, account_id)
|
log_to_client("将重试...", user_id, account_id)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
continue
|
continue
|
||||||
log_to_client("❌ 截图失败: 登录失败", user_id, account_id)
|
log_to_client("❌ 截图失败: 登录失败", user_id, account_id)
|
||||||
return {"success": False, "error": "登录失败"}
|
return {"success": False, "error": "登录失败"}
|
||||||
|
elif should_refresh_login:
|
||||||
|
# 首次尝试时快速检查登录状态
|
||||||
|
log_to_client("正在刷新登录态...", user_id, account_id)
|
||||||
|
if not _ensure_login_cookies(account, proxy_config, custom_log):
|
||||||
|
log_to_client("❌ 截图失败: 登录失败", user_id, account_id)
|
||||||
|
return {"success": False, "error": "登录失败"}
|
||||||
|
|
||||||
log_to_client(f"导航到 '{browse_type}' 页面...", user_id, account_id)
|
log_to_client(f"导航到 '{browse_type}' 页面...", user_id, account_id)
|
||||||
|
|
||||||
# 截图场景:优先用 bz 参数直达页面(更稳定,避免页面按钮点击失败导致截图跑偏)
|
from urllib.parse import urlsplit
|
||||||
navigated = False
|
|
||||||
try:
|
|
||||||
from urllib.parse import urlsplit
|
|
||||||
|
|
||||||
parsed = urlsplit(config.ZSGL_LOGIN_URL)
|
parsed = urlsplit(config.ZSGL_LOGIN_URL)
|
||||||
base = f"{parsed.scheme}://{parsed.netloc}"
|
base = f"{parsed.scheme}://{parsed.netloc}"
|
||||||
if "注册前" in str(browse_type):
|
if "注册前" in str(browse_type):
|
||||||
bz = 0
|
bz = 0
|
||||||
else:
|
else:
|
||||||
bz = 2 # 应读
|
bz = 0 # 应读(网站更新后 bz=0 为应读)
|
||||||
target_url = f"{base}/admin/center.aspx?bz={bz}"
|
target_url = f"{base}/admin/center.aspx?bz={bz}"
|
||||||
# 目标:保留外层框架(左侧菜单/顶部栏),仅在 mainframe 内部导航到目标内容页
|
index_url = config.ZSGL_INDEX_URL or f"{base}/admin/index.aspx"
|
||||||
iframe = None
|
run_script = (
|
||||||
try:
|
"(function(){"
|
||||||
iframe = automation.get_iframe_safe(retry=True, max_retries=5)
|
"function done(){window.status='ready';}"
|
||||||
except Exception:
|
"function ensureNav(){try{if(typeof loadMenuTree==='function'){loadMenuTree(true);}}catch(e){}}"
|
||||||
iframe = None
|
"function expandMenu(){"
|
||||||
|
"try{var body=document.body;if(body&&body.classList.contains('lay-mini')){body.classList.remove('lay-mini');}}catch(e){}"
|
||||||
if iframe:
|
"try{if(typeof mainPageResize==='function'){mainPageResize();}}catch(e){}"
|
||||||
iframe.goto(target_url, timeout=60000)
|
"try{if(typeof toggleMainMenu==='function' && document.body && document.body.classList.contains('lay-mini')){toggleMainMenu();}}catch(e){}"
|
||||||
current_url = getattr(iframe, "url", "") or ""
|
"try{var navRight=document.querySelector('.nav-right');if(navRight){navRight.style.display='block';}}catch(e){}"
|
||||||
if "center.aspx" not in current_url:
|
"try{var mainNav=document.getElementById('main-nav');if(mainNav){mainNav.style.display='block';}}catch(e){}"
|
||||||
raise RuntimeError(f"unexpected_iframe_url:{current_url}")
|
"}"
|
||||||
try:
|
"function navReady(){"
|
||||||
iframe.wait_for_load_state("networkidle", timeout=10000)
|
"try{var nav=document.getElementById('sidebar-nav');return nav && nav.querySelectorAll('a').length>0;}catch(e){return false;}"
|
||||||
except Exception:
|
"}"
|
||||||
pass
|
"function frameReady(){"
|
||||||
try:
|
"try{var f=document.getElementById('mainframe');return f && f.contentDocument && f.contentDocument.readyState==='complete';}catch(e){return false;}"
|
||||||
iframe.wait_for_selector("table.ltable", timeout=5000)
|
"}"
|
||||||
except Exception:
|
"function check(){"
|
||||||
pass
|
"if(navReady() && frameReady()){done();return;}"
|
||||||
else:
|
"setTimeout(check,300);"
|
||||||
# 兜底:若获取不到 iframe,则退回到主页面直达
|
"}"
|
||||||
automation.main_page.goto(target_url, timeout=60000)
|
"var f=document.getElementById('mainframe');"
|
||||||
current_url = getattr(automation.main_page, "url", "") or ""
|
"ensureNav();"
|
||||||
if "center.aspx" not in current_url:
|
"expandMenu();"
|
||||||
raise RuntimeError(f"unexpected_url:{current_url}")
|
"if(!f){done();return;}"
|
||||||
try:
|
f"f.src='{target_url}';"
|
||||||
automation.main_page.wait_for_load_state("networkidle", timeout=10000)
|
"f.onload=function(){ensureNav();expandMenu();setTimeout(check,300);};"
|
||||||
except Exception:
|
"setTimeout(check,5000);"
|
||||||
pass
|
"})();"
|
||||||
try:
|
)
|
||||||
automation.main_page.wait_for_selector("table.ltable", timeout=5000)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
navigated = True
|
|
||||||
except Exception as nav_error:
|
|
||||||
log_to_client(f"直达页面失败,将尝试按钮切换: {str(nav_error)[:120]}", user_id, account_id)
|
|
||||||
|
|
||||||
# 兼容兜底:若直达失败,则回退到原有按钮切换方式
|
|
||||||
if not navigated:
|
|
||||||
result = automation.browse_content(
|
|
||||||
navigate_only=True,
|
|
||||||
browse_type=browse_type,
|
|
||||||
auto_next_page=False,
|
|
||||||
auto_view_attachments=False,
|
|
||||||
interval=0,
|
|
||||||
should_stop_callback=None,
|
|
||||||
)
|
|
||||||
if not result.success and result.error_message:
|
|
||||||
log_to_client(f"导航警告: {result.error_message}", user_id, account_id)
|
|
||||||
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
timestamp = get_beijing_now().strftime("%Y%m%d_%H%M%S")
|
timestamp = get_beijing_now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
|
||||||
@@ -178,9 +321,24 @@ def take_screenshot_for_account(
|
|||||||
screenshot_filename = f"{username_prefix}_{login_account}_{browse_type}_{timestamp}.jpg"
|
screenshot_filename = f"{username_prefix}_{login_account}_{browse_type}_{timestamp}.jpg"
|
||||||
screenshot_path = os.path.join(SCREENSHOTS_DIR, screenshot_filename)
|
screenshot_path = os.path.join(SCREENSHOTS_DIR, screenshot_filename)
|
||||||
|
|
||||||
if automation.take_screenshot(screenshot_path):
|
cookies_for_shot = cookie_path if is_cookie_jar_fresh(cookie_path) else None
|
||||||
|
if take_screenshot_wkhtmltoimage(
|
||||||
|
index_url,
|
||||||
|
screenshot_path,
|
||||||
|
cookies_path=cookies_for_shot,
|
||||||
|
proxy_server=proxy_server,
|
||||||
|
run_script=run_script,
|
||||||
|
window_status="ready",
|
||||||
|
log_callback=custom_log,
|
||||||
|
) or take_screenshot_wkhtmltoimage(
|
||||||
|
target_url,
|
||||||
|
screenshot_path,
|
||||||
|
cookies_path=cookies_for_shot,
|
||||||
|
proxy_server=proxy_server,
|
||||||
|
log_callback=custom_log,
|
||||||
|
):
|
||||||
if os.path.exists(screenshot_path) and os.path.getsize(screenshot_path) > 1000:
|
if os.path.exists(screenshot_path) and os.path.getsize(screenshot_path) > 1000:
|
||||||
log_to_client(f"✓ 截图成功: {screenshot_filename}", user_id, account_id)
|
log_to_client(f"[OK] 截图成功: {screenshot_filename}", user_id, account_id)
|
||||||
return {"success": True, "filename": screenshot_filename}
|
return {"success": True, "filename": screenshot_filename}
|
||||||
log_to_client("截图文件异常,将重试", user_id, account_id)
|
log_to_client("截图文件异常,将重试", user_id, account_id)
|
||||||
if os.path.exists(screenshot_path):
|
if os.path.exists(screenshot_path):
|
||||||
@@ -197,15 +355,6 @@ def take_screenshot_for_account(
|
|||||||
if attempt < max_retries:
|
if attempt < max_retries:
|
||||||
log_to_client("将重试...", user_id, account_id)
|
log_to_client("将重试...", user_id, account_id)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
finally:
|
|
||||||
if automation:
|
|
||||||
try:
|
|
||||||
if automation.context:
|
|
||||||
automation.context.close()
|
|
||||||
automation.context = None
|
|
||||||
automation.page = None
|
|
||||||
except Exception as e:
|
|
||||||
logger.debug(f"关闭context时出错: {e}")
|
|
||||||
|
|
||||||
return {"success": False, "error": "截图失败,已重试3次"}
|
return {"success": False, "error": "截图失败,已重试3次"}
|
||||||
|
|
||||||
@@ -250,6 +399,38 @@ def take_screenshot_for_account(
|
|||||||
|
|
||||||
account_name = account.remark if account.remark else account.username
|
account_name = account.remark if account.remark else account.username
|
||||||
|
|
||||||
|
try:
|
||||||
|
if screenshot_path and result and result.get("success"):
|
||||||
|
cfg = database.get_system_config() or {}
|
||||||
|
if int(cfg.get("kdocs_enabled", 0) or 0) == 1:
|
||||||
|
doc_url = (cfg.get("kdocs_doc_url") or "").strip()
|
||||||
|
if doc_url:
|
||||||
|
user_cfg = database.get_user_kdocs_settings(user_id) or {}
|
||||||
|
if int(user_cfg.get("kdocs_auto_upload", 0) or 0) == 1:
|
||||||
|
unit = (
|
||||||
|
user_cfg.get("kdocs_unit") or cfg.get("kdocs_default_unit") or ""
|
||||||
|
).strip()
|
||||||
|
name = (account.remark or "").strip()
|
||||||
|
if unit and name:
|
||||||
|
from services.kdocs_uploader import get_kdocs_uploader
|
||||||
|
|
||||||
|
ok = get_kdocs_uploader().enqueue_upload(
|
||||||
|
user_id=user_id,
|
||||||
|
account_id=account_id,
|
||||||
|
unit=unit,
|
||||||
|
name=name,
|
||||||
|
image_path=screenshot_path,
|
||||||
|
)
|
||||||
|
if not ok:
|
||||||
|
log_to_client("表格上传排队失败: 队列已满", user_id, account_id)
|
||||||
|
else:
|
||||||
|
if not unit:
|
||||||
|
log_to_client("表格上传跳过: 未配置县区", user_id, account_id)
|
||||||
|
if not name:
|
||||||
|
log_to_client("表格上传跳过: 账号备注为空", user_id, account_id)
|
||||||
|
except Exception as kdocs_error:
|
||||||
|
logger.warning(f"表格上传任务提交失败: {kdocs_error}")
|
||||||
|
|
||||||
if batch_id:
|
if batch_id:
|
||||||
_batch_task_record_result(
|
_batch_task_record_result(
|
||||||
batch_id=batch_id,
|
batch_id=batch_id,
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ class TaskScheduler:
|
|||||||
|
|
||||||
self._executor_max_workers = self.max_global
|
self._executor_max_workers = self.max_global
|
||||||
self._executor = ThreadPoolExecutor(max_workers=self._executor_max_workers, thread_name_prefix="TaskWorker")
|
self._executor = ThreadPoolExecutor(max_workers=self._executor_max_workers, thread_name_prefix="TaskWorker")
|
||||||
self._old_executors = []
|
|
||||||
|
|
||||||
self._futures_lock = threading.Lock()
|
self._futures_lock = threading.Lock()
|
||||||
self._active_futures = set()
|
self._active_futures = set()
|
||||||
@@ -138,12 +137,6 @@ class TaskScheduler:
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for ex in self._old_executors:
|
|
||||||
try:
|
|
||||||
ex.shutdown(wait=False)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# 最后兜底:清理本调度器提交过的 active_task,避免测试/重启时被“任务已在运行中”误拦截
|
# 最后兜底:清理本调度器提交过的 active_task,避免测试/重启时被“任务已在运行中”误拦截
|
||||||
try:
|
try:
|
||||||
with self._cond:
|
with self._cond:
|
||||||
@@ -168,15 +161,18 @@ class TaskScheduler:
|
|||||||
new_max_global = max(1, int(max_global))
|
new_max_global = max(1, int(max_global))
|
||||||
self.max_global = new_max_global
|
self.max_global = new_max_global
|
||||||
if new_max_global > self._executor_max_workers:
|
if new_max_global > self._executor_max_workers:
|
||||||
self._old_executors.append(self._executor)
|
# 立即关闭旧线程池,防止资源泄漏
|
||||||
|
old_executor = self._executor
|
||||||
self._executor_max_workers = new_max_global
|
self._executor_max_workers = new_max_global
|
||||||
self._executor = ThreadPoolExecutor(
|
self._executor = ThreadPoolExecutor(
|
||||||
max_workers=self._executor_max_workers, thread_name_prefix="TaskWorker"
|
max_workers=self._executor_max_workers, thread_name_prefix="TaskWorker"
|
||||||
)
|
)
|
||||||
|
# 立即关闭旧线程池
|
||||||
try:
|
try:
|
||||||
self._old_executors[-1].shutdown(wait=False)
|
old_executor.shutdown(wait=False)
|
||||||
except Exception:
|
logger.info(f"线程池已扩容:{old_executor._max_workers} -> {self._executor_max_workers}")
|
||||||
pass
|
except Exception as e:
|
||||||
|
logger.warning(f"关闭旧线程池失败: {e}")
|
||||||
|
|
||||||
self._cond.notify_all()
|
self._cond.notify_all()
|
||||||
|
|
||||||
@@ -331,7 +327,8 @@ class TaskScheduler:
|
|||||||
except Exception:
|
except Exception:
|
||||||
with self._cond:
|
with self._cond:
|
||||||
self._running_global = max(0, self._running_global - 1)
|
self._running_global = max(0, self._running_global - 1)
|
||||||
self._running_by_user[task.user_id] = max(0, self._running_by_user.get(task.user_id, 1) - 1)
|
# 使用默认值 0 与增加时保持一致
|
||||||
|
self._running_by_user[task.user_id] = max(0, self._running_by_user.get(task.user_id, 0) - 1)
|
||||||
if self._running_by_user.get(task.user_id) == 0:
|
if self._running_by_user.get(task.user_id) == 0:
|
||||||
self._running_by_user.pop(task.user_id, None)
|
self._running_by_user.pop(task.user_id, None)
|
||||||
self._cond.notify_all()
|
self._cond.notify_all()
|
||||||
@@ -389,7 +386,8 @@ class TaskScheduler:
|
|||||||
safe_remove_task(task.account_id)
|
safe_remove_task(task.account_id)
|
||||||
with self._cond:
|
with self._cond:
|
||||||
self._running_global = max(0, self._running_global - 1)
|
self._running_global = max(0, self._running_global - 1)
|
||||||
self._running_by_user[task.user_id] = max(0, self._running_by_user.get(task.user_id, 1) - 1)
|
# 使用默认值 0 与增加时保持一致
|
||||||
|
self._running_by_user[task.user_id] = max(0, self._running_by_user.get(task.user_id, 0) - 1)
|
||||||
if self._running_by_user.get(task.user_id) == 0:
|
if self._running_by_user.get(task.user_id) == 0:
|
||||||
self._running_by_user.pop(task.user_id, None)
|
self._running_by_user.pop(task.user_id, None)
|
||||||
self._cond.notify_all()
|
self._cond.notify_all()
|
||||||
@@ -537,7 +535,9 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
_emit("account_update", account.to_dict(), room=f"user_{user_id}")
|
_emit("account_update", account.to_dict(), room=f"user_{user_id}")
|
||||||
account.last_browse_type = browse_type
|
account.last_browse_type = browse_type
|
||||||
|
|
||||||
safe_update_task_status(account_id, {"status": "运行中", "detail_status": "初始化", "start_time": task_start_time})
|
safe_update_task_status(
|
||||||
|
account_id, {"status": "运行中", "detail_status": "初始化", "start_time": task_start_time}
|
||||||
|
)
|
||||||
|
|
||||||
max_attempts = 3
|
max_attempts = 3
|
||||||
|
|
||||||
@@ -555,7 +555,7 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
proxy_server = get_proxy_from_api(proxy_api_url, max_retries=3)
|
proxy_server = get_proxy_from_api(proxy_api_url, max_retries=3)
|
||||||
if proxy_server:
|
if proxy_server:
|
||||||
proxy_config = {"server": proxy_server}
|
proxy_config = {"server": proxy_server}
|
||||||
log_to_client(f"✓ 将使用代理: {proxy_server}", user_id, account_id)
|
log_to_client(f"[OK] 将使用代理: {proxy_server}", user_id, account_id)
|
||||||
account.proxy_config = proxy_config # 保存代理配置供截图使用
|
account.proxy_config = proxy_config # 保存代理配置供截图使用
|
||||||
else:
|
else:
|
||||||
log_to_client("✗ 代理获取失败,将不使用代理继续", user_id, account_id)
|
log_to_client("✗ 代理获取失败,将不使用代理继续", user_id, account_id)
|
||||||
@@ -573,8 +573,16 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
|
|
||||||
with APIBrowser(log_callback=custom_log, proxy_config=proxy_config) as api_browser:
|
with APIBrowser(log_callback=custom_log, proxy_config=proxy_config) as api_browser:
|
||||||
if api_browser.login(account.username, account.password):
|
if api_browser.login(account.username, account.password):
|
||||||
log_to_client("✓ 登录成功!", user_id, account_id)
|
log_to_client("[OK] 首次登录成功,刷新登录时间...", user_id, account_id)
|
||||||
api_browser.save_cookies_for_playwright(account.username)
|
|
||||||
|
# 二次登录:让"上次登录时间"变成刚才首次登录的时间
|
||||||
|
# 这样截图时显示的"上次登录时间"就是几秒前而不是昨天
|
||||||
|
if api_browser.login(account.username, account.password):
|
||||||
|
log_to_client("[OK] 二次登录成功!", user_id, account_id)
|
||||||
|
else:
|
||||||
|
log_to_client("⚠ 二次登录失败,继续使用首次登录状态", user_id, account_id)
|
||||||
|
|
||||||
|
api_browser.save_cookies_for_screenshot(account.username)
|
||||||
database.reset_account_login_status(account_id)
|
database.reset_account_login_status(account_id)
|
||||||
|
|
||||||
if not account.remark:
|
if not account.remark:
|
||||||
@@ -602,7 +610,9 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
browsed_items = int(progress.get("browsed_items") or 0)
|
browsed_items = int(progress.get("browsed_items") or 0)
|
||||||
if total_items > 0:
|
if total_items > 0:
|
||||||
account.total_items = total_items
|
account.total_items = total_items
|
||||||
safe_update_task_status(account_id, {"progress": {"items": browsed_items, "attachments": 0}})
|
safe_update_task_status(
|
||||||
|
account_id, {"progress": {"items": browsed_items, "attachments": 0}}
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -647,7 +657,9 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
|
|
||||||
if result.success:
|
if result.success:
|
||||||
log_to_client(
|
log_to_client(
|
||||||
f"浏览完成! 共 {result.total_items} 条内容,{result.total_attachments} 个附件", user_id, account_id
|
f"浏览完成! 共 {result.total_items} 条内容,{result.total_attachments} 个附件",
|
||||||
|
user_id,
|
||||||
|
account_id,
|
||||||
)
|
)
|
||||||
safe_update_task_status(
|
safe_update_task_status(
|
||||||
account_id,
|
account_id,
|
||||||
@@ -717,7 +729,9 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
account.automation = None
|
account.automation = None
|
||||||
|
|
||||||
if attempt < max_attempts:
|
if attempt < max_attempts:
|
||||||
log_to_client(f"⚠ 代理可能速度过慢,将换新IP重试 ({attempt}/{max_attempts})", user_id, account_id)
|
log_to_client(
|
||||||
|
f"⚠ 代理可能速度过慢,将换新IP重试 ({attempt}/{max_attempts})", user_id, account_id
|
||||||
|
)
|
||||||
time_module.sleep(2)
|
time_module.sleep(2)
|
||||||
continue
|
continue
|
||||||
log_to_client(f"❌ 已达到最大重试次数({max_attempts}),任务失败", user_id, account_id)
|
log_to_client(f"❌ 已达到最大重试次数({max_attempts}),任务失败", user_id, account_id)
|
||||||
@@ -857,7 +871,10 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
browse_result_dict = {"total_items": result.total_items, "total_attachments": result.total_attachments}
|
browse_result_dict = {
|
||||||
|
"total_items": result.total_items,
|
||||||
|
"total_attachments": result.total_attachments,
|
||||||
|
}
|
||||||
screenshot_submitted = True
|
screenshot_submitted = True
|
||||||
threading.Thread(
|
threading.Thread(
|
||||||
target=take_screenshot_for_account,
|
target=take_screenshot_for_account,
|
||||||
@@ -880,7 +897,13 @@ def run_task(user_id, account_id, browse_type, enable_screenshot=True, source="m
|
|||||||
_emit("account_update", account.to_dict(), room=f"user_{user_id}")
|
_emit("account_update", account.to_dict(), room=f"user_{user_id}")
|
||||||
|
|
||||||
def delayed_retry_submit():
|
def delayed_retry_submit():
|
||||||
if account.should_stop:
|
# 重新获取最新的账户对象,避免使用闭包中的旧对象
|
||||||
|
fresh_account = safe_get_account(user_id, account_id)
|
||||||
|
if not fresh_account:
|
||||||
|
log_to_client("自动重试取消: 账户不存在", user_id, account_id)
|
||||||
|
return
|
||||||
|
if fresh_account.should_stop:
|
||||||
|
log_to_client("自动重试取消: 任务已被停止", user_id, account_id)
|
||||||
return
|
return
|
||||||
log_to_client(f"🔄 开始第 {retry_count + 1} 次自动重试...", user_id, account_id)
|
log_to_client(f"🔄 开始第 {retry_count + 1} 次自动重试...", user_id, account_id)
|
||||||
ok, msg = submit_account_task(
|
ok, msg = submit_account_task(
|
||||||
|
|||||||
@@ -1,34 +1,34 @@
|
|||||||
{
|
{
|
||||||
"_email-BghJNgj1.js": {
|
"_email-C4xyG93p.js": {
|
||||||
"file": "assets/email-BghJNgj1.js",
|
"file": "assets/email-C4xyG93p.js",
|
||||||
"name": "email",
|
"name": "email",
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html"
|
"index.html"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_tasks-Cx_Yf55V.js": {
|
"_system-C6kBIFhi.js": {
|
||||||
"file": "assets/tasks-Cx_Yf55V.js",
|
"file": "assets/system-C6kBIFhi.js",
|
||||||
|
"name": "system",
|
||||||
|
"imports": [
|
||||||
|
"index.html"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"_tasks-dxahzB_w.js": {
|
||||||
|
"file": "assets/tasks-dxahzB_w.js",
|
||||||
"name": "tasks",
|
"name": "tasks",
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html"
|
"index.html"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_update-D34iQbO6.js": {
|
"_users-ecMaaAFD.js": {
|
||||||
"file": "assets/update-D34iQbO6.js",
|
"file": "assets/users-ecMaaAFD.js",
|
||||||
"name": "update",
|
|
||||||
"imports": [
|
|
||||||
"index.html"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"_users-DCcrmSwH.js": {
|
|
||||||
"file": "assets/users-DCcrmSwH.js",
|
|
||||||
"name": "users",
|
"name": "users",
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html"
|
"index.html"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"index.html": {
|
"index.html": {
|
||||||
"file": "assets/index-C9w-iZIr.js",
|
"file": "assets/index-DKH_HvPt.js",
|
||||||
"name": "index",
|
"name": "index",
|
||||||
"src": "index.html",
|
"src": "index.html",
|
||||||
"isEntry": true,
|
"isEntry": true,
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/AnnouncementsPage.vue": {
|
"src/pages/AnnouncementsPage.vue": {
|
||||||
"file": "assets/AnnouncementsPage-DEX_yASt.js",
|
"file": "assets/AnnouncementsPage-kpoSCxEP.js",
|
||||||
"name": "AnnouncementsPage",
|
"name": "AnnouncementsPage",
|
||||||
"src": "src/pages/AnnouncementsPage.vue",
|
"src": "src/pages/AnnouncementsPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
@@ -56,16 +56,16 @@
|
|||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/AnnouncementsPage-CjcC-aWD.css"
|
"assets/AnnouncementsPage-BhIwmMSX.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/EmailPage.vue": {
|
"src/pages/EmailPage.vue": {
|
||||||
"file": "assets/EmailPage-Cev_X_Ce.js",
|
"file": "assets/EmailPage-CEtsoP5P.js",
|
||||||
"name": "EmailPage",
|
"name": "EmailPage",
|
||||||
"src": "src/pages/EmailPage.vue",
|
"src": "src/pages/EmailPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"_email-BghJNgj1.js",
|
"_email-C4xyG93p.js",
|
||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/FeedbacksPage.vue": {
|
"src/pages/FeedbacksPage.vue": {
|
||||||
"file": "assets/FeedbacksPage-BKxylUkG.js",
|
"file": "assets/FeedbacksPage-ByHln3Ce.js",
|
||||||
"name": "FeedbacksPage",
|
"name": "FeedbacksPage",
|
||||||
"src": "src/pages/FeedbacksPage.vue",
|
"src": "src/pages/FeedbacksPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
@@ -85,13 +85,13 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/LogsPage.vue": {
|
"src/pages/LogsPage.vue": {
|
||||||
"file": "assets/LogsPage-CemQ-Y_T.js",
|
"file": "assets/LogsPage-vZFAwgb-.js",
|
||||||
"name": "LogsPage",
|
"name": "LogsPage",
|
||||||
"src": "src/pages/LogsPage.vue",
|
"src": "src/pages/LogsPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"_users-DCcrmSwH.js",
|
"_users-ecMaaAFD.js",
|
||||||
"_tasks-Cx_Yf55V.js",
|
"_tasks-dxahzB_w.js",
|
||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
@@ -99,22 +99,22 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/ReportPage.vue": {
|
"src/pages/ReportPage.vue": {
|
||||||
"file": "assets/ReportPage-D6vDD1zK.js",
|
"file": "assets/ReportPage--ClMBhif.js",
|
||||||
"name": "ReportPage",
|
"name": "ReportPage",
|
||||||
"src": "src/pages/ReportPage.vue",
|
"src": "src/pages/ReportPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html",
|
"index.html",
|
||||||
"_email-BghJNgj1.js",
|
"_email-C4xyG93p.js",
|
||||||
"_tasks-Cx_Yf55V.js",
|
"_tasks-dxahzB_w.js",
|
||||||
"_update-D34iQbO6.js"
|
"_system-C6kBIFhi.js"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/ReportPage-CSbGJlZV.css"
|
"assets/ReportPage-Q8rCsG8A.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/SecurityPage.vue": {
|
"src/pages/SecurityPage.vue": {
|
||||||
"file": "assets/SecurityPage-DGvsGoGa.js",
|
"file": "assets/SecurityPage-DBhX0IuO.js",
|
||||||
"name": "SecurityPage",
|
"name": "SecurityPage",
|
||||||
"src": "src/pages/SecurityPage.vue",
|
"src": "src/pages/SecurityPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
@@ -122,11 +122,11 @@
|
|||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/SecurityPage-CH3QeiaV.css"
|
"assets/SecurityPage-Dv9jYTtC.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/SettingsPage.vue": {
|
"src/pages/SettingsPage.vue": {
|
||||||
"file": "assets/SettingsPage-Bw1ItHlK.js",
|
"file": "assets/SettingsPage-D91FOriC.js",
|
||||||
"name": "SettingsPage",
|
"name": "SettingsPage",
|
||||||
"src": "src/pages/SettingsPage.vue",
|
"src": "src/pages/SettingsPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
@@ -134,29 +134,29 @@
|
|||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/SettingsPage-DGdwb4W2.css"
|
"assets/SettingsPage-DKTq8S2K.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/SystemPage.vue": {
|
"src/pages/SystemPage.vue": {
|
||||||
"file": "assets/SystemPage-RgAQwtHu.js",
|
"file": "assets/SystemPage-DVj-4Lnp.js",
|
||||||
"name": "SystemPage",
|
"name": "SystemPage",
|
||||||
"src": "src/pages/SystemPage.vue",
|
"src": "src/pages/SystemPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"_update-D34iQbO6.js",
|
"_system-C6kBIFhi.js",
|
||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/SystemPage-BjTkcmTG.css"
|
"assets/SystemPage-C8GQyKcD.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/UsersPage.vue": {
|
"src/pages/UsersPage.vue": {
|
||||||
"file": "assets/UsersPage-CFbr6Y3k.js",
|
"file": "assets/UsersPage-C_vL5-r3.js",
|
||||||
"name": "UsersPage",
|
"name": "UsersPage",
|
||||||
"src": "src/pages/UsersPage.vue",
|
"src": "src/pages/UsersPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"_users-DCcrmSwH.js",
|
"_users-ecMaaAFD.js",
|
||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
|
|||||||
1
static/admin/assets/AnnouncementsPage-BhIwmMSX.css
Normal file
1
static/admin/assets/AnnouncementsPage-BhIwmMSX.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.page-stack[data-v-cad97d6b]{display:flex;flex-direction:column;gap:12px}.card[data-v-cad97d6b]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.section-title[data-v-cad97d6b]{margin:0 0 12px;font-size:14px;font-weight:800}.help[data-v-cad97d6b]{margin-top:10px;font-size:12px;color:var(--app-muted)}.image-preview[data-v-cad97d6b]{margin:6px 0 2px;display:flex;justify-content:flex-start}.image-preview img[data-v-cad97d6b]{max-width:280px;max-height:160px;border-radius:8px;border:1px solid var(--app-border);object-fit:contain}.image-upload-row[data-v-cad97d6b]{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.image-input[data-v-cad97d6b]{display:none}.image-url[data-v-cad97d6b]{font-size:12px;color:var(--app-muted);word-break:break-all}.announcement-view[data-v-cad97d6b]{display:flex;flex-direction:column;gap:12px}.announcement-view-text[data-v-cad97d6b]{white-space:pre-wrap;line-height:1.6;font-size:14px}.announcement-view-image[data-v-cad97d6b]{max-width:100%;max-height:320px;border-radius:10px;border:1px solid var(--app-border);object-fit:contain}.table-wrap[data-v-cad97d6b]{overflow-x:auto}.ellipsis[data-v-cad97d6b]{display:inline-block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.actions[data-v-cad97d6b]{display:flex;flex-wrap:wrap;gap:8px}
|
||||||
@@ -1 +0,0 @@
|
|||||||
.page-stack[data-v-a7b3418e]{display:flex;flex-direction:column;gap:12px}.card[data-v-a7b3418e]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.section-title[data-v-a7b3418e]{margin:0 0 12px;font-size:14px;font-weight:800}.help[data-v-a7b3418e]{margin-top:10px;font-size:12px;color:var(--app-muted)}.table-wrap[data-v-a7b3418e]{overflow-x:auto}.ellipsis[data-v-a7b3418e]{display:inline-block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.actions[data-v-a7b3418e]{display:flex;flex-wrap:wrap;gap:8px}
|
|
||||||
File diff suppressed because one or more lines are too long
1
static/admin/assets/AnnouncementsPage-kpoSCxEP.js
Normal file
1
static/admin/assets/AnnouncementsPage-kpoSCxEP.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
static/admin/assets/FeedbacksPage-ByHln3Ce.js
Normal file
1
static/admin/assets/FeedbacksPage-ByHln3Ce.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
static/admin/assets/ReportPage--ClMBhif.js
Normal file
1
static/admin/assets/ReportPage--ClMBhif.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
static/admin/assets/ReportPage-Q8rCsG8A.css
Normal file
1
static/admin/assets/ReportPage-Q8rCsG8A.css
Normal file
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
|||||||
.page-stack[data-v-ea9240bd]{display:flex;flex-direction:column;gap:12px}.toolbar[data-v-ea9240bd]{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.stats-row[data-v-ea9240bd]{margin-bottom:2px}.card[data-v-ea9240bd]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.sub-card[data-v-ea9240bd]{margin-top:12px;border-radius:var(--app-radius);border:1px solid var(--app-border)}.stat-card[data-v-ea9240bd]{border-radius:var(--app-radius);border:1px solid var(--app-border);box-shadow:var(--app-shadow)}.stat-value[data-v-ea9240bd]{font-size:22px;font-weight:800;line-height:1.1}.stat-label[data-v-ea9240bd]{margin-top:6px;font-size:12px;color:var(--app-muted)}.filters[data-v-ea9240bd]{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:12px}.table-wrap[data-v-ea9240bd]{overflow-x:auto}.ellipsis[data-v-ea9240bd]{display:inline-block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mono[data-v-ea9240bd]{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.pagination[data-v-ea9240bd]{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:14px;flex-wrap:wrap}.page-hint[data-v-ea9240bd]{font-size:12px}.inner-tabs[data-v-ea9240bd]{margin-top:6px}.risk-head[data-v-ea9240bd]{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:12px;flex-wrap:wrap}.risk-title[data-v-ea9240bd]{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.dialog-actions[data-v-ea9240bd]{display:flex;align-items:center;gap:10px}.spacer[data-v-ea9240bd]{flex:1}
|
|
||||||
5
static/admin/assets/SecurityPage-DBhX0IuO.js
Normal file
5
static/admin/assets/SecurityPage-DBhX0IuO.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
static/admin/assets/SecurityPage-Dv9jYTtC.css
Normal file
1
static/admin/assets/SecurityPage-Dv9jYTtC.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.page-stack[data-v-22d57053]{display:flex;flex-direction:column;gap:12px}.toolbar[data-v-22d57053]{display:flex;gap:10px;align-items:center;flex-wrap:wrap}.stats-row[data-v-22d57053]{margin-bottom:2px}.card[data-v-22d57053]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.sub-card[data-v-22d57053]{margin-top:12px;border-radius:var(--app-radius);border:1px solid var(--app-border)}.stat-card[data-v-22d57053]{border-radius:var(--app-radius);border:1px solid var(--app-border);box-shadow:var(--app-shadow)}.stat-value[data-v-22d57053]{font-size:22px;font-weight:800;line-height:1.1}.stat-label[data-v-22d57053]{margin-top:6px;font-size:12px;color:var(--app-muted)}.filters[data-v-22d57053]{display:flex;flex-wrap:wrap;gap:10px;align-items:center;margin-bottom:12px}.table-wrap[data-v-22d57053]{overflow-x:auto}.ellipsis[data-v-22d57053]{display:inline-block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mono[data-v-22d57053]{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.pagination[data-v-22d57053]{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:14px;flex-wrap:wrap}.page-hint[data-v-22d57053]{font-size:12px}.inner-tabs[data-v-22d57053]{margin-top:6px}.risk-head[data-v-22d57053]{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:12px;flex-wrap:wrap}.risk-title[data-v-22d57053]{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.dialog-actions[data-v-22d57053]{display:flex;align-items:center;gap:10px}.spacer[data-v-22d57053]{flex:1}
|
||||||
@@ -1 +0,0 @@
|
|||||||
import{O as m,_ as T,r as p,d as u,e as h,f as k,g as r,h as a,w as s,n as x,J as d,I as b}from"./index-C9w-iZIr.js";async function C(o){const{data:t}=await m.put("/admin/username",{new_username:o});return t}async function P(o){const{data:t}=await m.put("/admin/password",{new_password:o});return t}async function U(){const{data:o}=await m.post("/logout");return o}const E={class:"page-stack"},N={__name:"SettingsPage",setup(o){const t=p(""),i=p(""),n=p(!1);async function f(){try{await U()}catch{}finally{window.location.href="/yuyx"}}async function V(){const l=t.value.trim();if(!l){d.error("请输入新用户名");return}try{await b.confirm(`确定将管理员用户名修改为「${l}」吗?修改后需要重新登录。`,"修改用户名",{confirmButtonText:"确认修改",cancelButtonText:"取消",type:"warning"})}catch{return}n.value=!0;try{await C(l),d.success("用户名修改成功,请重新登录"),t.value="",setTimeout(f,1200)}catch{}finally{n.value=!1}}async function B(){const l=i.value;if(!l){d.error("请输入新密码");return}if(l.length<6){d.error("密码至少6个字符");return}try{await b.confirm("确定修改管理员密码吗?修改后需要重新登录。","修改密码",{confirmButtonText:"确认修改",cancelButtonText:"取消",type:"warning"})}catch{return}n.value=!0;try{await P(l),d.success("密码修改成功,请重新登录"),i.value="",setTimeout(f,1200)}catch{}finally{n.value=!1}}return(l,e)=>{const w=u("el-input"),v=u("el-form-item"),y=u("el-form"),_=u("el-button"),g=u("el-card");return k(),h("div",E,[e[7]||(e[7]=r("div",{class:"app-page-title"},[r("h2",null,"设置"),r("span",{class:"app-muted"},"管理员账号设置")],-1)),a(g,{shadow:"never","body-style":{padding:"16px"},class:"card"},{default:s(()=>[e[3]||(e[3]=r("h3",{class:"section-title"},"修改管理员用户名",-1)),a(y,{"label-width":"120px"},{default:s(()=>[a(v,{label:"新用户名"},{default:s(()=>[a(w,{modelValue:t.value,"onUpdate:modelValue":e[0]||(e[0]=c=>t.value=c),placeholder:"输入新用户名",disabled:n.value},null,8,["modelValue","disabled"])]),_:1})]),_:1}),a(_,{type:"primary",loading:n.value,onClick:V},{default:s(()=>[...e[2]||(e[2]=[x("保存用户名",-1)])]),_:1},8,["loading"])]),_:1}),a(g,{shadow:"never","body-style":{padding:"16px"},class:"card"},{default:s(()=>[e[5]||(e[5]=r("h3",{class:"section-title"},"修改管理员密码",-1)),a(y,{"label-width":"120px"},{default:s(()=>[a(v,{label:"新密码"},{default:s(()=>[a(w,{modelValue:i.value,"onUpdate:modelValue":e[1]||(e[1]=c=>i.value=c),type:"password","show-password":"",placeholder:"输入新密码",disabled:n.value},null,8,["modelValue","disabled"])]),_:1})]),_:1}),a(_,{type:"primary",loading:n.value,onClick:B},{default:s(()=>[...e[4]||(e[4]=[x("保存密码",-1)])]),_:1},8,["loading"]),e[6]||(e[6]=r("div",{class:"help"},"建议使用更强密码(至少8位且包含字母与数字)。",-1))]),_:1})])}}},I=T(N,[["__scopeId","data-v-2f4b840f"]]);export{I as default};
|
|
||||||
1
static/admin/assets/SettingsPage-D91FOriC.js
Normal file
1
static/admin/assets/SettingsPage-D91FOriC.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import{a as m,_ as B,r as p,f as u,g as T,h as P,j as r,m as a,w as l,q as x,L as i,K as b}from"./index-DKH_HvPt.js";async function C(o){const{data:s}=await m.put("/admin/username",{new_username:o});return s}async function S(o){const{data:s}=await m.put("/admin/password",{new_password:o});return s}async function U(){const{data:o}=await m.post("/logout");return o}const A={class:"page-stack"},E={__name:"SettingsPage",setup(o){const s=p(""),d=p(""),n=p(!1);function k(t){const e=String(t||"");return e.length<8?{ok:!1,message:"密码长度至少8位"}:e.length>128?{ok:!1,message:"密码长度不能超过128个字符"}:!/[a-zA-Z]/.test(e)||!/\d/.test(e)?{ok:!1,message:"密码必须包含字母和数字"}:{ok:!0,message:""}}async function f(){try{await U()}catch{}finally{window.location.href="/yuyx"}}async function V(){const t=s.value.trim();if(!t){i.error("请输入新用户名");return}try{await b.confirm(`确定将管理员用户名修改为「${t}」吗?修改后需要重新登录。`,"修改用户名",{confirmButtonText:"确认修改",cancelButtonText:"取消",type:"warning"})}catch{return}n.value=!0;try{await C(t),i.success("用户名修改成功,请重新登录"),s.value="",setTimeout(f,1200)}catch{}finally{n.value=!1}}async function h(){const t=d.value;if(!t){i.error("请输入新密码");return}const e=k(t);if(!e.ok){i.error(e.message);return}try{await b.confirm("确定修改管理员密码吗?修改后需要重新登录。","修改密码",{confirmButtonText:"确认修改",cancelButtonText:"取消",type:"warning"})}catch{return}n.value=!0;try{await S(t),i.success("密码修改成功,请重新登录"),d.value="",setTimeout(f,1200)}catch{}finally{n.value=!1}}return(t,e)=>{const g=u("el-input"),w=u("el-form-item"),v=u("el-form"),y=u("el-button"),_=u("el-card");return P(),T("div",A,[e[7]||(e[7]=r("div",{class:"app-page-title"},[r("h2",null,"设置"),r("span",{class:"app-muted"},"管理员账号设置")],-1)),a(_,{shadow:"never","body-style":{padding:"16px"},class:"card"},{default:l(()=>[e[3]||(e[3]=r("h3",{class:"section-title"},"修改管理员用户名",-1)),a(v,{"label-width":"120px"},{default:l(()=>[a(w,{label:"新用户名"},{default:l(()=>[a(g,{modelValue:s.value,"onUpdate:modelValue":e[0]||(e[0]=c=>s.value=c),placeholder:"输入新用户名",disabled:n.value},null,8,["modelValue","disabled"])]),_:1})]),_:1}),a(y,{type:"primary",loading:n.value,onClick:V},{default:l(()=>[...e[2]||(e[2]=[x("保存用户名",-1)])]),_:1},8,["loading"])]),_:1}),a(_,{shadow:"never","body-style":{padding:"16px"},class:"card"},{default:l(()=>[e[5]||(e[5]=r("h3",{class:"section-title"},"修改管理员密码",-1)),a(v,{"label-width":"120px"},{default:l(()=>[a(w,{label:"新密码"},{default:l(()=>[a(g,{modelValue:d.value,"onUpdate:modelValue":e[1]||(e[1]=c=>d.value=c),type:"password","show-password":"",placeholder:"输入新密码",disabled:n.value},null,8,["modelValue","disabled"])]),_:1})]),_:1}),a(y,{type:"primary",loading:n.value,onClick:h},{default:l(()=>[...e[4]||(e[4]=[x("保存密码",-1)])]),_:1},8,["loading"]),e[6]||(e[6]=r("div",{class:"help"},"建议使用更强密码(至少8位且包含字母与数字)。",-1))]),_:1})])}}},M=B(E,[["__scopeId","data-v-12a26d11"]]);export{M as default};
|
||||||
@@ -1 +0,0 @@
|
|||||||
.page-stack[data-v-2f4b840f]{display:flex;flex-direction:column;gap:12px}.card[data-v-2f4b840f]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.section-title[data-v-2f4b840f]{margin:0 0 12px;font-size:14px;font-weight:800}.help[data-v-2f4b840f]{margin-top:10px;font-size:12px;color:var(--app-muted)}
|
|
||||||
1
static/admin/assets/SettingsPage-DKTq8S2K.css
Normal file
1
static/admin/assets/SettingsPage-DKTq8S2K.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.page-stack[data-v-12a26d11]{display:flex;flex-direction:column;gap:12px}.card[data-v-12a26d11]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.section-title[data-v-12a26d11]{margin:0 0 12px;font-size:14px;font-weight:800}.help[data-v-12a26d11]{margin-top:10px;font-size:12px;color:var(--app-muted)}
|
||||||
@@ -1 +0,0 @@
|
|||||||
.page-stack[data-v-d88590f1]{display:flex;flex-direction:column;gap:12px}.card[data-v-d88590f1]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.section-title[data-v-d88590f1]{margin:0 0 12px;font-size:14px;font-weight:800}.help[data-v-d88590f1]{margin-top:6px;font-size:12px;color:var(--app-muted)}.row-actions[data-v-d88590f1]{display:flex;flex-wrap:wrap;gap:10px}
|
|
||||||
1
static/admin/assets/SystemPage-C8GQyKcD.css
Normal file
1
static/admin/assets/SystemPage-C8GQyKcD.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.page-stack[data-v-b359577d]{display:flex;flex-direction:column;gap:12px}.card[data-v-b359577d]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.section-title[data-v-b359577d]{margin:0 0 12px;font-size:14px;font-weight:800}.kdocs-qr[data-v-b359577d]{display:flex;flex-direction:column;align-items:center;gap:12px}.kdocs-qr img[data-v-b359577d]{width:260px;max-width:100%;border:1px solid var(--app-border);border-radius:8px;padding:8px;background:#fff}.help[data-v-b359577d]{margin-top:6px;font-size:12px;color:var(--app-muted)}.row-actions[data-v-b359577d]{display:flex;flex-wrap:wrap;gap:10px}
|
||||||
17
static/admin/assets/SystemPage-DVj-4Lnp.js
Normal file
17
static/admin/assets/SystemPage-DVj-4Lnp.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
static/admin/assets/UsersPage-C_vL5-r3.js
Normal file
1
static/admin/assets/UsersPage-C_vL5-r3.js
Normal file
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
|||||||
import{O as n}from"./index-C9w-iZIr.js";async function i(){const{data:a}=await n.get("/email/settings");return a}async function e(a){const{data:t}=await n.post("/email/settings",a);return t}async function c(){const{data:a}=await n.get("/email/stats");return a}async function o(a){const{data:t}=await n.get("/email/logs",{params:a});return t}async function l(a){const{data:t}=await n.post("/email/logs/cleanup",{days:a});return t}export{o as a,i as b,l as c,c as f,e as u};
|
import{a as n}from"./index-DKH_HvPt.js";async function i(){const{data:a}=await n.get("/email/settings");return a}async function e(a){const{data:t}=await n.post("/email/settings",a);return t}async function c(){const{data:a}=await n.get("/email/stats");return a}async function o(a){const{data:t}=await n.get("/email/logs",{params:a});return t}async function l(a){const{data:t}=await n.post("/email/logs/cleanup",{days:a});return t}export{o as a,i as b,l as c,c as f,e as u};
|
||||||
File diff suppressed because one or more lines are too long
1
static/admin/assets/system-C6kBIFhi.js
Normal file
1
static/admin/assets/system-C6kBIFhi.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import{a}from"./index-DKH_HvPt.js";async function s(){const{data:t}=await a.get("/system/config");return t}async function c(t){const{data:e}=await a.post("/system/config",t);return e}async function o(){const{data:t}=await a.post("/schedule/execute",{});return t}export{o as e,s as f,c as u};
|
||||||
@@ -1 +0,0 @@
|
|||||||
import{O as a}from"./index-C9w-iZIr.js";async function c(){const{data:t}=await a.get("/server/info");return t}async function e(){const{data:t}=await a.get("/docker_stats");return t}async function o(){const{data:t}=await a.get("/task/stats");return t}async function r(){const{data:t}=await a.get("/task/running");return t}async function i(t){const{data:s}=await a.get("/task/logs",{params:t});return s}async function f(t){const{data:s}=await a.post("/task/logs/clear",{days:t});return s}export{r as a,c as b,e as c,i as d,f as e,o as f};
|
|
||||||
1
static/admin/assets/tasks-dxahzB_w.js
Normal file
1
static/admin/assets/tasks-dxahzB_w.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import{a}from"./index-DKH_HvPt.js";async function c(){const{data:t}=await a.get("/server/info");return t}async function e(){const{data:t}=await a.get("/docker_stats");return t}async function o(){const{data:t}=await a.get("/task/stats");return t}async function r(){const{data:t}=await a.get("/task/running");return t}async function i(t){const{data:s}=await a.get("/task/logs",{params:t});return s}async function f(t){const{data:s}=await a.post("/task/logs/clear",{days:t});return s}export{r as a,c as b,e as c,i as d,f as e,o as f};
|
||||||
@@ -1 +0,0 @@
|
|||||||
import{O as a}from"./index-C9w-iZIr.js";async function s(){const{data:t}=await a.get("/system/config");return t}async function c(t){const{data:e}=await a.post("/system/config",t);return e}async function u(){const{data:t}=await a.post("/schedule/execute",{});return t}async function o(){const{data:t}=await a.get("/update/status");return t}async function r(){const{data:t}=await a.get("/update/result");return t}async function d(t={}){const{data:e}=await a.get("/update/log",{params:t});return e}async function i(){const{data:t}=await a.post("/update/check",{});return t}async function f(t={}){const{data:e}=await a.post("/update/run",t);return e}export{o as a,r as b,d as c,f as d,u as e,s as f,i as r,c as u};
|
|
||||||
@@ -1 +1 @@
|
|||||||
import{O as t}from"./index-C9w-iZIr.js";async function n(){const{data:s}=await t.get("/users");return s}async function o(s){const{data:a}=await t.post(`/users/${s}/approve`);return a}async function c(s){const{data:a}=await t.post(`/users/${s}/reject`);return a}async function i(s){const{data:a}=await t.delete(`/users/${s}`);return a}async function u(s,a){const{data:e}=await t.post(`/users/${s}/vip`,{days:a});return e}async function p(s){const{data:a}=await t.delete(`/users/${s}/vip`);return a}async function d(s,a){const{data:e}=await t.post(`/users/${s}/reset_password`,{new_password:a});return e}export{o as a,p as b,d as c,i as d,n as f,c as r,u as s};
|
import{a as t}from"./index-DKH_HvPt.js";async function n(){const{data:s}=await t.get("/users");return s}async function o(s){const{data:a}=await t.post(`/users/${s}/approve`);return a}async function c(s){const{data:a}=await t.post(`/users/${s}/reject`);return a}async function i(s){const{data:a}=await t.delete(`/users/${s}`);return a}async function u(s,a){const{data:e}=await t.post(`/users/${s}/vip`,{days:a});return e}async function p(s){const{data:a}=await t.delete(`/users/${s}/vip`);return a}async function d(s,a){const{data:e}=await t.post(`/users/${s}/reset_password`,{new_password:a});return e}export{o as a,p as b,d as c,i as d,n as f,c as r,u as s};
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>后台管理 - 知识管理平台</title>
|
<title>后台管理 - 知识管理平台</title>
|
||||||
<script type="module" crossorigin src="./assets/index-C9w-iZIr.js"></script>
|
<script type="module" crossorigin src="./assets/index-DKH_HvPt.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="./assets/index-_5Ec1Hmd.css">
|
<link rel="stylesheet" crossorigin href="./assets/index-_5Ec1Hmd.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
{
|
{
|
||||||
"_accounts-CTfB-Ncr.js": {
|
"_accounts-Bta9cdL5.js": {
|
||||||
"file": "assets/accounts-CTfB-Ncr.js",
|
"file": "assets/accounts-Bta9cdL5.js",
|
||||||
"name": "accounts",
|
"name": "accounts",
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html"
|
"index.html"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_auth-WsWSY0rn.js": {
|
"_auth--ytvFYf6.js": {
|
||||||
"file": "assets/auth-WsWSY0rn.js",
|
"file": "assets/auth--ytvFYf6.js",
|
||||||
"name": "auth",
|
"name": "auth",
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html"
|
"index.html"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"index.html": {
|
"index.html": {
|
||||||
"file": "assets/index-CEOd73lG.js",
|
"file": "assets/index-CPwwGffH.js",
|
||||||
"name": "index",
|
"name": "index",
|
||||||
"src": "index.html",
|
"src": "index.html",
|
||||||
"isEntry": true,
|
"isEntry": true,
|
||||||
@@ -28,68 +28,68 @@
|
|||||||
"src/pages/ScreenshotsPage.vue"
|
"src/pages/ScreenshotsPage.vue"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/index-CD3NfpmF.css"
|
"assets/index-BVjJVlht.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/AccountsPage.vue": {
|
"src/pages/AccountsPage.vue": {
|
||||||
"file": "assets/AccountsPage-D3IUho1c.js",
|
"file": "assets/AccountsPage-D3MJyXUD.js",
|
||||||
"name": "AccountsPage",
|
"name": "AccountsPage",
|
||||||
"src": "src/pages/AccountsPage.vue",
|
"src": "src/pages/AccountsPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"_accounts-CTfB-Ncr.js",
|
"_accounts-Bta9cdL5.js",
|
||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/AccountsPage-CkDdMK5Q.css"
|
"assets/AccountsPage-tARhOk5s.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/LoginPage.vue": {
|
"src/pages/LoginPage.vue": {
|
||||||
"file": "assets/LoginPage-x4LlIM56.js",
|
"file": "assets/LoginPage-Cz6slTnR.js",
|
||||||
"name": "LoginPage",
|
"name": "LoginPage",
|
||||||
"src": "src/pages/LoginPage.vue",
|
"src": "src/pages/LoginPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html",
|
"index.html",
|
||||||
"_auth-WsWSY0rn.js"
|
"_auth--ytvFYf6.js"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/LoginPage-C_sxX_84.css"
|
"assets/LoginPage-CnwOLKJz.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/RegisterPage.vue": {
|
"src/pages/RegisterPage.vue": {
|
||||||
"file": "assets/RegisterPage-BBedBh-y.js",
|
"file": "assets/RegisterPage-D46uldFj.js",
|
||||||
"name": "RegisterPage",
|
"name": "RegisterPage",
|
||||||
"src": "src/pages/RegisterPage.vue",
|
"src": "src/pages/RegisterPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html",
|
"index.html",
|
||||||
"_auth-WsWSY0rn.js"
|
"_auth--ytvFYf6.js"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/RegisterPage-yylt2w7b.css"
|
"assets/RegisterPage-BOcNcW5D.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/ResetPasswordPage.vue": {
|
"src/pages/ResetPasswordPage.vue": {
|
||||||
"file": "assets/ResetPasswordPage--Vqm02p7.js",
|
"file": "assets/ResetPasswordPage-CO1hZug-.js",
|
||||||
"name": "ResetPasswordPage",
|
"name": "ResetPasswordPage",
|
||||||
"src": "src/pages/ResetPasswordPage.vue",
|
"src": "src/pages/ResetPasswordPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"index.html",
|
"index.html",
|
||||||
"_auth-WsWSY0rn.js"
|
"_auth--ytvFYf6.js"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"assets/ResetPasswordPage-DybfLMAw.css"
|
"assets/ResetPasswordPage-DybfLMAw.css"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/SchedulesPage.vue": {
|
"src/pages/SchedulesPage.vue": {
|
||||||
"file": "assets/SchedulesPage-Cln6Gk1v.js",
|
"file": "assets/SchedulesPage-CliP1bMU.js",
|
||||||
"name": "SchedulesPage",
|
"name": "SchedulesPage",
|
||||||
"src": "src/pages/SchedulesPage.vue",
|
"src": "src/pages/SchedulesPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
"imports": [
|
"imports": [
|
||||||
"_accounts-CTfB-Ncr.js",
|
"_accounts-Bta9cdL5.js",
|
||||||
"index.html"
|
"index.html"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/ScreenshotsPage.vue": {
|
"src/pages/ScreenshotsPage.vue": {
|
||||||
"file": "assets/ScreenshotsPage-BeyAIC93.js",
|
"file": "assets/ScreenshotsPage-CqETBpbn.js",
|
||||||
"name": "ScreenshotsPage",
|
"name": "ScreenshotsPage",
|
||||||
"src": "src/pages/ScreenshotsPage.vue",
|
"src": "src/pages/ScreenshotsPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"src/pages/VerifyResultPage.vue": {
|
"src/pages/VerifyResultPage.vue": {
|
||||||
"file": "assets/VerifyResultPage-Ci85Um-V.js",
|
"file": "assets/VerifyResultPage-XFuV1ie5.js",
|
||||||
"name": "VerifyResultPage",
|
"name": "VerifyResultPage",
|
||||||
"src": "src/pages/VerifyResultPage.vue",
|
"src": "src/pages/VerifyResultPage.vue",
|
||||||
"isDynamicEntry": true,
|
"isDynamicEntry": true,
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
.page[data-v-b4e85160]{display:flex;flex-direction:column;gap:12px}.stat-card[data-v-b4e85160],.panel[data-v-b4e85160]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.stat-label[data-v-b4e85160]{font-size:12px}.stat-value[data-v-b4e85160]{margin-top:6px;font-size:22px;font-weight:900;letter-spacing:.2px}.stat-suffix[data-v-b4e85160]{margin-left:6px;font-size:12px;font-weight:600}.upgrade-banner[data-v-b4e85160]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.upgrade-actions[data-v-b4e85160]{margin-top:10px}.panel-head[data-v-b4e85160]{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:10px;flex-wrap:wrap}.panel-title[data-v-b4e85160]{font-size:16px;font-weight:900}.panel-actions[data-v-b4e85160]{display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end}.toolbar[data-v-b4e85160]{display:flex;flex-wrap:wrap;align-items:center;gap:12px;padding:10px;border:1px dashed rgba(17,24,39,.14);border-radius:12px;background:#f6f7fb99}.toolbar-left[data-v-b4e85160],.toolbar-middle[data-v-b4e85160],.toolbar-right[data-v-b4e85160]{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.toolbar-right[data-v-b4e85160]{margin-left:auto;justify-content:flex-end}.grid[data-v-b4e85160]{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:12px;align-items:start}.account-card[data-v-b4e85160]{border-radius:14px;border:1px solid var(--app-border)}.card-top[data-v-b4e85160]{display:flex;gap:10px}.card-check[data-v-b4e85160]{padding-top:2px}.card-main[data-v-b4e85160]{min-width:0;flex:1}.card-title[data-v-b4e85160]{display:flex;align-items:center;justify-content:space-between;gap:10px}.card-name[data-v-b4e85160]{font-size:14px;font-weight:900;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.card-sub[data-v-b4e85160]{margin-top:6px;font-size:12px;line-height:1.4;word-break:break-word}.progress[data-v-b4e85160]{margin-top:12px}.progress-meta[data-v-b4e85160]{margin-top:6px;display:flex;justify-content:space-between;gap:10px;font-size:12px}.card-controls[data-v-b4e85160]{margin-top:12px;display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.card-buttons[data-v-b4e85160]{display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end}.vip-body[data-v-b4e85160]{padding:12px 0 0}.vip-tip[data-v-b4e85160]{margin-top:10px;font-size:13px;line-height:1.6}@media(max-width:480px){.grid[data-v-b4e85160]{grid-template-columns:1fr}}@media(max-width:768px){.panel-actions[data-v-b4e85160]{width:100%;justify-content:flex-end}.toolbar-left[data-v-b4e85160],.toolbar-middle[data-v-b4e85160],.toolbar-right[data-v-b4e85160]{width:100%}.toolbar-right[data-v-b4e85160]{margin-left:0;justify-content:flex-end}}
|
|
||||||
File diff suppressed because one or more lines are too long
1
static/app/assets/AccountsPage-D3MJyXUD.js
Normal file
1
static/app/assets/AccountsPage-D3MJyXUD.js
Normal file
File diff suppressed because one or more lines are too long
1
static/app/assets/AccountsPage-tARhOk5s.css
Normal file
1
static/app/assets/AccountsPage-tARhOk5s.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.page[data-v-961c6960]{display:flex;flex-direction:column;gap:12px}.stat-card[data-v-961c6960],.panel[data-v-961c6960]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.stat-label[data-v-961c6960]{font-size:12px}.stat-value[data-v-961c6960]{margin-top:6px;font-size:22px;font-weight:900;letter-spacing:.2px}.stat-suffix[data-v-961c6960]{margin-left:6px;font-size:12px;font-weight:600}.upgrade-banner[data-v-961c6960]{border-radius:var(--app-radius);border:1px solid var(--app-border)}.upgrade-actions[data-v-961c6960]{margin-top:10px}.panel-head[data-v-961c6960]{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:10px;flex-wrap:wrap}.panel-title[data-v-961c6960]{font-size:16px;font-weight:900}.panel-actions[data-v-961c6960]{display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end}.toolbar[data-v-961c6960]{display:flex;flex-wrap:wrap;align-items:center;gap:12px;padding:10px;border:1px dashed rgba(17,24,39,.14);border-radius:12px;background:#f6f7fb99}.toolbar-left[data-v-961c6960],.toolbar-middle[data-v-961c6960],.toolbar-right[data-v-961c6960]{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.toolbar-right[data-v-961c6960]{margin-left:auto;justify-content:flex-end}.grid[data-v-961c6960]{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:12px;align-items:start}.account-card[data-v-961c6960]{border-radius:14px;border:1px solid var(--app-border)}.card-top[data-v-961c6960]{display:flex;gap:10px}.card-check[data-v-961c6960]{padding-top:2px}.card-main[data-v-961c6960]{min-width:0;flex:1}.card-title[data-v-961c6960]{display:flex;align-items:center;justify-content:space-between;gap:10px}.card-name[data-v-961c6960]{font-size:14px;font-weight:900;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.card-sub[data-v-961c6960]{margin-top:6px;font-size:12px;line-height:1.4;word-break:break-word}.progress[data-v-961c6960]{margin-top:12px}.progress-meta[data-v-961c6960]{margin-top:6px;display:flex;justify-content:space-between;gap:10px;font-size:12px}.card-controls[data-v-961c6960]{margin-top:12px;display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.card-buttons[data-v-961c6960]{display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end}.vip-body[data-v-961c6960]{padding:12px 0 0}.vip-tip[data-v-961c6960]{margin-top:10px;font-size:13px;line-height:1.6}@media(max-width:480px){.grid[data-v-961c6960]{grid-template-columns:1fr}}@media(max-width:768px){.panel-actions[data-v-961c6960]{width:100%;justify-content:flex-end}.toolbar-left[data-v-961c6960],.toolbar-middle[data-v-961c6960],.toolbar-right[data-v-961c6960]{width:100%}.toolbar-right[data-v-961c6960]{margin-left:0;justify-content:flex-end}}
|
||||||
@@ -1 +0,0 @@
|
|||||||
.auth-wrap[data-v-c04a6b1b]{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}.auth-card[data-v-c04a6b1b]{width:100%;max-width:420px;border-radius:var(--app-radius);border:1px solid var(--app-border);box-shadow:var(--app-shadow)}.brand[data-v-c04a6b1b]{margin-bottom:14px}.brand-title[data-v-c04a6b1b]{font-size:18px;font-weight:900}.brand-sub[data-v-c04a6b1b]{margin-top:4px;font-size:12px}.links[data-v-c04a6b1b]{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:2px 0 10px;flex-wrap:wrap}.submit-btn[data-v-c04a6b1b]{width:100%}.foot[data-v-c04a6b1b]{margin-top:14px;display:flex;align-items:center;justify-content:center;gap:6px}.dialog-form[data-v-c04a6b1b]{margin-top:10px}.captcha-row[data-v-c04a6b1b]{display:flex;align-items:center;gap:10px;width:100%}.captcha-img[data-v-c04a6b1b]{height:40px;border:1px solid var(--app-border);border-radius:8px;cursor:pointer;-webkit-user-select:none;user-select:none}@media(max-width:480px){.captcha-img[data-v-c04a6b1b]{height:38px}}
|
|
||||||
1
static/app/assets/LoginPage-CnwOLKJz.css
Normal file
1
static/app/assets/LoginPage-CnwOLKJz.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.auth-wrap[data-v-9eb557e5]{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}.auth-card[data-v-9eb557e5]{width:100%;max-width:420px;border-radius:var(--app-radius);border:1px solid var(--app-border);box-shadow:var(--app-shadow)}.brand[data-v-9eb557e5]{margin-bottom:14px}.brand-title[data-v-9eb557e5]{font-size:18px;font-weight:900}.brand-sub[data-v-9eb557e5]{margin-top:4px;font-size:12px}.links[data-v-9eb557e5]{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:2px 0 10px;flex-wrap:wrap}.submit-btn[data-v-9eb557e5]{width:100%}.foot[data-v-9eb557e5]{margin-top:14px;display:flex;align-items:center;justify-content:center;gap:6px}.dialog-form[data-v-9eb557e5]{margin-top:10px}.captcha-row[data-v-9eb557e5]{display:flex;align-items:center;gap:10px;width:100%}.captcha-img[data-v-9eb557e5]{height:40px;border:1px solid var(--app-border);border-radius:8px;cursor:pointer;-webkit-user-select:none;user-select:none}@media(max-width:480px){.captcha-img[data-v-9eb557e5]{height:38px}}
|
||||||
1
static/app/assets/LoginPage-Cz6slTnR.js
Normal file
1
static/app/assets/LoginPage-Cz6slTnR.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user