feat: add export/import modes, unify service layer, fix binary detection
Export/import:
- Add --export and --import modes for both local and client paths
- Use strfmt crate for --export-filename-format templates ({id}, {tags}, {ts}, {compression})
- Import preserves original timestamps via server ?ts= param
- --import-data-file for file-based import; stdin fallback streams with PIPESIZE buffers
Service unification:
- Merge SyncDataService unique methods into ItemService (delete_item now returns Result<Item>)
- Delete AsyncDataService, AsyncItemService, DataService trait (dead code / async-blocking anti-pattern)
- All server handlers use spawn_blocking + ItemService directly
- Extract shared types (ExportMeta, ImportMeta) and helpers (resolve_item_id(s), check_binary_tty)
Binary detection fix:
- Replace broken metadata.get("map") + is_binary(&[]) with actual content sampling
- Both as_meta and allow_binary paths read PIPESIZE sample before deciding
- Never load entire item into memory for binary check
Other fixes:
- Fix lock consistency: all handlers use blocking_lock() in spawn_blocking (no mixed lock().await)
- Use ISO 8601 format for {ts} in export filenames
- Fix resolve_item_ids returning only 1 item for tag lookups
- Fix client get.rs triple-buffering and export.rs whole-file buffering
- Add KeepClient::get_item_content_stream() for streaming reads
- Pass all clippy --features server lints (Path vs PathBuf, &mut conn, etc.)
This commit is contained in:
29
src/db.rs
29
src/db.rs
@@ -292,6 +292,35 @@ pub fn create_item(
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a new item with a specific timestamp (for import).
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `conn` - Database connection.
|
||||
/// * `ts` - Timestamp to use for the item.
|
||||
/// * `compression` - Compression type string (e.g., "lz4", "gzip", "none").
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Result<Item>` - The created item with its ID set.
|
||||
pub fn insert_item_with_ts(
|
||||
conn: &Connection,
|
||||
ts: chrono::DateTime<chrono::Utc>,
|
||||
compression: &str,
|
||||
) -> Result<Item> {
|
||||
let item = Item {
|
||||
id: None,
|
||||
ts,
|
||||
size: None,
|
||||
compression: compression.to_string(),
|
||||
};
|
||||
let item_id = insert_item(conn, item.clone())?;
|
||||
Ok(Item {
|
||||
id: Some(item_id),
|
||||
..item
|
||||
})
|
||||
}
|
||||
|
||||
/// Adds a tag to an item.
|
||||
///
|
||||
/// Inserts a new tag association in the `tags` table.
|
||||
|
||||
Reference in New Issue
Block a user