This commit is contained in:
Your Name
2026-04-16 21:35:47 +08:00
parent ff32aa50bf
commit ebf632e651
86 changed files with 14097 additions and 585 deletions

View File

@@ -31,6 +31,17 @@ class Settings(BaseSettings):
worker_mode: str = "windows-local"
worker_service_name: str = "domaincheck-worker"
api_service_name: str = "domaincheck-api"
sync_agent_service_name: str = "domaincheck-sync-agent"
node_code: str = "overseas-control-01"
node_region: str = "overseas"
node_role: str = "control"
sync_push_enabled: bool = False
sync_source_region: str = "unknown"
sync_target_region: str = "overseas"
sync_target_api_base_url: str = ""
sync_shared_token: str = ""
sync_batch_size: int = 200
sync_poll_interval_seconds: int = 30
@field_validator("cors_origins", mode="before")
@classmethod

View File

@@ -15,8 +15,11 @@ def read_json(relative_path: str, default: dict | list | None = None):
path = domain_root() / relative_path
if not path.exists():
return {} if default is None else default
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
try:
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
except (json.JSONDecodeError, OSError):
return {} if default is None else default
def write_json(relative_path: str, payload) -> None:
@@ -44,8 +47,11 @@ def read_runtime_json(filename: str, default: dict | list | None = None):
path = runtime_root() / filename
if not path.exists():
return {} if default is None else default
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
try:
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
except (json.JSONDecodeError, OSError):
return {} if default is None else default
def write_runtime_json(filename: str, payload) -> None:
@@ -77,8 +83,11 @@ def load_export_records() -> list[dict]:
path = runtime_root() / "export_tasks.json"
if not path.exists():
return []
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
try:
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
except (json.JSONDecodeError, OSError):
return []
def save_export_record(record: dict) -> None:
@@ -93,8 +102,11 @@ def load_import_records() -> list[dict]:
path = runtime_root() / "import_tasks.json"
if not path.exists():
return []
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
try:
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
except (json.JSONDecodeError, OSError):
return []
def save_import_records(records: list[dict]) -> None:
@@ -103,5 +115,39 @@ def save_import_records(records: list[dict]) -> None:
json.dump(records[:200], handle, ensure_ascii=False, indent=2, default=str)
def load_juming_records() -> list[dict]:
path = runtime_root() / "juming_tasks.json"
if not path.exists():
return []
try:
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
except (json.JSONDecodeError, OSError):
return []
def save_juming_records(records: list[dict]) -> None:
path = runtime_root() / "juming_tasks.json"
with path.open("w", encoding="utf-8") as handle:
json.dump(records[:200], handle, ensure_ascii=False, indent=2, default=str)
def load_detect_records() -> list[dict]:
path = runtime_root() / "detect_runs.json"
if not path.exists():
return []
try:
with path.open("r", encoding="utf-8") as handle:
return json.load(handle)
except (json.JSONDecodeError, OSError):
return []
def save_detect_records(records: list[dict]) -> None:
path = runtime_root() / "detect_runs.json"
with path.open("w", encoding="utf-8") as handle:
json.dump(records[:200], handle, ensure_ascii=False, indent=2, default=str)
def timestamp_filename(prefix: str, ext: str) -> str:
return f"{prefix}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.{ext}"