diff --git a/Cargo.toml b/Cargo.toml index 3a6cfbd..b458689 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ version = "0.1.0" [dependencies] actix-web = "4.3.1" image = "0.24.6" -libwebp-sys = "0.9.2" +libwebp-sys = { version = "0.9.2", optional = true } mimalloc = "0.1.37" once_cell = "1.18.0" qstring = "0.7.2" @@ -19,4 +19,6 @@ reqwest = { version = "0.11.18", features = ["rustls-tls", "stream", "brotli", " tokio = { version = "1.29.1", features = ["full"] } [features] +default = ["webp"] avif = ["dep:ravif", "dep:rgb"] +webp = ["dep:libwebp-sys"] diff --git a/src/main.rs b/src/main.rs index a105066..aa74be1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,8 @@ use std::env; use std::error::Error; +use actix_web::{App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer, web}; use actix_web::http::Method; -use actix_web::{web, App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer}; -use libwebp_sys::{WebPEncodeRGB, WebPFree}; use mimalloc::MiMalloc; use once_cell::sync::Lazy; use qstring::QString; @@ -28,8 +27,8 @@ async fn main() -> std::io::Result<()> { let bind = env::var("BIND").unwrap_or_else(|_| "0.0.0.0:8080".to_string()); server.bind(bind)? } - .run() - .await + .run() + .await } static RE_DOMAIN: Lazy = @@ -221,7 +220,10 @@ async fn index(req: HttpRequest) -> Result> { }; } + #[cfg(feature = "webp")] if content_type == "image/jpeg" { + use libwebp_sys::{WebPEncodeRGB, WebPFree}; + let resp_bytes = resp.bytes().await.unwrap(); let image = image::load_from_memory(&resp_bytes).unwrap(); @@ -256,6 +258,7 @@ async fn index(req: HttpRequest) -> Result> { response.content_type("image/jpeg"); return Ok(response.body(resp_bytes)); } + if content_type == "application/x-mpegurl" || content_type == "application/vnd.apple.mpegurl" {