重构代理池系统:简化架构并增强核心功能
后端变更: - 移除 tasks_manager.py 和 core/auth.py,简化架构 - 新增 core/scheduler.py 验证调度器,替代原有任务管理 - 大幅优化 api_server.py:统一错误处理、增强参数验证、支持调度器控制 - validator.py 增强 SOCKS4/SOCKS5 代理验证支持 - config.py 清理废弃配置(WebSocket、API Key、认证开关) - SQLite 数据库操作性能优化 前端变更: - 移除任务管理页面 (CrawlerTasks) 和 WebSocket 相关代码 - 路由简化为 4 个核心页面:总览、代理列表、插件管理、设置 - 提取前端工具函数(clipboard、confirm、format)和 API 类型定义 - 优化 CSS 架构:完善 variables、utilities、element-plus 样式 - Dashboard、Plugins、ProxyList、Settings 页面 UI/UX 优化 - App.vue 响应式侧边栏和页面过渡动画优化 其他: - 移除 PowerShell 启动脚本,简化 Windows 批处理脚本 - 新增 README_SOCKS.md SOCKS 代理支持文档 - .env.example 和 .gitignore 更新
This commit is contained in:
142
script/README.md
142
script/README.md
@@ -1,142 +0,0 @@
|
||||
# Proxy Pool Startup Scripts
|
||||
|
||||
## File List
|
||||
|
||||
- **start_backend.bat** - Start backend service
|
||||
- **start_frontend.bat** - Start frontend service
|
||||
- **stop_all.bat** - Stop all services
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Start Services Separately
|
||||
- Backend: Double-click `start_backend.bat`
|
||||
- Frontend: Double-click `start_frontend.bat`
|
||||
|
||||
### Stop Services
|
||||
Double-click `stop_all.bat` to stop all services
|
||||
|
||||
## Script Features
|
||||
|
||||
### Smart Process Management
|
||||
- Automatically detect and stop running processes
|
||||
- Prevent duplicate startup of multiple instances
|
||||
- Automatically clean up port conflicts
|
||||
|
||||
### Log Management
|
||||
- All output written to log files
|
||||
- Backend log: `backend.log`
|
||||
- Frontend log: `frontend.log`
|
||||
- Logs include timestamps for troubleshooting
|
||||
|
||||
### PID Management
|
||||
- Automatically record process ID to PID files
|
||||
- Facilitates subsequent service stopping
|
||||
- Automatically clean up PID files after process stops
|
||||
|
||||
### Port Cleanup
|
||||
- Automatically detect and clean up port conflicts
|
||||
- Backend port: 3000
|
||||
- Frontend port: 8080
|
||||
|
||||
## Access Addresses
|
||||
|
||||
After successful startup:
|
||||
- Backend API: http://localhost:3000
|
||||
- Frontend UI: http://localhost:8080
|
||||
|
||||
## Manual Operations
|
||||
|
||||
### View Logs
|
||||
```bash
|
||||
# View backend log
|
||||
type backend.log
|
||||
|
||||
# View frontend log
|
||||
type frontend.log
|
||||
```
|
||||
|
||||
### Manual Stop Process
|
||||
```bash
|
||||
# View PID file content
|
||||
type backend.pid
|
||||
type frontend.pid
|
||||
|
||||
# Stop process using PID
|
||||
taskkill /F /PID <ProcessID>
|
||||
```
|
||||
|
||||
### Check Port Usage
|
||||
```bash
|
||||
# Check backend port
|
||||
netstat -ano | findstr :3000
|
||||
|
||||
# Check frontend port
|
||||
netstat -ano | findstr :8080
|
||||
```
|
||||
|
||||
## Log Examples
|
||||
|
||||
### backend.log
|
||||
```
|
||||
[13:30:15.00] ========================================
|
||||
[13:30:15.00] Starting backend service...
|
||||
INFO: Started server process [12345]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
INFO: Uvicorn running on http://0.0.0.0:3000
|
||||
```
|
||||
|
||||
### frontend.log
|
||||
```
|
||||
[13:30:20.00] ========================================
|
||||
[13:30:20.00] Starting frontend service...
|
||||
VITE v5.0.0 ready in 1234 ms
|
||||
|
||||
➜ Local: http://localhost:8080/
|
||||
➜ Network: use --host to expose
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
1. **First-time frontend startup**: If dependencies are not installed, the script will automatically run `npm install`
|
||||
2. **Virtual environment**: Ensure backend uses Python virtual environment (venv)
|
||||
3. **Firewall**: Ensure firewall allows ports 3000 and 8080
|
||||
4. **Antivirus**: Some antivirus software may block scripts, need to add to whitelist
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Backend Won't Start
|
||||
1. Check if Python virtual environment is correctly installed
|
||||
2. View `backend.log` log file
|
||||
3. Confirm port 3000 is not in use
|
||||
4. Check if dependency packages are complete: `venv\Scripts\pip list`
|
||||
|
||||
### Frontend Won't Start
|
||||
1. Check if Node.js is installed: `node --version`
|
||||
2. View `frontend.log` log file
|
||||
3. Confirm port 8080 is not in use
|
||||
4. Manually install dependencies: Enter frontend directory and run `npm install`
|
||||
|
||||
### Process Won't Stop
|
||||
1. Manually find process: `tasklist | findstr python`
|
||||
2. Force stop: `taskkill /F /IM python.exe`
|
||||
3. Check port: `netstat -ano | findstr :3000`
|
||||
|
||||
## Advanced Usage
|
||||
|
||||
### Modify Ports
|
||||
- Backend: Modify port number in `api_server.py`
|
||||
- Frontend: Modify port number in `vite.config.js`
|
||||
- After modification, need to sync update port checking logic in scripts
|
||||
|
||||
### Custom Log Location
|
||||
- Modify `LOG_FILE` variable in scripts
|
||||
- Ensure directory exists and has write permissions
|
||||
|
||||
## Technical Support
|
||||
|
||||
If you encounter issues, please check:
|
||||
1. Log files (backend.log, frontend.log)
|
||||
2. PID files (backend.pid, frontend.pid)
|
||||
3. Port usage (netstat -ano)
|
||||
4. Process list (tasklist)
|
||||
@@ -1,9 +1,95 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal
|
||||
cd /d %~dp0
|
||||
echo === ProxyPool Startup ===
|
||||
echo.
|
||||
|
||||
REM Launch via PowerShell to avoid encoding issues with Chinese characters
|
||||
powershell -ExecutionPolicy Bypass -File start.ps1
|
||||
set "ROOT_PATH=%~dp0.."
|
||||
set "BACKEND_PORT=9949"
|
||||
set "FRONTEND_PORT=9948"
|
||||
|
||||
timeout /t 3
|
||||
REM 1. Clean processes on ports
|
||||
echo [1/4] Cleaning old processes...
|
||||
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":%BACKEND_PORT%" ^| findstr "LISTENING"') do (
|
||||
taskkill /F /PID %%a >nul 2>&1
|
||||
echo Stopped port %BACKEND_PORT% (PID: %%a)
|
||||
)
|
||||
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":%FRONTEND_PORT%" ^| findstr "LISTENING"') do (
|
||||
taskkill /F /PID %%a >nul 2>&1
|
||||
echo Stopped port %FRONTEND_PORT% (PID: %%a)
|
||||
)
|
||||
echo Cleanup complete!
|
||||
echo.
|
||||
|
||||
REM 2. Start Backend
|
||||
echo [2/4] Starting backend (FastAPI)...
|
||||
if exist "%ROOT_PATH%\venv\Scripts\python.exe" (
|
||||
set "PYTHON_PATH=%ROOT_PATH%\venv\Scripts\python.exe"
|
||||
echo Using venv
|
||||
) else (
|
||||
set "PYTHON_PATH=python"
|
||||
echo Using system Python
|
||||
)
|
||||
|
||||
cd /d "%ROOT_PATH%"
|
||||
set "PYTHONIOENCODING=utf-8"
|
||||
|
||||
REM Clear old logs
|
||||
if exist "%ROOT_PATH%\logs\backend_startup.log" del /f "%ROOT_PATH%\logs\backend_startup.log" >nul 2>&1
|
||||
if exist "%ROOT_PATH%\logs\backend_error.log" del /f "%ROOT_PATH%\logs\backend_error.log" >nul 2>&1
|
||||
|
||||
REM Start backend
|
||||
start /B "" "%PYTHON_PATH%" -u api_server.py >"%ROOT_PATH%\logs\backend_startup.log" 2>"%ROOT_PATH%\logs\backend_error.log"
|
||||
echo Backend started
|
||||
echo.
|
||||
|
||||
REM 3. Wait for backend
|
||||
echo [3/4] Waiting for backend...
|
||||
set RETRY_COUNT=0
|
||||
set BACKEND_READY=0
|
||||
|
||||
:WAIT_LOOP
|
||||
if %RETRY_COUNT% geq 10 goto WAIT_DONE
|
||||
timeout /t 2 /nobreak >nul
|
||||
set /a RETRY_COUNT+=1
|
||||
|
||||
ping -n 1 127.0.0.1 -w 500 >nul
|
||||
timeout /t 1 /nobreak >nul
|
||||
|
||||
REM Try to connect to backend
|
||||
powershell -Command "try { $r = Invoke-RestMethod -Uri 'http://127.0.0.1:9949/' -TimeoutSec 2 -ErrorAction Stop; exit 0 } catch { exit 1 }" >nul 2>&1
|
||||
if %errorlevel% equ 0 (
|
||||
set BACKEND_READY=1
|
||||
goto WAIT_DONE
|
||||
)
|
||||
echo Waiting... (%RETRY_COUNT%/10)
|
||||
|
||||
if exist "%ROOT_PATH%\logs\backend_startup.log" (
|
||||
for /f "delims=" %%i in ('powershell -Command "Get-Content '%ROOT_PATH%\logs\backend_startup.log' -Tail 1" 2^>nul') do (
|
||||
echo Log: %%i
|
||||
)
|
||||
)
|
||||
goto WAIT_LOOP
|
||||
|
||||
:WAIT_DONE
|
||||
if %BACKEND_READY% equ 0 (
|
||||
echo.
|
||||
echo Backend failed to start!
|
||||
echo Check error log: %ROOT_PATH%\logs\backend_error.log
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
echo Backend is ready!
|
||||
echo.
|
||||
|
||||
REM 4. Start Frontend
|
||||
echo [4/4] Starting frontend (Vite)...
|
||||
start /B "" cmd /c "cd /d "%ROOT_PATH%\frontend" && npm run dev" >nul 2>&1
|
||||
echo Frontend started
|
||||
echo.
|
||||
|
||||
echo === All services started ===
|
||||
echo Backend: http://127.0.0.1:9949
|
||||
echo Frontend: http://localhost:9948
|
||||
echo.
|
||||
echo Please open frontend in browser
|
||||
timeout /t 5 >nul
|
||||
|
||||
109
script/start.ps1
109
script/start.ps1
@@ -1,109 +0,0 @@
|
||||
# ProxyPool Startup Script
|
||||
$rootPath = Split-Path $PSScriptRoot -Parent
|
||||
|
||||
Write-Host "=== ProxyPool Startup ===" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# 1. Clean processes on ports 8923 and 6173
|
||||
Write-Host "[1/4] Cleaning old processes..." -ForegroundColor Cyan
|
||||
$ports = @(8923, 6173)
|
||||
foreach ($port in $ports) {
|
||||
try {
|
||||
$conn = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
|
||||
if ($conn) {
|
||||
$processId = $conn.OwningProcess
|
||||
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Stopped port $port (PID: $processId)" -ForegroundColor Gray
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
Write-Host " Cleanup complete!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# 2. Start Backend (FastAPI)
|
||||
Write-Host "[2/4] Starting backend (FastAPI)..." -ForegroundColor Cyan
|
||||
|
||||
$venvPython = "$rootPath\venv\Scripts\python.exe"
|
||||
if (Test-Path $venvPython) {
|
||||
$pythonPath = $venvPython
|
||||
Write-Host " Using venv: $venvPython" -ForegroundColor Green
|
||||
} else {
|
||||
$pythonPath = (Get-Command python).Source
|
||||
Write-Host " Using system Python: $pythonPath" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
$env:PYTHONIOENCODING = "utf-8"
|
||||
|
||||
$backendLog = "$rootPath\logs\backend_startup.log"
|
||||
$backendErr = "$rootPath\logs\backend_error.log"
|
||||
|
||||
# Clear old logs
|
||||
if (Test-Path $backendLog) { Remove-Item $backendLog -Force }
|
||||
if (Test-Path $backendErr) { Remove-Item $backendErr -Force }
|
||||
|
||||
# Start backend with -u flag for unbuffered output and redirect logs
|
||||
$backendProcess = Start-Process -FilePath $pythonPath -ArgumentList "-u", "api_server.py" -WorkingDirectory "$rootPath" -RedirectStandardOutput $backendLog -RedirectStandardError $backendErr -WindowStyle Hidden -PassThru
|
||||
|
||||
Write-Host " Backend started (PID: $($backendProcess.Id))" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# 3. Wait for backend to be ready (max 10 seconds)
|
||||
Write-Host "[3/4] Waiting for backend..." -ForegroundColor Cyan
|
||||
$maxRetries = 5
|
||||
$retryCount = 0
|
||||
$backendReady = $false
|
||||
|
||||
while (-not $backendReady -and $retryCount -lt $maxRetries) {
|
||||
Start-Sleep -Seconds 2
|
||||
$retryCount++
|
||||
|
||||
try {
|
||||
$response = Invoke-RestMethod -Uri "http://127.0.0.1:8923/" -Method Get -TimeoutSec 2 -ErrorAction Stop
|
||||
if ($response) {
|
||||
$backendReady = $true
|
||||
Write-Host " Backend is ready!" -ForegroundColor Green
|
||||
}
|
||||
} catch {
|
||||
$errMessage = $_.Exception.Message
|
||||
Write-Host " Waiting... ($retryCount/$maxRetries)" -ForegroundColor Yellow
|
||||
|
||||
if (Test-Path $backendLog) {
|
||||
$lastLog = Get-Content $backendLog -Tail 1 -ErrorAction SilentlyContinue
|
||||
if ($lastLog) { Write-Host " Log: $lastLog" -ForegroundColor DarkGray }
|
||||
}
|
||||
|
||||
if ($backendProcess.HasExited) {
|
||||
Write-Host " Backend process exited!" -ForegroundColor Red
|
||||
Write-Host " Exit code: $($backendProcess.ExitCode)" -ForegroundColor Red
|
||||
if (Test-Path $backendErr) {
|
||||
Write-Host "" -ForegroundColor Red
|
||||
Write-Host "Error log:" -ForegroundColor Red
|
||||
Get-Content $backendErr -Tail 20 | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
|
||||
}
|
||||
$backendReady = $false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $backendReady) {
|
||||
Write-Host "" -ForegroundColor Red
|
||||
Write-Host "Backend failed to start!" -ForegroundColor Red
|
||||
Write-Host "Check error log: $backendErr" -ForegroundColor Red
|
||||
pause
|
||||
exit
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# 4. Start Frontend (Vite)
|
||||
Write-Host "[4/4] Starting frontend (Vite)..." -ForegroundColor Cyan
|
||||
Start-Process -FilePath "cmd" -ArgumentList "/c npm run dev" -WorkingDirectory "$rootPath\frontend" -WindowStyle Hidden
|
||||
Write-Host " Frontend started" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "=== All services started ===" -ForegroundColor Cyan
|
||||
Write-Host "Backend: http://127.0.0.1:8923" -ForegroundColor Green
|
||||
Write-Host "Frontend: http://localhost:6173" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Please open frontend in browser" -ForegroundColor Magenta
|
||||
@@ -1,8 +1,41 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal
|
||||
cd /d %~dp0
|
||||
echo === Stopping ProxyPool Services ===
|
||||
echo.
|
||||
|
||||
powershell -ExecutionPolicy Bypass -File stop.ps1
|
||||
set "BACKEND_PORT=9949"
|
||||
set "FRONTEND_PORT=9948"
|
||||
set "STOPPED_COUNT=0"
|
||||
|
||||
echo [1/2] Stopping processes on ports %BACKEND_PORT% and %FRONTEND_PORT%...
|
||||
|
||||
REM Stop backend port
|
||||
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":%BACKEND_PORT%" ^| findstr "LISTENING"') do (
|
||||
for /f "tokens=1" %%b in ('tasklist /FI "PID eq %%a" ^| findstr "%%a"') do (
|
||||
taskkill /F /PID %%a >nul 2>&1
|
||||
echo Stopped port %BACKEND_PORT% (PID: %%a, Process: %%b)
|
||||
set /a STOPPED_COUNT+=1
|
||||
)
|
||||
)
|
||||
|
||||
REM Stop frontend port
|
||||
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":%FRONTEND_PORT%" ^| findstr "LISTENING"') do (
|
||||
for /f "tokens=1" %%b in ('tasklist /FI "PID eq %%a" ^| findstr "%%a"') do (
|
||||
taskkill /F /PID %%a >nul 2>&1
|
||||
echo Stopped port %FRONTEND_PORT% (PID: %%a, Process: %%b)
|
||||
set /a STOPPED_COUNT+=1
|
||||
)
|
||||
)
|
||||
|
||||
echo Stopped %STOPPED_COUNT% process(es)
|
||||
echo.
|
||||
|
||||
echo [2/2] Waiting for processes to fully stop...
|
||||
timeout /t 2 /nobreak >nul
|
||||
|
||||
echo.
|
||||
echo === Done ===
|
||||
echo All services have been stopped.
|
||||
echo.
|
||||
|
||||
pause
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
# ProxyPool Stop Script
|
||||
$rootPath = Split-Path $PSScriptRoot -Parent
|
||||
|
||||
Write-Host "=== Stopping ProxyPool Services ===" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "[1/2] Stopping processes on ports 8923 and 6173..." -ForegroundColor Cyan
|
||||
$ports = @(8923, 6173)
|
||||
$stoppedCount = 0
|
||||
|
||||
foreach ($port in $ports) {
|
||||
try {
|
||||
$conn = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
|
||||
if ($conn) {
|
||||
$processId = $conn.OwningProcess
|
||||
|
||||
try {
|
||||
$process = Get-Process -Id $processId -ErrorAction SilentlyContinue
|
||||
if ($process) {
|
||||
$processName = $process.ProcessName
|
||||
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host " Stopped port $port (PID: $processId, Process: $processName)" -ForegroundColor Gray
|
||||
$stoppedCount++
|
||||
}
|
||||
} catch {
|
||||
Write-Host " Warning: Could not stop process on port $port (PID: $processId)" -ForegroundColor Yellow
|
||||
}
|
||||
} else {
|
||||
Write-Host " Port ${port}: No process found" -ForegroundColor DarkGray
|
||||
}
|
||||
} catch {
|
||||
Write-Host " Error checking port ${port}: $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host " Stopped $stoppedCount process(es)" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "[2/2] Waiting for processes to fully stop..." -ForegroundColor Cyan
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=== Done ===" -ForegroundColor Cyan
|
||||
Write-Host "All services have been stopped." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Reference in New Issue
Block a user