rust-api-template/src/api/routes/files/models.rs
2025-05-31 17:57:05 +02:00

33 lines
628 B
Rust

use blake3::Hasher;
use serde::Serialize;
use tokio_util::bytes::Bytes;
use ts_rs::TS;
use utoipa::ToSchema;
#[derive(Debug, Clone, Serialize, TS, ToSchema)]
#[ts(export)]
pub struct AttachedFile {
pub name: String,
pub hash: String,
pub content_type: String,
pub size: i32,
}
#[derive(Debug)]
pub struct File {
pub name: String,
pub content_type: String,
pub data: Bytes,
pub size: i32,
}
impl File {
pub fn hash(&self) -> String {
let mut hasher = Hasher::new();
hasher.update(&self.data);
let hash = hasher.finalize();
hash.to_hex().to_string()
}
}