mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-11 20:32:12 +00:00
max length
This commit is contained in:
1 parent
56c1b57cce
commit
3a990d014a
2 files changed
+20
-6
No files matched your search
+9
-1
@@ -30,7 +30,7 @@ use crate::util::http_download_url_to_bytes::http_download_url_to_bytes;
|
||||
use crate::util::lookup::lookup_media_file_urls_as_map::lookup_media_file_urls_as_map;
|
||||
|
||||
const MAX_NAME_LENGTH: usize = 255;
|
||||
const MAX_DESCRIPTION_LENGTH: usize = 512;
|
||||
const MAX_DESCRIPTION_LENGTH: usize = 500;
|
||||
|
||||
/// Create a new character.
|
||||
#[utoipa::path(
|
||||
@@ -86,6 +86,14 @@ pub async fn create_character_handler(
|
||||
let character_description = request.character_description.as_deref()
|
||||
.map(|desc| desc.trim());
|
||||
|
||||
if let Some(desc) = character_description {
|
||||
if desc.len() > MAX_DESCRIPTION_LENGTH {
|
||||
return Err(AdvancedCommonWebError::BadInputWithSimpleMessage(
|
||||
format!("Description exceeds maximum length of {} characters.", MAX_DESCRIPTION_LENGTH),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// --- Look up the image media file ---
|
||||
|
||||
let file_urls_by_token = lookup_media_file_urls_as_map(
|
||||
|
||||
+11
-5
@@ -71,7 +71,7 @@ pub async fn edit_character_handler(
|
||||
// --- Determine what to update ---
|
||||
|
||||
let new_name = resolve_name_update(&request.updated_name);
|
||||
let description_update = resolve_description_update(&request.updated_description);
|
||||
let description_update = resolve_description_update(&request.updated_description)?;
|
||||
|
||||
let has_name_change = new_name.is_some();
|
||||
let has_description_change = !matches!(description_update, DescriptionUpdateType::NoUpdate);
|
||||
@@ -160,17 +160,23 @@ fn resolve_name_update(updated_name: &Option<String>) -> Option<String> {
|
||||
}
|
||||
|
||||
/// Determine the description update type.
|
||||
fn resolve_description_update(updated_description: &Option<String>) -> DescriptionUpdateType {
|
||||
fn resolve_description_update(
|
||||
updated_description: &Option<String>,
|
||||
) -> Result<DescriptionUpdateType, AdvancedCommonWebError> {
|
||||
let desc = match updated_description.as_ref() {
|
||||
None => return DescriptionUpdateType::NoUpdate,
|
||||
None => return Ok(DescriptionUpdateType::NoUpdate),
|
||||
Some(d) => d,
|
||||
};
|
||||
|
||||
let trimmed = desc.trim();
|
||||
if trimmed.is_empty() {
|
||||
DescriptionUpdateType::Nullify
|
||||
Ok(DescriptionUpdateType::Nullify)
|
||||
} else if trimmed.len() > MAX_DESCRIPTION_LENGTH {
|
||||
Err(AdvancedCommonWebError::BadInputWithSimpleMessage(
|
||||
format!("Description exceeds maximum length of {} characters.", MAX_DESCRIPTION_LENGTH),
|
||||
))
|
||||
} else {
|
||||
DescriptionUpdateType::Update(truncate(trimmed, MAX_DESCRIPTION_LENGTH))
|
||||
Ok(DescriptionUpdateType::Update(trimmed.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user