Add Debian deployment, MariaDB storage and randomized proxy routing
This commit is contained in:
+14
-6
@@ -1,13 +1,16 @@
|
||||
"""Project-local, non-secret configuration."""
|
||||
import json
|
||||
import threading
|
||||
import math
|
||||
import os
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
DEFAULTS = {
|
||||
"network_mode": "prefer_proxy", "pool_url": "http://127.0.0.1:5010",
|
||||
"pool_project": r"C:\Users\Jayson\Desktop\proxy_pool",
|
||||
"backup_proxies": [], "request_interval": 1.2, "timeout": 30, "retries": 3,
|
||||
"pool_project": r"C:\Users\Jayson\Desktop\proxy_pool" if os.name == "nt" else "/opt/kaoyan-studio-deploy/proxy_pool",
|
||||
"backup_proxies": [], "request_interval": 1.2, "request_interval_max": 2.4,
|
||||
"proxy_rotate_every": 0, "timeout": 30, "retries": 3,
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +40,10 @@ class SettingsStore:
|
||||
def read(self):
|
||||
with self.lock:
|
||||
values = json.loads(self.path.read_text(encoding="utf-8")) if self.path.exists() else {}
|
||||
return {**DEFAULTS, **{k: v for k, v in values.items() if k in DEFAULTS}}
|
||||
result = {**DEFAULTS, **{k: v for k, v in values.items() if k in DEFAULTS}}
|
||||
if "request_interval_max" not in values:
|
||||
result["request_interval_max"] = max(result["request_interval"], DEFAULTS["request_interval_max"])
|
||||
return result
|
||||
|
||||
def update(self, values):
|
||||
with self.lock:
|
||||
@@ -48,10 +54,12 @@ class SettingsStore:
|
||||
if parsed.scheme not in ("http", "https") or not parsed.hostname or parsed.username or parsed.password:
|
||||
raise ValueError("代理池 API 地址无效")
|
||||
values["pool_url"] = values["pool_url"].rstrip("/")
|
||||
for key, low, high in [("request_interval", .3, 60), ("timeout", 5, 120), ("retries", 1, 6)]:
|
||||
values[key] = float(values[key]) if key == "request_interval" else int(values[key])
|
||||
if not low <= values[key] <= high:
|
||||
for key, low, high in [("request_interval", .3, 60), ("request_interval_max", .3, 60), ("timeout", 5, 120), ("retries", 1, 6), ("proxy_rotate_every", 0, 100000)]:
|
||||
values[key] = float(values[key]) if key.startswith("request_interval") else int(values[key])
|
||||
if not math.isfinite(values[key]) or not low <= values[key] <= high:
|
||||
raise ValueError(f"{key} 应在 {low} 到 {high} 之间")
|
||||
if values["request_interval_max"] < values["request_interval"]:
|
||||
raise ValueError("请求间隔上限不能小于下限")
|
||||
proxies = values["backup_proxies"]
|
||||
if isinstance(proxies, str):
|
||||
proxies = proxies.splitlines()
|
||||
|
||||
Reference in New Issue
Block a user