diff --git a/Cargo.lock b/Cargo.lock index 81916c8..cdafc2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1316,7 +1316,6 @@ dependencies = [ "imageproc", "infer", "kamadak-exif", - "libheif-sys", "log", "mime_guess", "once_cell", @@ -2279,17 +2278,6 @@ dependencies = [ "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]] name = "libm" version = "0.2.11" diff --git a/Cargo.toml b/Cargo.toml index 4934393..6c0f7b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ env_logger = "0.11.5" actix = "0.13.5" imageproc = "0.25.0" ab_glyph = "0.2.29" -libheif-sys = "1.12" +# libheif-sys = "1.12.0" once_cell = "1.18" kamadak-exif = "0.5" infer = "0.15" diff --git a/Dockerfile b/Dockerfile index 9030fd7..1dc08a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,30 @@ -# Use Debian-based Rust image instead of Alpine -FROM rust:slim-bookworm AS build +# Build stage +FROM rust:slim-bookworm as build -# Install necessary packages +# Install build dependencies RUN apt-get update && \ - apt-get install -y git pkg-config make g++ libssl-dev libheif-dev libheif1 libtiff-dev \ - clang libclang-dev pkg-config libde265-dev libx265-dev libjpeg-dev && \ - rustup target add x86_64-unknown-linux-gnu + apt-get install -y \ + git \ + 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 -ENV LIBCLANG_PATH=/usr/lib/llvm-14/lib -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 +# Add target +RUN rustup target add x86_64-unknown-linux-gnu -# Create a new Rust binary project +# Create a new empty shell project RUN USER=root cargo new --bin quoter + WORKDIR /quoter -# Copy Cargo files to cache dependencies +# Copy manifests COPY ./Cargo.lock ./Cargo.lock COPY ./Cargo.toml ./Cargo.toml @@ -29,33 +35,26 @@ RUN cargo build --release # Remove the default source file created by cargo new RUN rm src/*.rs -# Copy your source code into the container +# Copy source code COPY ./src ./src -# Build the application for release +# Build for release +RUN rm ./target/release/deps/quoter* RUN cargo build --release -# Use Debian slim for the final stage +# Final stage FROM debian:bookworm-slim -ENV RUST_BACKTRACE=full -ENV RUST_LOG=warn - # Install runtime dependencies RUN apt-get update && \ apt-get install -y --no-install-recommends \ libssl3 \ - libheif1 \ libtiff6 \ - libde265-0 \ - libx265-199 \ - libjpeg62-turbo \ + && apt-get clean \ && 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 . -ENV PORT=8080 -EXPOSE 8080 - +# Set the startup command CMD ["./quoter"] \ No newline at end of file diff --git a/src/handlers/upload.rs b/src/handlers/upload.rs index 4baa26b..f65a800 100644 --- a/src/handlers/upload.rs +++ b/src/handlers/upload.rs @@ -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) }; diff --git a/src/thumbnail.rs b/src/thumbnail.rs index 2bd8aed..c6240c1 100644 --- a/src/thumbnail.rs +++ b/src/thumbnail.rs @@ -198,31 +198,6 @@ pub fn find_closest_width(requested_width: u32) -> u32 { /// Конвертирует HEIC в JPEG pub fn convert_heic_to_jpeg(data: &[u8]) -> Result, 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()) }