This commit is contained in:
JMARyA 2025-05-05 12:00:49 +02:00
commit 70c87bfad5
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
10 changed files with 4165 additions and 0 deletions

26
src/profile_pic.rs Normal file
View file

@ -0,0 +1,26 @@
use super::User;
use owl::{db::model::file::File, dereference, get, prelude::*, update};
pub trait ProfilePic {
fn profile_pic(&self) -> impl std::future::Future<Output = Option<Vec<u8>>>;
fn set_profile_pic(&self, image: Vec<u8>) -> impl std::future::Future<Output = ()>;
}
impl ProfilePic for User {
/// Get a user's profile picture from the database
async fn profile_pic(&self) -> Option<Vec<u8>> {
self.profile_picture
.as_ref()
.map(|x| dereference!(x).read_file(&owl::DB.get().unwrap()))
}
/// Set a user's profile picture in the database
async fn set_profile_pic(&self, image: Vec<u8>) {
let mut target = vec![get!(self.id.clone()).unwrap()];
let file = File::new(image, None, &owl::DB.get().unwrap());
update!(&mut target, |u: &mut User| {
u.profile_picture = Some(file.reference());
})
}
}