//! Snapshot downloads: what the file is, how it is compressed, and the limits around producing it. //! //! The export is first written to a private directory by the vault, then streamed to the client, //! compressed on the fly when it is not already a compressed format. The decision uses both the //! manifest hints and the first bytes of the real file; the bytes win, because hints are written by //! many producers and one of them (a legacy Restic commit) writes none. use crate::auth::{AuditAction, AuditOutcome, AuditResource, Principal}; use crate::db::Db; use axum::body::Bytes; use futures_core::Stream; use std::io; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; use tokio::sync::{OwnedSemaphorePermit, Semaphore}; use uuid::Uuid; pub const EXPORT_PREFIX: &str = "tessera-export-"; const DEFAULT_CONCURRENCY: usize = 2; const DEFAULT_MARGIN: u64 = 512 * 1024 * 1024; /// Reduce free text to `[a-z0-9_-]`: anything else becomes `_`, runs collapse, and the ends are trimmed. fn slug(text: &str, limit: usize) -> String { let mut out = String::new(); for c in text.chars() { let c = if c.is_ascii_alphanumeric() || c == '-' || c == '_' { c.to_ascii_lowercase() } else { '_' }; if c == '_' && out.ends_with('_') { continue; } out.push(c); } let out = out.trim_matches(['_', '-']); out.chars() .take(limit) .collect::() .trim_matches(['_', '-']) .to_string() } /// A readable file name for a download: `_