优化: 项目管理阻塞去重 + normalize_path/白名单抽公共
- collect_sample/detect_stack 三处包 spawn_blocking 防 async 阻塞 + bind_directory 补漏一处 - normalize_path 抽公共到 df-project/scan(删 project.rs 本地 + tool_registry inline 闭包) - tool_registry update_project 复用 crud is_allowed_column(删硬编码白名单,与 CRUD 同源) Sprint 20 审查 ③④⑤。todo 记 A/B 验证发现的 2 项非阻断(T-09 idea 补偿删级联 / T-10 normalize_path 同步)
This commit is contained in:
@@ -10,6 +10,19 @@ use std::path::Path;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
/// 规范化路径用于比较:canonicalize 解析绝对规范路径(失败降级),
|
||||
/// 统一正斜杠 + 小写。防 `C:\a\b` vs `C:/a/b/` 绕过重复检查。
|
||||
/// 注:仅用于比较,存库保留用户输入的原始可读路径。
|
||||
pub fn normalize_path(p: &str) -> String {
|
||||
match Path::new(p).canonicalize() {
|
||||
Ok(abs) => abs.to_string_lossy().replace('\\', "/").to_lowercase(),
|
||||
Err(_) => p
|
||||
.trim_end_matches(['\\', '/'])
|
||||
.replace('\\', "/")
|
||||
.to_lowercase(),
|
||||
}
|
||||
}
|
||||
|
||||
/// 探测目录的技术栈
|
||||
///
|
||||
/// 返回去重后的技术栈标签数组(如 `["rust","vue","tauri","typescript"]`)。
|
||||
|
||||
@@ -278,7 +278,7 @@ impl SettingsRepo {
|
||||
/// projects 的 "name" 会在校验阶段拒绝,而非靠 SQLite "no such column" 兜底报错)。
|
||||
/// 专用更新路径的列不列入:knowledges.embedding(set_embedding)、projects.deleted_at
|
||||
/// (soft_delete/restore)。未登记的表返回 None → 放行(仅靠参数化防注入,向后兼容)。
|
||||
fn allowed_columns_for(table: &str) -> Option<&'static [&'static str]> {
|
||||
pub fn allowed_columns_for(table: &str) -> Option<&'static [&'static str]> {
|
||||
Some(match table {
|
||||
"ideas" => &[
|
||||
"id", "title", "description", "status", "priority", "score", "tags", "source",
|
||||
@@ -339,6 +339,16 @@ fn validate_column_name(field: &str, table: &str) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 是否允许更新某表的某列(按表隔离白名单)。未登记表返回 false(保守拒绝,防误传)。
|
||||
///
|
||||
/// 供 AI 工具层等外部调用方复用 CRUD 白名单,避免双份字段列表不同步。
|
||||
pub fn is_allowed_column(table: &str, field: &str) -> bool {
|
||||
match allowed_columns_for(table) {
|
||||
Some(cols) => cols.contains(&field),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 时间工具
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user