mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-15 03:38:07 +00:00
Handle multipart requests
This commit is contained in:
@ -14,23 +14,16 @@ use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::{account_helper, api_helper, user_helper, conversations_helper};
|
||||
use crate::utils::virtual_directories_utils::check_virtual_directory;
|
||||
use bytes::Bytes;
|
||||
|
||||
/// Http request handler
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
/// Single request body value
|
||||
pub struct RequestValue {
|
||||
pub string: Option<String>
|
||||
}
|
||||
|
||||
impl RequestValue {
|
||||
/// Build a string value
|
||||
pub fn string(s: String) -> RequestValue {
|
||||
RequestValue {
|
||||
string: Some(s)
|
||||
}
|
||||
}
|
||||
pub enum RequestValue {
|
||||
String(String),
|
||||
File(String, Bytes),
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@ -187,19 +180,19 @@ impl HttpRequestHandler {
|
||||
-> ResultBoxError<String> {
|
||||
let param = self.post_parameter(name)?;
|
||||
|
||||
match (¶m.string, required) {
|
||||
(None, true) =>
|
||||
Err(self.bad_request(format!("'{}' is not a string!", name)).unwrap_err()),
|
||||
|
||||
(None, false) => Ok(String::new()),
|
||||
|
||||
(Some(s), _) => {
|
||||
match (¶m, required) {
|
||||
(RequestValue::String(s), _) => {
|
||||
if s.len() >= min_length {
|
||||
Ok(s.to_string())
|
||||
} else {
|
||||
Err(self.bad_request(format!("'{}' is too short!", name)).unwrap_err())
|
||||
}
|
||||
}
|
||||
|
||||
(_, false) => Ok(String::new()),
|
||||
|
||||
(_, true) =>
|
||||
Err(self.bad_request(format!("'{}' is not a string!", name)).unwrap_err()),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user