juiceback/
tus.rs

1//! In-memory state for TUS resumable uploads.
2
3use std::sync::Arc;
4
5use dashmap::DashMap;
6
7/// A TUS upload session that lives in memory while the upload is in progress.
8///
9/// Chunks arrive one by one. When offset reaches total_length the file gets
10/// pushed to juicehost and a permanent database record is created.
11#[derive(Debug, Clone)]
12pub struct TusUpload {
13    pub id: String,
14    pub storage_path: std::path::PathBuf,
15    pub offset: u64,
16    pub total_length: u64,
17    pub filename: String,
18    pub mime_type: String,
19    pub ttl_hours: f64,
20    pub created_at: i64,
21    pub delete_token: String,
22    pub uploader_ip: String,
23    pub storage_host: String,
24    pub storage_upload_mode: String,
25}
26
27pub type TusMap = Arc<DashMap<String, TusUpload>>;
28
29pub fn new_tus_state() -> TusMap {
30    Arc::new(DashMap::new())
31}