fix(database): close canonical restore review gaps

This commit is contained in:
SaladDay
2026-08-01 14:12:08 +00:00
parent 9a87512224
commit 89961dff28
4 changed files with 902 additions and 91 deletions
+28 -1
View File
@@ -100,6 +100,23 @@ pub(crate) fn validate_provider_storage_json(
if let Some(source) = meta.pricing_model_source.as_deref() {
super::proxy::validate_pricing_source(source)?;
}
for (field, value) in [
("limitDailyUsd", meta.limit_daily_usd.as_deref()),
("limitMonthlyUsd", meta.limit_monthly_usd.as_deref()),
] {
if let Some(value) = value {
let parsed = value.parse::<rust_decimal::Decimal>().map_err(|error| {
AppError::InvalidInput(format!(
"invalid provider meta {field} for '{app_type}/{provider_id}': {error}"
))
})?;
if parsed < rust_decimal::Decimal::ZERO {
return Err(AppError::InvalidInput(format!(
"negative provider meta {field} for '{app_type}/{provider_id}'"
)));
}
}
}
Ok(())
}
@@ -495,7 +512,17 @@ impl Database {
|row| row.get(0),
)
.map_err(|e| AppError::Database(e.to_string()))?;
Ok(max.map(|v| (v + 1) as usize).unwrap_or(0))
match max {
Some(value) => value
.checked_add(1)
.and_then(|next| usize::try_from(next).ok())
.ok_or_else(|| {
AppError::InvalidInput(format!(
"provider sort_index cannot advance past {value}"
))
}),
None => Ok(0),
}
}
/// 启动时调用:补齐缺失的官方预设供应商(Claude / Codex / Gemini)。