Skip to main content

lingxia_platform/traits/
media_runtime.rs

1use std::path::{Path, PathBuf};
2
3use crate::error::PlatformError;
4
5use super::media_interaction::MediaKind;
6
7#[derive(Debug, Clone)]
8pub struct ImageInfo {
9    pub width: u32,
10    pub height: u32,
11    pub mime_type: Option<String>,
12}
13
14#[derive(Debug, Clone)]
15pub struct CompressImageRequest {
16    pub source_uri: String,
17    pub quality: u8,
18    pub max_width: Option<u32>,
19    pub max_height: Option<u32>,
20    pub output_path: PathBuf,
21}
22
23pub trait MediaRuntime: Send + Sync + 'static {
24    /// Copy a picked/album media asset identified by `uri` into a local file at `dest_path`.
25    ///
26    /// Notes:
27    /// - `uri` is an opaque platform media reference coming from platform pickers and may not be a
28    ///   directly readable filesystem path.
29    /// - Implementations should support platform-specific schemes as applicable, for example:
30    ///   - Android: `content://...`
31    ///   - iOS: `ph://...` (or other Photos identifiers)
32    ///   - Harmony: picker URIs such as `file://media/...`
33    ///   - Some platforms may also provide `file:///absolute/path` (or an absolute path string).
34    /// - Implementations should create parent directories for `dest_path` if needed and write the
35    ///   file content so that `dest_path` exists on success.
36    fn copy_album_media_to_file(
37        &self,
38        uri: &str,
39        dest_path: &Path,
40        kind: MediaKind,
41    ) -> Result<(), PlatformError>;
42
43    fn get_image_info(&self, uri: &str) -> Result<ImageInfo, PlatformError>;
44
45    fn compress_image(&self, request: &CompressImageRequest) -> Result<PathBuf, PlatformError>;
46}