noheic-convertion
Some checks failed
deploy / deploy (push) Failing after 5s

This commit is contained in:
2024-11-13 11:32:50 +03:00
parent 566379042d
commit b471c66209
5 changed files with 34 additions and 77 deletions

View File

@@ -8,7 +8,7 @@ use crate::s3_utils::{self, upload_to_s3, generate_key_with_extension};
use crate::lookup::store_file_info;
use futures::TryStreamExt;
use crate::handlers::MAX_WEEK_BYTES;
use crate::thumbnail::convert_heic_to_jpeg;
// use crate::thumbnail::convert_heic_to_jpeg;
/// Обработчик для аплоада файлов.
pub async fn upload_handler(
@@ -50,15 +50,10 @@ pub async fn upload_handler(
}
};
// Для HEIC файлов конвертируем в JPEG
// Для HEIC файлов просто сохраняем как есть
let (file_bytes, content_type) = if detected_mime_type == "image/heic" {
match convert_heic_to_jpeg(&file_bytes) {
Ok(jpeg_data) => (jpeg_data, "image/jpeg".to_string()),
Err(e) => {
warn!("Failed to convert HEIC to JPEG: {}", e);
(file_bytes, detected_mime_type)
}
}
warn!("HEIC support is temporarily disabled, saving original file");
(file_bytes, detected_mime_type)
} else {
(file_bytes, detected_mime_type)
};

View File

@@ -198,31 +198,6 @@ pub fn find_closest_width(requested_width: u32) -> u32 {
/// Конвертирует HEIC в JPEG
pub fn convert_heic_to_jpeg(data: &[u8]) -> Result<Vec<u8>, actix_web::Error> {
// Пробуем прочитать как обычное изображение
if let Ok(img) = image::load_from_memory(data) {
let mut buffer = Vec::new();
img.write_to(&mut Cursor::new(&mut buffer), ImageFormat::Jpeg)
.map_err(|e| actix_web::error::ErrorInternalServerError(format!("Failed to convert to JPEG: {}", e)))?;
return Ok(buffer);
}
// Если не получилось, пробуем через exif
let mut cursor = Cursor::new(data);
match exif::Reader::new().read_from_container(&mut cursor) {
Ok(_exif) => {
// Конвертируем в JPEG
let img = image::load_from_memory(data)
.map_err(|e| actix_web::error::ErrorInternalServerError(format!("Failed to load HEIC: {}", e)))?;
let mut buffer = Vec::new();
img.write_to(&mut Cursor::new(&mut buffer), ImageFormat::Jpeg)
.map_err(|e| actix_web::error::ErrorInternalServerError(format!("Failed to convert to JPEG: {}", e)))?;
Ok(buffer)
}
Err(e) => Err(actix_web::error::ErrorInternalServerError(format!(
"Failed to process HEIC: {}",
e
))),
}
warn!("HEIC conversion is temporarily disabled");
Ok(data.to_vec())
}