dove_core/transfer.rs
1//! The transfer seam: the operations every backend (self-hosted S3 today, a
2//! future hosted cloud backend later) must implement. The CLI and the Dove
3//! desktop app drive shares through this trait instead of talking to S3
4//! directly, so a new backend plugs in without either caller changing.
5
6use crate::error::Result;
7use crate::progress::Progress;
8use std::path::PathBuf;
9use std::time::Duration;
10
11/// What to share: a resolved local path plus the policy for the resulting link.
12pub struct ShareRequest {
13 pub path: PathBuf,
14 pub expires: Duration,
15 pub encrypt: bool,
16 pub downloads: Option<u32>,
17 pub pin: Option<String>,
18 pub from: Option<String>,
19 pub message: Option<String>,
20}
21
22/// The result of a successful share: the link to hand out, plus what got recorded.
23pub struct Share {
24 pub id: String,
25 pub link: String,
26 pub size: u64,
27 pub expires_at: u64,
28}
29
30/// What to fetch: a share link (and, if the gate demands one, a pin).
31pub struct GetRequest {
32 pub url: String,
33 pub out: Option<PathBuf>,
34 pub pin: Option<String>,
35}
36
37/// The result of a successful fetch: where the file landed, and the trust
38/// metadata the sender attached (if any) — their name and a short message,
39/// decrypted from the gate's `/meta` blob with the fragment secret.
40pub struct Fetched {
41 pub path: PathBuf,
42 pub from: Option<String>,
43 pub message: Option<String>,
44}
45
46/// One entry in `dove ls` — enough to identify and describe a live share
47/// without re-fetching its contents.
48pub struct ShareInfo {
49 pub id: String,
50 pub filename: Option<String>,
51 pub expires_at: u64,
52}
53
54/// Backend health/config summary for `dove status` — an ordered list of
55/// label/value pairs so callers can render it without knowing the backend kind.
56pub struct BackendStatus {
57 pub summary: Vec<(String, String)>,
58}
59
60/// The seam every backend implements: share a file, fetch one, list and
61/// revoke what this machine has shared, and report backend status. No
62/// terminal I/O here — progress is reported through `&dyn Progress`, and
63/// results are returned for the caller to render.
64pub trait Transfer {
65 fn share(&self, req: ShareRequest, progress: &dyn Progress) -> Result<Share>;
66 fn get(&self, req: GetRequest, progress: &dyn Progress) -> Result<Fetched>;
67 fn list(&self) -> Result<Vec<ShareInfo>>;
68 fn revoke(&self, id: &str) -> Result<()>;
69 fn status(&self) -> Result<BackendStatus>;
70}