fix: unify backend port to 18080 and make validator targets configurable

- Set default API port to 18080 in config.py
- Add configurable validation_targets to SettingsSchema and DEFAULT_SETTINGS
- Update ValidatorService to support runtime test URL updates
- Hot-reload validation_targets from DB on startup and on settings save
- Add domestic fallback URLs (baidu.com, qq.com) to reduce foreign dependency risk
- Update Settings.vue to allow adding/removing validator target URLs in UI
This commit is contained in:
祀梦
2026-04-04 22:47:54 +08:00
parent b972b64616
commit 49e440cb41
7 changed files with 107 additions and 10 deletions

View File

@@ -14,6 +14,14 @@ DEFAULT_SETTINGS = {
"proxy_expiry_days": 7,
"auto_validate": True,
"validate_interval_minutes": 30,
"validation_targets": [
"http://httpbin.org/ip",
"https://httpbin.org/ip",
"http://api.ipify.org",
"https://api.ipify.org",
"http://www.baidu.com",
"http://www.qq.com",
],
}
@@ -33,6 +41,11 @@ class SettingsRepository:
settings[key] = value.lower() == "true"
elif isinstance(default, int):
settings[key] = int(value)
elif isinstance(default, list):
try:
settings[key] = json.loads(value)
except json.JSONDecodeError:
settings[key] = default
else:
settings[key] = value
except Exception as e:
@@ -43,6 +56,10 @@ class SettingsRepository:
async def save(db: aiosqlite.Connection, settings: Dict[str, Any]) -> bool:
try:
for key, value in settings.items():
if isinstance(value, list):
stored_value = json.dumps(value, ensure_ascii=False)
else:
stored_value = str(value)
await db.execute(
"""
INSERT INTO settings (key, value, updated_at)
@@ -51,7 +68,7 @@ class SettingsRepository:
value = excluded.value,
updated_at = CURRENT_TIMESTAMP
""",
(key, str(value)),
(key, stored_value),
)
await db.commit()
return True