Can download uploaded images
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::schema::{families, members, memberships, photos, users};
|
||||
use crate::utils::crypt_utils::sha256;
|
||||
use diesel::prelude::*;
|
||||
|
||||
/// User ID holder
|
||||
@ -121,6 +123,28 @@ pub struct FamilyMembership {
|
||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, Eq, PartialEq, Hash)]
|
||||
pub struct PhotoID(pub i32);
|
||||
|
||||
impl PhotoID {
|
||||
pub fn to_signed_hash(&self) -> String {
|
||||
let secret = AppConfig::get().secret();
|
||||
format!(
|
||||
"{}-{}",
|
||||
self.0,
|
||||
sha256(format!("{secret}{}{secret}", self.0).as_bytes())
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from_signed_hash(hash: &str) -> Option<Self> {
|
||||
let (id, _) = hash.split_once('-')?;
|
||||
let id = Self(id.parse().ok()?);
|
||||
|
||||
if id.to_signed_hash() != hash {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Debug, serde::Serialize)]
|
||||
pub struct Photo {
|
||||
id: i32,
|
||||
|
Reference in New Issue
Block a user