Turn webp rewriting into a feature flag.

This commit is contained in:
Kavin 2023-08-05 16:26:19 +01:00
parent 53329c43e8
commit 5212b4213c
No known key found for this signature in database
GPG key ID: 6E4598CA5C92C41F
2 changed files with 10 additions and 5 deletions

View file

@ -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"]

View file

@ -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;
@ -221,7 +220,10 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
};
}
#[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<HttpResponse, Box<dyn Error>> {
response.content_type("image/jpeg");
return Ok(response.body(resp_bytes));
}
if content_type == "application/x-mpegurl"
|| content_type == "application/vnd.apple.mpegurl"
{