diff options
author | Adam T. Carpenter <atc@53hor.net> | 2020-10-31 10:14:31 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2020-10-31 10:14:31 -0400 |
commit | 3e1eadbbfdca1b2c0cb32ba4c8e1160a60e0ccb8 (patch) | |
tree | 3b712bc31a6db0a16ddfd4a02529d8b2497a5c54 /dichroism/src/models/photo.rs | |
parent | 00c71f6baff136a88805ca2e3f9ef72453ac9f35 (diff) | |
download | theglassyladies-3e1eadbbfdca1b2c0cb32ba4c8e1160a60e0ccb8.tar.xz theglassyladies-3e1eadbbfdca1b2c0cb32ba4c8e1160a60e0ccb8.zip |
All basic functionality implemented.
Diffstat (limited to 'dichroism/src/models/photo.rs')
-rw-r--r-- | dichroism/src/models/photo.rs | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/dichroism/src/models/photo.rs b/dichroism/src/models/photo.rs index 8c1435e..e24a691 100644 --- a/dichroism/src/models/photo.rs +++ b/dichroism/src/models/photo.rs @@ -1,34 +1,14 @@ -use crate::config::CONFIG_INSTANCE; -use crate::error::DichroismError; -use crate::result::Result; -use image::DynamicImage; -use std::path::PathBuf; -use uuid::Uuid; - -#[derive(Debug, Queryable, Serialize, Clone)] +#[derive(Debug, Clone)] pub struct Photo { - pub filename: String, + pub id: String, } impl Photo { - pub fn from_filename(filename: String) -> Self { - Self { filename } + pub fn new(id: String) -> Self { + Self { id } } - pub fn from_image(image: &DynamicImage) -> Result<Self> { - let base_name = Uuid::new_v3(&Uuid::NAMESPACE_OID, &image.to_bytes()) - .to_hyphenated() - .to_string(); - let mut path = PathBuf::from(&CONFIG_INSTANCE.img_root); - path.push(base_name); - path.set_extension("jpg"); - image.save(&path)?; - - let filename = path - .file_name() - .ok_or(DichroismError::ImageWrite)? - .to_str() - .ok_or(DichroismError::ImageWrite)?; - Ok(Self::from_filename(String::from(filename))) + pub fn filename(&self) -> String { + format!("{}.jpg", self.id) } } |