fix(mcp): reveal/revoke 令牌时将字符串 id 解析为 Uuid

reveal_mcp_token / revoke_mcp_token 把前端传来的 String id 直接绑到
$1::uuid,tokio-postgres 解析参数类型为 uuid 后拒绝 String,报
'cannot convert between the Rust type String and the Postgres type uuid'
导致 /api/reveal_mcp_token 500。

参照 assets/delete.rs 的做法,绑定前用 uuid::Uuid::parse_str 转换;
解析失败按令牌不存在处理(reveal 返回 None、revoke 静默无操作),
与函数既有的'避免探测'语义一致。
This commit is contained in:
xfy 2026-07-28 14:42:14 +08:00
parent e6f7704367
commit 60360f6b49

View File

@ -177,6 +177,12 @@ pub async fn reveal_mcp_token(id: String) -> Result<Option<String>, ServerFnErro
let admin = get_current_admin_user().await?;
let client = get_conn().await.map_err(AppError::db_conn)?;
// id 由前端以字符串传入(表 id 列是 uuid解析失败视作令牌不存在。
let id = match uuid::Uuid::parse_str(&id) {
Ok(u) => u,
Err(_) => return Ok(None),
};
// 仅取属于当前管理员的令牌的密文,避免越权解密他人令牌。
let row = client
.query_opt(
@ -210,6 +216,12 @@ pub async fn revoke_mcp_token(id: String) -> Result<(), ServerFnError> {
let admin = get_current_admin_user().await?;
let client = get_conn().await.map_err(AppError::db_conn)?;
// id 解析失败视作令牌不存在(静默无操作,避免探测)。
let id = match uuid::Uuid::parse_str(&id) {
Ok(u) => u,
Err(_) => return Ok(()),
};
client
.execute(
"UPDATE mcp_tokens SET revoked_at = NOW() \