init
This commit is contained in:
commit
70c87bfad5
10 changed files with 4165 additions and 0 deletions
26
src/profile_pic.rs
Normal file
26
src/profile_pic.rs
Normal 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());
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue