fix: FAT32 文件系统修改时间读取失败导致转码报错;更新 useLocalVideo 注释

This commit is contained in:
小鱼开发
2026-05-21 15:58:05 +08:00
parent 666842ce2b
commit 59bfadcb99
2 changed files with 7 additions and 5 deletions
+3 -2
View File
@@ -740,9 +740,10 @@ pub async fn transcode_for_preview(app: &AppHandle, input_path: &str) -> Result<
// 获取文件元数据用于缓存 key
let metadata = std::fs::metadata(input_path)
.map_err(|e| format!("无法读取文件元数据: {}", e))?;
// 某些文件系统(如 FAT32)不支持修改时间,失败时回退为 0
let mtime = metadata.modified()
.map_err(|e| format!("无法读取修改时间: {}", e))?
.duration_since(std::time::UNIX_EPOCH)
.ok()
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
.unwrap_or_default()
.as_secs();
let file_size = metadata.len();
+4 -3
View File
@@ -2,7 +2,8 @@
* 本地视频加载 Hook
* =================
*
* 使Rust Command 路径校验 + convertFileSrc 安全访问本地视频文件
* getPreviewVideoUrl 获取浏览器兼容的预览视频 URL
* 首次加载时后台自动转码(H.264 Baseline + YUV420p),缓存后复用。
* 替代原有的 readFile + Blob URL 模式,零内存拷贝,支持 video 标签流式播放与 seek。
*/
@@ -16,10 +17,10 @@ interface UseLocalVideoResult {
}
/**
* 加载本地视频文件,返回 asset:// URL
* 加载本地视频文件,返回预览用的 asset:// URL
*
* @param filePath 本地文件绝对路径(如 /Users/.../scene_1.mp4
* @returns asset:// URL 或 undefined
* @returns 转码后的 asset:// URL 或 undefined(远程 URL 直接返回)
*/
export function useLocalVideo(filePath: string | undefined): UseLocalVideoResult {
const [videoUrl, setVideoUrl] = useState<string | undefined>(undefined);