Skip to main content

oximedia_proxy/workflow/
roundtrip.rs

1//! Round-trip workflow (offline to online to delivery).
2
3use crate::{OfflineWorkflow, ProxyPreset, Result};
4use std::path::Path;
5
6/// Round-trip workflow manager for complete offline-online pipeline.
7pub struct RoundtripWorkflow {
8    offline: OfflineWorkflow,
9}
10
11impl RoundtripWorkflow {
12    /// Create a new round-trip workflow.
13    ///
14    /// # Errors
15    ///
16    /// Returns an error if initialization fails.
17    pub async fn new(db_path: impl AsRef<Path>) -> Result<Self> {
18        let offline = OfflineWorkflow::new(db_path).await?;
19        Ok(Self { offline })
20    }
21
22    /// Phase 1: Ingest originals and create proxies.
23    ///
24    /// # Errors
25    ///
26    /// Returns an error if ingest fails.
27    pub async fn phase_ingest(
28        &mut self,
29        originals: &[impl AsRef<Path>],
30        proxy_dir: impl AsRef<Path>,
31        preset: ProxyPreset,
32    ) -> Result<()> {
33        for original in originals {
34            let filename = original
35                .as_ref()
36                .file_name()
37                .and_then(|n| n.to_str())
38                .unwrap_or("proxy.mp4");
39
40            let proxy_path = proxy_dir.as_ref().join(filename);
41
42            self.offline.ingest(original, proxy_path, preset).await?;
43        }
44
45        Ok(())
46    }
47
48    /// Phase 2: Edit with proxies (external editing application).
49    pub fn phase_edit(&self) -> Result<String> {
50        Ok("Edit with your NLE using proxy files".to_string())
51    }
52
53    /// Phase 3: Conform to originals for finishing.
54    ///
55    /// # Errors
56    ///
57    /// Returns an error if conform fails.
58    pub async fn phase_conform(
59        &self,
60        edl_path: impl AsRef<Path>,
61        output: impl AsRef<Path>,
62    ) -> Result<crate::ConformResult> {
63        self.offline.conform(edl_path, output).await
64    }
65
66    /// Phase 4: Final delivery (rendering, packaging, etc.).
67    pub async fn phase_deliver(&self, _output: impl AsRef<Path>) -> Result<()> {
68        // Placeholder: would handle final delivery tasks
69        Ok(())
70    }
71}
72
73#[cfg(test)]
74mod tests {
75    use super::*;
76
77    #[tokio::test]
78    async fn test_roundtrip_workflow_creation() {
79        let temp_dir = std::env::temp_dir();
80        let db_path = temp_dir.join("test_roundtrip.json");
81
82        let workflow = RoundtripWorkflow::new(&db_path).await;
83        assert!(workflow.is_ok());
84
85        // Clean up
86        let _ = std::fs::remove_file(db_path);
87    }
88}