feat: 支持托管到Metrix应用包并移除授权与平台模式

- 新增 scripts/package_metrix.py 打包应用包(user_auth=metrix、admin_auth=none、数据目录 /data)
- 托管模式只认平台代理身份,停用应用登录与改密码,新增 /api/session
- 后端按 X-Forwarded-Prefix 注入 <base href>,前端改为相对路径构建并按 basePath 请求
- 托管时隐藏登录页、退出按钮和修改密码页,顶栏显示 Metrix 用户名
- 移除授权到期校验、激活码和连点品牌图标打开的授权延期窗口
- 移除 Metrix 平台数据源/仓库模式及相关配置、接口、设置页和 requests 依赖
- 新增托管鉴权与 base href 注入测试,更新使用与开发文档
This commit is contained in:
2026-11-06 16:22:32 +08:00
parent 488c5406c4
commit 22fbf47577
45 changed files with 548 additions and 2195 deletions
+13 -35
View File
@@ -1,4 +1,3 @@
import time
from datetime import date, datetime
from pathlib import Path
from threading import Thread
@@ -7,32 +6,23 @@ from typing import Any, Callable, Iterable
from fastapi import APIRouter, Body, HTTPException
from app import state
from app.api.routers.task_runtime import (
apply_history_retention_safely,
log_license_check,
set_task_stage,
)
from app.api.routers.task_runtime import apply_history_retention_safely, set_task_stage
from app.config import AppConfig, CACHE_DIR, RemoteDataConfig
from app.processor import DataProcessor, ProcessLogger
from app.config import CELLDATA_SCRIPT
from app.services.cell_data import copy_celldata_tables_to_capacity, execute_celldata_script, refresh_cell_data
from app.services.license import LicenseError, check_processing_allowed
from app.services.platform import PlatformStorageDownloader, make_source_downloader
from app.services.pipeline import RESULT_TABLES, run_import_and_report
from app.services.remote_download import RemoteDataDownloader
router = APIRouter(tags=["remote"])
RESULT_TABLES = ["4G_结果表", "5G_结果表"]
@router.post("/api/remote/test")
def test_remote_connection(config: dict[str, Any] | None = Body(None)):
app_config = state.current_config()
try:
if app_config.source_type == "metrix":
PlatformStorageDownloader(app_config).test_connection()
return {"success": True, "message": "平台储存连接成功"}
# FTP/SFTP: test the posted form config if provided, else the saved one.
# Test the posted form config if provided, else the saved one.
remote_config = RemoteDataConfig.from_dict(config) if config else app_config.remote_data
RemoteDataDownloader(remote_config).test_connection()
return {"success": True, "message": "远程服务器连接成功"}
@@ -133,14 +123,11 @@ def _run_remote_processing(
) -> None:
final_status = "failed"
try:
if app_config.source_type == "metrix":
logger.info(f"开始从平台储存下载,目录: {remote_config.remote_dir}")
else:
logger.info(
f"开始远程下载,协议: {remote_config.protocol.upper()},"
f"服务器: {remote_config.host}:{remote_config.port},目录: {remote_config.remote_dir}"
)
downloader = make_source_downloader(app_config, logger.info)
logger.info(
f"开始远程下载,协议: {remote_config.protocol.upper()},"
f"服务器: {remote_config.host}:{remote_config.port},目录: {remote_config.remote_dir}"
)
downloader = RemoteDataDownloader(remote_config, logger.info)
download_result = downloader.download_to(work_dir, target_dates=target_dates)
logger.success(
f"下载完成,共 {download_result.file_count} 个文件,"
@@ -154,18 +141,11 @@ def _run_remote_processing(
_try_refresh_cell_data(app_config, work_dir, logger)
if app_config.warehouse_type == "metrix":
started = time.time()
run_import_and_report(work_dir, app_config, logger)
status, error, elapsed = "completed", None, round(time.time() - started, 2)
else:
logger.set_stage("license")
log_license_check(logger, check_processing_allowed(work_dir))
processor = DataProcessor(app_config, work_dir, logger)
result = processor.process()
status = "completed" if result.get("success") else "failed"
error = result.get("error")
elapsed = result.get("elapsed_time", 0)
processor = DataProcessor(app_config, work_dir, logger)
result = processor.process()
status = "completed" if result.get("success") else "failed"
error = result.get("error")
elapsed = result.get("elapsed_time", 0)
if status == "completed" and remote_config.auto_delete_source:
try:
deleted_count = downloader.delete_source_files(download_result.remote_files)
@@ -191,7 +171,6 @@ def _run_remote_processing(
"error": error,
}
except Exception as exc:
error_detail = exc.to_detail() if isinstance(exc, LicenseError) else None
if source == "scheduler":
logger.error(f"自动调度任务失败: {exc}")
else:
@@ -202,7 +181,6 @@ def _run_remote_processing(
"status": "failed",
"stage": "failed",
"error": str(exc),
"error_detail": error_detail,
}
finally:
apply_history_retention_safely()