refactor: make media compression optional for blossom
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
kieran 2024-10-15 11:14:07 +01:00
parent 1a35924e8b
commit 5453205a58
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 22 additions and 11 deletions

View File

@ -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 = []

View File

@ -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:

View File

@ -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)?;

View File

@ -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;

View File

@ -56,10 +56,16 @@ struct BlossomError {
pub message: String,
}
#[cfg(feature = "media-compression")]
pub fn blossom_routes() -> Vec<Route> {
routes![delete_blob, upload, list_files, upload_head, upload_media]
}
#[cfg(not(feature = "media-compression"))]
pub fn blossom_routes() -> Vec<Route> {
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 = "<data>")]
async fn upload_media(
auth: BlossomAuth,