fix: replace all hardcoded paths in files.rs (A-4.2 P3)

Issues: 7 hardcoded fallback paths
- 5× output_dir: /Users/accusys/momentry/output
- 2× scripts_dir: /Users/accusys/momentry_core_0.1/scripts

Solution: Use config constants and path_utils
- config::OUTPUT_DIR for output paths
- path_utils::scripts_dir() for scripts paths

Changes:
- Replaced all unwrap_or_else fallbacks
- Unified path resolution

Verification: cargo check --lib passes, 0 hardcoded paths remaining

Progress: files.rs ✅, admin_config.rs ✅

Remaining: ~24 P3 locations in other files
This commit is contained in:
Accusys
2026-10-04 16:18:42 +08:00
parent b4dec14f8d
commit 1166599f70
+6 -14
View File
@@ -249,8 +249,7 @@ pub(crate) async fn register_single_file(
.map(|n| n.to_string_lossy().to_string())
.unwrap_or_default();
let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string());
let output_dir = crate::core::config::OUTPUT_DIR.to_string();
let birthday = std::fs::metadata(&path)
.ok()
@@ -411,8 +410,7 @@ pub(crate) async fn register_single_file(
let temp_probe_json: serde_json::Value = if let Some(ref pre) = pre_data {
pre.get("probe_json").cloned().unwrap_or_default()
} else {
let scripts_dir = std::env::var("MOMENTRY_SCRIPTS_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry_core_0.1/scripts".to_string());
let scripts_dir = crate::core::path_utils::scripts_dir().to_string_lossy().to_string();
let python_path = std::env::var("MOMENTRY_PYTHON_PATH")
.unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string());
crate::core::probe::unified::unified_probe(&path, &scripts_dir, &python_path).await
@@ -507,10 +505,8 @@ pub(crate) async fn register_single_file(
let mut cut_done = false;
if has_video && total_frames > 0 && fps > 0.0 {
let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string());
let scripts_dir = std::env::var("MOMENTRY_SCRIPTS_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry_core_0.1/scripts".to_string());
let output_dir = crate::core::config::OUTPUT_DIR.to_string();
let scripts_dir = crate::core::path_utils::scripts_dir().to_string_lossy().to_string();
let python_path = std::env::var("MOMENTRY_PYTHON_PATH")
.unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string());
@@ -574,8 +570,7 @@ pub(crate) async fn register_single_file(
});
let audio_tracks_json = serde_json::to_value(&audio_tracks).ok();
let cut_path = std::path::Path::new(
&std::env::var("MOMENTRY_OUTPUT_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()),
&crate::core::config::OUTPUT_DIR.to_string(),
)
.join(format!("{}.cut.json", file_uuid));
let mut cut_count = 0i32;
@@ -607,8 +602,7 @@ pub(crate) async fn register_single_file(
if let Some(json_val) = probe_json {
let probe_path = std::path::Path::new(
&std::env::var("MOMENTRY_OUTPUT_DIR")
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()),
&crate::core::config::OUTPUT_DIR.to_string(),
)
.join(format!("{}.probe.json", file_uuid));
let json_str = serde_json::to_string_pretty(&json_val).unwrap_or_default();
@@ -1188,8 +1182,6 @@ fn delete_output_files(uuid: &str) -> u64 {
// Check multiple output directories
let output_dirs = [
config::OUTPUT_DIR.to_string(),
// Legacy paths for backward compatibility during migration
"/Users/accusys/momentry/output".to_string(),
];
for output_dir in &output_dirs {