rust-api-template/src/api/routes/files/models.rs

34 lines
673 B
Rust
Raw Normal View History

2025-04-05 17:10:55 +00:00
use chrono::NaiveDateTime;
use serde::Serialize;
use sha2::{Digest, Sha256};
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,
}
pub struct File {
pub name: String,
pub draft_id: NaiveDateTime,
pub content_type: String,
pub data: Bytes,
pub size: i32,
}
impl File {
pub fn hash(&self) -> String {
let mut hasher = Sha256::new();
hasher.update(&self.data);
let hash = hasher.finalize();
format!("{hash:X}")
}
}