fix: 配置导入导出版本号统一常量管理,移除前端硬编码版本校验

This commit is contained in:
RWDai
2026-02-11 17:06:06 +08:00
parent 257077a59b
commit 3a5d687f08
2 changed files with 9 additions and 7 deletions

View File

@@ -1795,9 +1795,9 @@ function handleConfigFileSelect(event: Event) {
const content = e.target?.result as string
const data = JSON.parse(content) as ConfigExportData
// 验证版本(支持 2.0 和 2.1
if (!['2.0', '2.1'].includes(data.version)) {
error(`不支持的配置版本: ${data.version}`)
// 基本格式验证:确保有版本字段
if (!data.version) {
error('无效的配置文件:缺少版本信息')
return
}

View File

@@ -1067,7 +1067,7 @@ class AdminExportConfigAdapter(AdminApiAdapter):
)
return {
"version": "2.2",
"version": CONFIG_EXPORT_VERSION,
"exported_at": datetime.now(timezone.utc).isoformat(),
"global_models": global_models_data,
"providers": providers_data,
@@ -1077,6 +1077,8 @@ class AdminExportConfigAdapter(AdminApiAdapter):
}
CONFIG_EXPORT_VERSION = "2.2"
CONFIG_SUPPORTED_VERSIONS = ("2.0", "2.1", "2.2")
MAX_IMPORT_SIZE = 10 * 1024 * 1024 # 10MB
@@ -1133,10 +1135,10 @@ class AdminImportConfigAdapter(AdminApiAdapter):
db = context.db
payload = context.ensure_json_body()
# 验证配置版本(支持 2.0、2.1 和 2.2
# 验证配置版本
version = payload.get("version")
if version not in ("2.0", "2.1", "2.2"):
raise InvalidRequestException(f"不支持的配置版本: {version}")
if version not in CONFIG_SUPPORTED_VERSIONS:
raise InvalidRequestException(f"不支持的配置版本: {version},支持的版本: {', '.join(CONFIG_SUPPORTED_VERSIONS)}")
# 获取导入选项
merge_mode = payload.get("merge_mode", "skip") # skip, overwrite, error