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:
+6
-14
@@ -249,8 +249,7 @@ pub(crate) async fn register_single_file(
|
|||||||
.map(|n| n.to_string_lossy().to_string())
|
.map(|n| n.to_string_lossy().to_string())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR")
|
let output_dir = crate::core::config::OUTPUT_DIR.to_string();
|
||||||
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string());
|
|
||||||
|
|
||||||
let birthday = std::fs::metadata(&path)
|
let birthday = std::fs::metadata(&path)
|
||||||
.ok()
|
.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 {
|
let temp_probe_json: serde_json::Value = if let Some(ref pre) = pre_data {
|
||||||
pre.get("probe_json").cloned().unwrap_or_default()
|
pre.get("probe_json").cloned().unwrap_or_default()
|
||||||
} else {
|
} else {
|
||||||
let scripts_dir = std::env::var("MOMENTRY_SCRIPTS_DIR")
|
let scripts_dir = crate::core::path_utils::scripts_dir().to_string_lossy().to_string();
|
||||||
.unwrap_or_else(|_| "/Users/accusys/momentry_core_0.1/scripts".to_string());
|
|
||||||
let python_path = std::env::var("MOMENTRY_PYTHON_PATH")
|
let python_path = std::env::var("MOMENTRY_PYTHON_PATH")
|
||||||
.unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string());
|
.unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string());
|
||||||
crate::core::probe::unified::unified_probe(&path, &scripts_dir, &python_path).await
|
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;
|
let mut cut_done = false;
|
||||||
if has_video && total_frames > 0 && fps > 0.0 {
|
if has_video && total_frames > 0 && fps > 0.0 {
|
||||||
let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR")
|
let output_dir = crate::core::config::OUTPUT_DIR.to_string();
|
||||||
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string());
|
let scripts_dir = crate::core::path_utils::scripts_dir().to_string_lossy().to_string();
|
||||||
let scripts_dir = std::env::var("MOMENTRY_SCRIPTS_DIR")
|
|
||||||
.unwrap_or_else(|_| "/Users/accusys/momentry_core_0.1/scripts".to_string());
|
|
||||||
let python_path = std::env::var("MOMENTRY_PYTHON_PATH")
|
let python_path = std::env::var("MOMENTRY_PYTHON_PATH")
|
||||||
.unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string());
|
.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 audio_tracks_json = serde_json::to_value(&audio_tracks).ok();
|
||||||
let cut_path = std::path::Path::new(
|
let cut_path = std::path::Path::new(
|
||||||
&std::env::var("MOMENTRY_OUTPUT_DIR")
|
&crate::core::config::OUTPUT_DIR.to_string(),
|
||||||
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()),
|
|
||||||
)
|
)
|
||||||
.join(format!("{}.cut.json", file_uuid));
|
.join(format!("{}.cut.json", file_uuid));
|
||||||
let mut cut_count = 0i32;
|
let mut cut_count = 0i32;
|
||||||
@@ -607,8 +602,7 @@ pub(crate) async fn register_single_file(
|
|||||||
|
|
||||||
if let Some(json_val) = probe_json {
|
if let Some(json_val) = probe_json {
|
||||||
let probe_path = std::path::Path::new(
|
let probe_path = std::path::Path::new(
|
||||||
&std::env::var("MOMENTRY_OUTPUT_DIR")
|
&crate::core::config::OUTPUT_DIR.to_string(),
|
||||||
.unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()),
|
|
||||||
)
|
)
|
||||||
.join(format!("{}.probe.json", file_uuid));
|
.join(format!("{}.probe.json", file_uuid));
|
||||||
let json_str = serde_json::to_string_pretty(&json_val).unwrap_or_default();
|
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
|
// Check multiple output directories
|
||||||
let output_dirs = [
|
let output_dirs = [
|
||||||
config::OUTPUT_DIR.to_string(),
|
config::OUTPUT_DIR.to_string(),
|
||||||
// Legacy paths for backward compatibility during migration
|
|
||||||
"/Users/accusys/momentry/output".to_string(),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
for output_dir in &output_dirs {
|
for output_dir in &output_dirs {
|
||||||
|
|||||||
Reference in New Issue
Block a user