fix: remove double extension in uploaded files (filename.png.png → filename.png)
Some checks failed
Deploy quoter / deploy (push) Has been cancelled

This commit is contained in:
2025-10-05 12:36:19 +03:00
parent 38ec9bf1a9
commit 0506f5abe9
3 changed files with 151 additions and 130 deletions

View File

@@ -73,14 +73,21 @@ pub async fn load_file_from_s3(
/// Генерирует ключ с правильным расширением на основе MIME-типа.
#[allow(clippy::collapsible_if)]
pub fn generate_key_with_extension(base_key: String, mime_type: String) -> String {
// Убираем существующее расширение из base_key (если есть)
let key_without_ext = if let Some(dot_pos) = base_key.rfind('.') {
&base_key[..dot_pos]
} else {
&base_key
};
let mime: mime::Mime =
mime::Mime::from_str(&mime_type).unwrap_or(mime::APPLICATION_OCTET_STREAM);
if let Some(extensions) = mime_guess::get_mime_extensions_str(mime.as_ref()) {
if let Some(extension) = extensions.first() {
return format!("{}.{}", base_key, extension.to_lowercase());
return format!("{}.{}", key_without_ext, extension.to_lowercase());
}
}
base_key
key_without_ext.to_string()
}
/// список файлов из S3