fix: unregistered 卡片確保有 size/mdate — MarkBase fallback + 磁碟掃描補齊 + formatSize/formatDate 顯示 '—' 替代空白
This commit is contained in:
+44
-2
@@ -236,6 +236,19 @@ async fn list_files(
|
||||
format!("{}/{}", default_root, name)
|
||||
})
|
||||
});
|
||||
// Fallback: use filesystem metadata when MarkBase data is unavailable
|
||||
let file_size = if mb_file.size > 0 {
|
||||
Some(mb_file.size)
|
||||
} else {
|
||||
std::fs::metadata(&file_path).ok().map(|m| m.len())
|
||||
};
|
||||
let modified_time = if !mb_file.modified.is_empty() {
|
||||
Some(mb_file.modified)
|
||||
} else {
|
||||
std::fs::metadata(&file_path).ok()
|
||||
.and_then(|m| m.modified().ok())
|
||||
.map(|t| chrono::DateTime::<chrono::Utc>::from(t).to_rfc3339())
|
||||
};
|
||||
all_files.push(FileItem {
|
||||
file_uuid: mb_file.file_uuid.unwrap_or_default(),
|
||||
file_name: name,
|
||||
@@ -243,8 +256,8 @@ async fn list_files(
|
||||
status: "unregistered".to_string(),
|
||||
is_registered: false,
|
||||
total_chunks: 0,
|
||||
file_size: Some(mb_file.size),
|
||||
modified_time: Some(mb_file.modified),
|
||||
file_size,
|
||||
modified_time,
|
||||
thumbnail_url: None,
|
||||
});
|
||||
}
|
||||
@@ -278,6 +291,35 @@ async fn list_files(
|
||||
}
|
||||
}
|
||||
|
||||
// Scan filesystem for files not in MarkBase AND not in DB (true unregistered)
|
||||
for (_, dir_path) in &upload_paths {
|
||||
if let Ok(entries) = std::fs::read_dir(dir_path) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if !path.is_file() { continue }
|
||||
let name = entry.file_name().to_string_lossy().to_string();
|
||||
let name_lower = name.to_lowercase();
|
||||
if name_lower == ".ds_store" || name_lower.ends_with(".sqlite") { continue }
|
||||
if all_names.contains(&name) { continue }
|
||||
// Check all paths (including MarkBase paths)
|
||||
if all_paths.contains(&path.to_string_lossy().to_string()) { continue }
|
||||
let meta = entry.metadata().ok();
|
||||
all_files.push(FileItem {
|
||||
file_uuid: String::new(),
|
||||
file_name: name,
|
||||
file_path: path.to_string_lossy().to_string(),
|
||||
status: "unregistered".to_string(),
|
||||
is_registered: false,
|
||||
total_chunks: 0,
|
||||
file_size: meta.as_ref().map(|m| m.len()),
|
||||
modified_time: meta.and_then(|m| m.modified().ok())
|
||||
.map(|t| chrono::DateTime::<chrono::Utc>::from(t).to_rfc3339()),
|
||||
thumbnail_url: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Add thumbnail URLs for all video files
|
||||
for file in &mut all_files {
|
||||
|
||||
Reference in New Issue
Block a user