heic-bypass
Some checks failed
deploy / deploy (push) Failing after 5s

This commit is contained in:
Untone 2024-11-13 12:03:32 +03:00
parent d0e70a7783
commit 0982dff45b
3 changed files with 27 additions and 25 deletions

View File

@ -1,5 +1,5 @@
# Build stage
FROM rust:slim-bookworm as build
FROM rust:slim-bookworm AS build
# Install build dependencies
RUN apt-get update && \

View File

@ -123,7 +123,7 @@ pub async fn proxy_handler(
// Создаем варианты путей с обоими регистрами расширения
let paths_lower = vec![
stored_path.clone(),
format!("production/{}", stored_path),
// format!("production/{}", stored_path),
format!("production/{}/{}", media_type, stored_path)
];
@ -132,7 +132,7 @@ pub async fn proxy_handler(
let orig_stored_path = format!("{}.{}", base_filename, orig_ext);
let paths_orig = vec![
orig_stored_path.clone(),
format!("production/{}", orig_stored_path),
// format!("production/{}", orig_stored_path),
format!("production/{}/{}", media_type, orig_stored_path)
];

View File

@ -128,16 +128,28 @@ pub async fn thumbdata_save(
warn!("original file name: {}", original_filename);
let (base_filename, _, extension) = parse_file_path(&original_filename);
warn!("detected file extension: {}", extension);
let ext = extension.to_lowercase();
// Определяем выходной формат
let output_ext = match ext.as_str() {
"heic" | "heif" => "jpg", // Конвертируем HEIC в JPEG
_ => &ext
};
let filename = format!("{}.{}", base_filename, output_ext);
// Для HEIC файлов просто сохраняем оригинал как миниатюру
if content_type == "image/heic" {
warn!("HEIC file detected, using original as thumbnail");
let thumb_filename = format!("{}_{}.heic", base_filename, THUMB_WIDTHS[0]);
if let Err(e) = upload_to_s3(
&state.storj_client,
&state.bucket,
&thumb_filename,
original_data,
&content_type,
)
.await
{
warn!("cannot save HEIC thumb {}: {}", thumb_filename, e);
return Err(ErrorInternalServerError("cant save HEIC thumbnail"));
}
return Ok(());
}
// Для остальных изображений продолжаем как обычно
let img = match image::load_from_memory(&original_data) {
Ok(img) => img,
Err(e) => {
@ -146,17 +158,13 @@ pub async fn thumbdata_save(
}
};
warn!("generate thumbnails for {}", filename);
warn!("generate thumbnails for {}", original_filename);
let format = determine_image_format(&extension.to_lowercase())?;
// Определяем формат изображения для сохранения
let format = determine_image_format(output_ext)?;
// Генерация миниатюр с использованием определённого формата
match generate_thumbnails(&img, format).await {
Ok(thumbnails_bytes) => {
for (thumb_width, thumbnail) in thumbnails_bytes {
let thumb_filename = format!("{}_{}.{}", base_filename, thumb_width, output_ext);
// Загружаем миниатюру в S3
let thumb_filename = format!("{}_{}.{}", base_filename, thumb_width, extension);
if let Err(e) = upload_to_s3(
&state.storj_client,
&state.bucket,
@ -171,7 +179,7 @@ pub async fn thumbdata_save(
}
}
Err(e) => {
warn!("cannot generate thumbnails for {}: {}", filename, e);
warn!("cannot generate thumbnails for {}: {}", original_filename, e);
return Err(e);
}
}
@ -195,9 +203,3 @@ pub fn find_closest_width(requested_width: u32) -> u32 {
.min_by_key(|&&width| (width as i32 - requested_width as i32).abs())
.unwrap_or(&THUMB_WIDTHS[0]) // Возвращаем самый маленький размер, если ничего не подошло
}
/// Конвертирует HEIC в JPEG
pub fn convert_heic_to_jpeg(data: &[u8]) -> Result<Vec<u8>, actix_web::Error> {
warn!("HEIC conversion is temporarily disabled");
Ok(data.to_vec())
}