subx_cli/core/matcher/
cache.rs

1use serde::{Deserialize, Serialize};
2
3/// 檔案快照項目,用於比對目錄檔案狀態
4#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
5pub struct SnapshotItem {
6    pub name: String,
7    pub size: u64,
8    pub mtime: u64,
9    pub file_type: String,
10}
11
12/// 單筆匹配操作快取結構
13#[derive(Debug, Serialize, Deserialize, Clone)]
14pub struct OpItem {
15    pub video_file: String,
16    pub subtitle_file: String,
17    pub new_subtitle_name: String,
18    pub confidence: f32,
19    pub reasoning: Vec<String>,
20}
21
22/// Dry-run 快取資料結構
23#[derive(Debug, Serialize, Deserialize, Clone)]
24pub struct CacheData {
25    pub cache_version: String,
26    pub directory: String,
27    pub file_snapshot: Vec<SnapshotItem>,
28    pub match_operations: Vec<OpItem>,
29    pub created_at: u64,
30    pub ai_model_used: String,
31    pub config_hash: String,
32}
33
34impl CacheData {
35    /// 從檔案載入快取資料
36    pub fn load(path: &std::path::Path) -> Result<Self, anyhow::Error> {
37        let content = std::fs::read_to_string(path)?;
38        let data = serde_json::from_str(&content)?;
39        Ok(data)
40    }
41}