summaryrefslogtreecommitdiff
path: root/dichroism/src/image_service.rs
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2020-11-02 20:36:18 -0500
committerAdam T. Carpenter <atc@53hor.net>2020-11-02 20:36:18 -0500
commitdcc96d0b349583e5d6a0f25ae1f7a3ffa3769788 (patch)
tree98a9cc9d322e309c05db400f4c536164bee4daac /dichroism/src/image_service.rs
parent9480317011b57d3be7b903048f4a85d02979c7c7 (diff)
downloadtheglassyladies-dcc96d0b349583e5d6a0f25ae1f7a3ffa3769788.tar.xz
theglassyladies-dcc96d0b349583e5d6a0f25ae1f7a3ffa3769788.zip
swapped json payload url encoded images for multipart form data
Diffstat (limited to 'dichroism/src/image_service.rs')
-rw-r--r--dichroism/src/image_service.rs18
1 files changed, 2 insertions, 16 deletions
diff --git a/dichroism/src/image_service.rs b/dichroism/src/image_service.rs
index 3a31e04..a69cca2 100644
--- a/dichroism/src/image_service.rs
+++ b/dichroism/src/image_service.rs
@@ -2,28 +2,14 @@ use crate::config::CONFIG_INSTANCE;
use crate::constants::{PHOTO_BASE_XY, PHOTO_FULLSIZE_XY, PHOTO_THUMBNAIL_XY};
use crate::error::DichroismError;
use crate::models::{Photo, PhotoSet};
-use base64::decode;
use image::imageops::FilterType;
use image::DynamicImage;
use image::GenericImageView;
-use once_cell::sync::Lazy;
-use regex::Regex;
use std::path::PathBuf;
use uuid::Uuid;
-static DATA_URI_RE: Lazy<Regex> = Lazy::new(|| {
- Regex::new("^data:image/(png|jpeg);base64,(?P<data>.+)")
- .expect("Couldn't parse data URI Regex.")
-});
-
-pub fn generate_photo_set(uri: &str) -> Result<PhotoSet, DichroismError> {
- let data = DATA_URI_RE
- .captures(uri)
- .ok_or_else(|| DichroismError::UriDataExtract("Failed to parse URI".to_string()))?
- .name("data")
- .ok_or_else(|| DichroismError::UriDataExtract("Failed to extract data".to_string()))?
- .as_str();
- let original = image::load_from_memory(&decode(data)?)?;
+pub fn generate_photo_set(data: &[u8]) -> Result<PhotoSet, DichroismError> {
+ let original = image::load_from_memory(&data)?;
let fullsize = original.resize(PHOTO_FULLSIZE_XY, PHOTO_FULLSIZE_XY, FilterType::Lanczos3);
let base = original.resize(PHOTO_BASE_XY, PHOTO_BASE_XY, FilterType::Lanczos3);