feat(storage): data.json 备份/资产骤减保护 + 缩略图批量读(Rust 批次 A2)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 54s

This commit is contained in:
qiqi committed 2026-12-05 18:51:33 +08:00
1 parent 352b2e0fe6
commit 0416bac128
9 files changed
+208 -11

No files matched your search

+29
View File
@@ -419,6 +419,34 @@ async fn list_dir_entries(base: String, rel: String) -> Result<Vec<DirEntryInfo>
}
#[derive(serde::Serialize)]
struct FileB64 {
rel: String,
b64: Option<String>,
error: Option<String>,
}
#[tauri::command]
async fn read_files_b64(base: String, rels: Vec<String>) -> Result<Vec<FileB64>, String> {
use base64::Engine;
let base_path = std::path::PathBuf::from(&base);
let mut out = Vec::with_capacity(rels.len());
for rel in rels {
let mut item = FileB64 { rel: rel.clone(), b64: None, error: None };
match resolve_under(&base_path, &rel) {
Some(abs) => match tokio::fs::read(&abs).await {
Ok(bytes) => item.b64 = Some(base64::engine::general_purpose::STANDARD.encode(bytes)),
Err(e) => item.error = Some(e.to_string()),
},
None => item.error = Some("bad-path".to_string()),
}
out.push(item);
}
Ok(out)
}
// 2026-12-04(文件版下载,默认关闭):流式写文件,避免整包 base64 过 IPC。
// 目标路径由 JS 提供(资料目录下的 cache/tmp/),这里只负责抓字节 + 落盘;失败会删半成品。
#[tauri::command]
@@ -2296,6 +2324,7 @@ pub fn run() {
stat_many,
read_text_many,
list_dir_entries,
read_files_b64,
])
.setup(|app| {
if cfg!(debug_assertions) {