feat: add streaming tar export/import and rename "none" to "raw"

- Add streaming tar-based export (--export produces .keep.tar)
- Add streaming tar import (--import reads .keep.tar archives)
- Add server endpoints GET /api/export and POST /api/import
- Rename CompressionType::None to CompressionType::Raw with "none" as alias
- Add DB migration to update existing "none" compression values to "raw"
- Fix export endpoint to propagate errors to client instead of swallowing
- Fix import endpoint to return 413 on max_body_size instead of truncating

Export streams items as tar archives without loading entire files into memory.
Import extracts items with new IDs, preserving original order. Both work
locally and via client/server mode.

Co-Authored-By: opencode <noreply@opencode.ai>
This commit is contained in:
2026-03-17 21:24:39 -03:00
parent 074ba64805
commit 49793a0f94
36 changed files with 1413 additions and 189 deletions

View File

@@ -0,0 +1,94 @@
#[cfg(test)]
mod export_tar_tests {
use crate::db::{Item, Meta, Tag};
use crate::export_tar::{common_tags, export_name};
use crate::services::types::ItemWithMeta;
use chrono::Utc;
fn make_item_with_tags(id: i64, tags: Vec<&str>) -> ItemWithMeta {
ItemWithMeta {
item: Item {
id: Some(id),
ts: Utc::now(),
size: Some(100),
compression: "raw".to_string(),
},
tags: tags
.into_iter()
.map(|t| Tag {
id: 0,
name: t.to_string(),
})
.collect(),
meta: Vec::new(),
}
}
#[test]
fn test_common_tags_empty() {
let items: Vec<ItemWithMeta> = Vec::new();
assert!(common_tags(&items).is_empty());
}
#[test]
fn test_common_tags_single_item() {
let items = vec![make_item_with_tags(1, vec!["foo", "bar"])];
let tags = common_tags(&items);
assert_eq!(tags, vec!["bar", "foo"]);
}
#[test]
fn test_common_tags_intersection() {
let items = vec![
make_item_with_tags(1, vec!["foo", "bar", "baz"]),
make_item_with_tags(2, vec!["foo", "bar", "qux"]),
make_item_with_tags(3, vec!["foo", "baz"]),
];
let tags = common_tags(&items);
assert_eq!(tags, vec!["foo"]);
}
#[test]
fn test_common_tags_no_intersection() {
let items = vec![
make_item_with_tags(1, vec!["foo"]),
make_item_with_tags(2, vec!["bar"]),
];
let tags = common_tags(&items);
assert!(tags.is_empty());
}
#[test]
fn test_export_name_with_arg() {
let items = vec![make_item_with_tags(1, vec!["foo"])];
let name = export_name(&Some("mybackup".to_string()), &items);
assert_eq!(name, "mybackup");
}
#[test]
fn test_export_name_default_with_tags() {
let items = vec![
make_item_with_tags(1, vec!["foo", "bar"]),
make_item_with_tags(2, vec!["foo", "baz"]),
];
let name = export_name(&None, &items);
assert_eq!(name, "export_foo");
}
#[test]
fn test_export_name_default_no_common_tags() {
let items = vec![
make_item_with_tags(1, vec!["foo"]),
make_item_with_tags(2, vec!["bar"]),
];
let name = export_name(&None, &items);
assert_eq!(name, "export");
}
#[test]
fn test_export_name_default_empty() {
let items: Vec<ItemWithMeta> = Vec::new();
let name = export_name(&None, &items);
assert_eq!(name, "export");
}
}