use serde::{Deserialize, Serialize}; pub const FILE_TYPES: [&str; 5] = ["audio", "video", "document", "software", "other"]; #[derive(Serialize, Clone, Debug)] pub struct FileRecord { pub id: String, pub peer_id: String, pub name: String, pub description: String, pub ftype: String, pub extension: String, pub size_bytes: i64, pub hash: String, pub license: String, pub tags: Vec, pub created_at: i64, } #[derive(Deserialize, Debug)] pub struct AnnounceRequest { pub peer_id: String, pub name: String, pub description: String, #[serde(rename = "type")] pub ftype: String, pub extension: String, pub size_bytes: i64, pub hash: String, pub license: String, #[serde(default)] pub tags: Vec, } #[derive(Deserialize, Debug)] pub struct SearchQuery { pub q: Option, pub ftype: Option, pub sort: Option, pub limit: Option, pub offset: Option, } impl FileRecord { pub(crate) fn from_row(r: &rusqlite::Row) -> rusqlite::Result { let tags: String = r.get(9)?; Ok(Self { id: r.get(0)?, peer_id: r.get(1)?, name: r.get(2)?, description: r.get(3)?, ftype: r.get(4)?, extension: r.get(5)?, size_bytes: r.get(6)?, hash: r.get(7)?, license: r.get(8)?, tags: serde_json::from_str(&tags).unwrap_or_default(), created_at: r.get(10)?, }) } }