34 lines
673 B
Rust
34 lines
673 B
Rust
|
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}")
|
||
|
}
|
||
|
}
|