iris_chat_core/
direct_files.rs1use serde::{Deserialize, Serialize};
2
3#[derive(uniffi::Enum, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
4pub enum DirectFileTransferStatus {
5 Offered,
6 Connecting,
7 Transferring,
8 Completed,
9 Declined,
10 Cancelled,
11 Failed,
12 Unavailable,
13}
14
15#[derive(uniffi::Record, Clone, Debug, PartialEq, Eq)]
16pub struct DirectFileSnapshot {
17 pub filename: String,
18 pub size_bytes: u64,
19 pub local_path: Option<String>,
20}
21
22#[derive(uniffi::Record, Clone, Debug, PartialEq, Eq)]
23pub struct DirectFileTransferSnapshot {
24 pub id: String,
25 pub files: Vec<DirectFileSnapshot>,
26 pub status: DirectFileTransferStatus,
27 pub is_sender: bool,
29 pub transferred_bytes: u64,
30 pub total_bytes: u64,
31 pub error: Option<String>,
32}
33
34pub(crate) fn valid_filename(name: &str) -> bool {
36 !name.is_empty()
37 && name.len() <= 240
38 && name != "."
39 && name != ".."
40 && !name
41 .chars()
42 .any(|c| c.is_control() || "/\\<>:\"|?*".contains(c))
43}
44
45pub(crate) fn valid_transfer_id(id: &str) -> bool {
46 !id.is_empty()
47 && id.len() <= 128
48 && id
49 .bytes()
50 .all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_')
51}