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

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

12
Cargo.lock generated
View File

@ -1316,7 +1316,6 @@ dependencies = [
"imageproc", "imageproc",
"infer", "infer",
"kamadak-exif", "kamadak-exif",
"libheif-sys",
"log", "log",
"mime_guess", "mime_guess",
"once_cell", "once_cell",
@ -2279,17 +2278,6 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "libheif-sys"
version = "1.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fec9617ceb95892391fba66dc1d559b3b15997844f5d36b17cb96ed86e0551c"
dependencies = [
"libc",
"pkg-config",
"vcpkg",
]
[[package]] [[package]]
name = "libm" name = "libm"
version = "0.2.11" version = "0.2.11"

View File

@ -26,7 +26,7 @@ env_logger = "0.11.5"
actix = "0.13.5" actix = "0.13.5"
imageproc = "0.25.0" imageproc = "0.25.0"
ab_glyph = "0.2.29" ab_glyph = "0.2.29"
libheif-sys = "1.12" # libheif-sys = "1.12.0"
once_cell = "1.18" once_cell = "1.18"
kamadak-exif = "0.5" kamadak-exif = "0.5"
infer = "0.15" infer = "0.15"

View File

@ -1,24 +1,30 @@
# Use Debian-based Rust image instead of Alpine # Build stage
FROM rust:slim-bookworm AS build FROM rust:slim-bookworm as build
# Install necessary packages # Install build dependencies
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y git pkg-config make g++ libssl-dev libheif-dev libheif1 libtiff-dev \ apt-get install -y \
clang libclang-dev pkg-config libde265-dev libx265-dev libjpeg-dev && \ git \
rustup target add x86_64-unknown-linux-gnu pkg-config \
make \
g++ \
libssl-dev \
libtiff-dev \
clang \
libclang-dev \
pkg-config \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Set environment variables for libclang # Add target
ENV LIBCLANG_PATH=/usr/lib/llvm-14/lib RUN rustup target add x86_64-unknown-linux-gnu
ENV BINDGEN_EXTRA_CLANG_ARGS="-I/usr/include"
ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig
ENV PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
ENV PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
# Create a new Rust binary project # Create a new empty shell project
RUN USER=root cargo new --bin quoter RUN USER=root cargo new --bin quoter
WORKDIR /quoter WORKDIR /quoter
# Copy Cargo files to cache dependencies # Copy manifests
COPY ./Cargo.lock ./Cargo.lock COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml COPY ./Cargo.toml ./Cargo.toml
@ -29,33 +35,26 @@ RUN cargo build --release
# Remove the default source file created by cargo new # Remove the default source file created by cargo new
RUN rm src/*.rs RUN rm src/*.rs
# Copy your source code into the container # Copy source code
COPY ./src ./src COPY ./src ./src
# Build the application for release # Build for release
RUN rm ./target/release/deps/quoter*
RUN cargo build --release RUN cargo build --release
# Use Debian slim for the final stage # Final stage
FROM debian:bookworm-slim FROM debian:bookworm-slim
ENV RUST_BACKTRACE=full
ENV RUST_LOG=warn
# Install runtime dependencies # Install runtime dependencies
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
libssl3 \ libssl3 \
libheif1 \
libtiff6 \ libtiff6 \
libde265-0 \ && apt-get clean \
libx265-199 \
libjpeg62-turbo \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy the compiled binary from the build stage # Copy the build artifact from the build stage
COPY --from=build /quoter/target/release/quoter . COPY --from=build /quoter/target/release/quoter .
ENV PORT=8080 # Set the startup command
EXPOSE 8080
CMD ["./quoter"] CMD ["./quoter"]

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 crate::lookup::store_file_info;
use futures::TryStreamExt; use futures::TryStreamExt;
use crate::handlers::MAX_WEEK_BYTES; 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( 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" { let (file_bytes, content_type) = if detected_mime_type == "image/heic" {
match convert_heic_to_jpeg(&file_bytes) { warn!("HEIC support is temporarily disabled, saving original file");
Ok(jpeg_data) => (jpeg_data, "image/jpeg".to_string()), (file_bytes, detected_mime_type)
Err(e) => {
warn!("Failed to convert HEIC to JPEG: {}", e);
(file_bytes, detected_mime_type)
}
}
} else { } else {
(file_bytes, detected_mime_type) (file_bytes, detected_mime_type)
}; };

View File

@ -198,31 +198,6 @@ pub fn find_closest_width(requested_width: u32) -> u32 {
/// Конвертирует HEIC в JPEG /// Конвертирует HEIC в JPEG
pub fn convert_heic_to_jpeg(data: &[u8]) -> Result<Vec<u8>, actix_web::Error> { pub fn convert_heic_to_jpeg(data: &[u8]) -> Result<Vec<u8>, actix_web::Error> {
// Пробуем прочитать как обычное изображение warn!("HEIC conversion is temporarily disabled");
if let Ok(img) = image::load_from_memory(data) { Ok(data.to_vec())
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
))),
}
} }