61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
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<String>,
|
|
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<String>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct SearchQuery {
|
|
pub q: Option<String>,
|
|
pub ftype: Option<String>,
|
|
pub sort: Option<String>,
|
|
pub limit: Option<i64>,
|
|
pub offset: Option<i64>,
|
|
}
|
|
|
|
impl FileRecord {
|
|
pub(crate) fn from_row(r: &rusqlite::Row) -> rusqlite::Result<Self> {
|
|
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)?,
|
|
})
|
|
}
|
|
} |