From 5453205a5871cb610925749ca0c6ad3e17d26dd8 Mon Sep 17 00:00:00 2001 From: kieran Date: Tue, 15 Oct 2024 11:14:07 +0100 Subject: [PATCH] refactor: make media compression optional for blossom --- Cargo.toml | 5 +++-- README.md | 9 ++++++--- src/filesystem.rs | 10 +++++----- src/lib.rs | 2 +- src/routes/blossom.rs | 7 +++++++ 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7b21a2..12ec1ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,10 @@ name = "route96" [features] default = ["nip96", "blossom", "analytics"] +media-compression = ["dep:ffmpeg-sys-the-third", "dep:blurhash", "dep:libc"] labels = ["nip96", "dep:candle-core", "dep:candle-nn", "dep:candle-transformers"] -nip96 = ["dep:ffmpeg-sys-the-third", "dep:blurhash", "dep:libc"] -blossom = ["dep:ffmpeg-sys-the-third", "dep:libc"] +nip96 = ["media-compression"] +blossom = [] bin-void-cat-migrate = ["dep:sqlx-postgres", "dep:clap", "dep:clap_derive"] torrent-v2 = [] analytics = [] diff --git a/README.md b/README.md index a1a761a..ddec98a 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,15 @@ Image hosting service - [BUD-05](https://github.com/hzrd149/blossom/blob/master/buds/05.md) - [BUD-06](https://github.com/hzrd149/blossom/blob/master/buds/06.md) - [BUD-08](https://github.com/hzrd149/blossom/blob/master/buds/08.md) -- Image compression to WebP (FFMPEG, NIP-96 only) -- Blurhash calculation (NIP-96 only) +- Image compression to WebP +- Blurhash calculation - AI image labeling ([ViT224](https://huggingface.co/google/vit-base-patch16-224)) +- Plausible analytics ## Planned - Torrent seed V2 +- Payment system ## Running @@ -45,11 +47,12 @@ docker run --rm -it \ ### Feature Flags -Default = `nip96` & `blossom` +Default = `nip96` & `blossom` & `analytics` - `nip96`: Enable NIP-96 support - `blossom`: Enable blossom support - `labels`: Enable AI image labeling (Depends on `nip96`) +- `analytics`: Enable pageview analytics reporting (Plausible) ### Default build: diff --git a/src/filesystem.rs b/src/filesystem.rs index e9e045c..9c03963 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -17,7 +17,7 @@ use crate::db::FileLabel; use crate::db::FileUpload; #[cfg(feature = "labels")] use crate::processing::labeling::label_frame; -#[cfg(feature = "nip96")] +#[cfg(feature = "media-compression")] use crate::processing::{compress_file, probe_file, FileProcessorResult, ProbeStream}; use crate::settings::Settings; @@ -97,14 +97,14 @@ impl FileStore { info!("File saved to temp path: {}", tmp_path.to_str().unwrap()); - #[cfg(feature = "nip96")] + #[cfg(feature = "media-compression")] if compress { let start = SystemTime::now(); let proc_result = compress_file(tmp_path.clone(), mime_type)?; if let FileProcessorResult::NewFile(new_temp) = proc_result { let old_size = tmp_path.metadata()?.len(); let new_size = new_temp.result.metadata()?.len(); - let time_compress = SystemTime::now().duration_since(start).unwrap(); + let time_compress = SystemTime::now().duration_since(start)?; let start = SystemTime::now(); let blur_hash = blurhash::encode( 9, @@ -113,7 +113,7 @@ impl FileStore { new_temp.height as u32, new_temp.image.as_slice(), )?; - let time_blur_hash = SystemTime::now().duration_since(start).unwrap(); + let time_blur_hash = SystemTime::now().duration_since(start)?; let start = SystemTime::now(); #[cfg(feature = "labels")] @@ -131,7 +131,7 @@ impl FileStore { vec![] }; - let time_labels = SystemTime::now().duration_since(start).unwrap(); + let time_labels = SystemTime::now().duration_since(start)?; // delete old temp fs::remove_file(tmp_path)?; diff --git a/src/lib.rs b/src/lib.rs index ddf0e30..e20edc5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ pub mod auth; pub mod cors; pub mod db; pub mod filesystem; -#[cfg(feature = "nip96")] +#[cfg(feature = "media-compression")] pub mod processing; pub mod routes; pub mod settings; diff --git a/src/routes/blossom.rs b/src/routes/blossom.rs index 8a35beb..d03ad0d 100644 --- a/src/routes/blossom.rs +++ b/src/routes/blossom.rs @@ -56,10 +56,16 @@ struct BlossomError { pub message: String, } +#[cfg(feature = "media-compression")] pub fn blossom_routes() -> Vec { routes![delete_blob, upload, list_files, upload_head, upload_media] } +#[cfg(not(feature = "media-compression"))] +pub fn blossom_routes() -> Vec { + routes![delete_blob, upload, list_files, upload_head] +} + impl BlossomError { pub fn new(msg: String) -> Self { Self { message: msg } @@ -210,6 +216,7 @@ async fn upload( process_upload("upload", false, auth, fs, db, settings, webhook, data).await } +#[cfg(feature = "media-compression")] #[rocket::put("/media", data = "")] async fn upload_media( auth: BlossomAuth,