refactor: make media compression optional for blossom
This commit is contained in:
parent
1a35924e8b
commit
5453205a58
@ -16,9 +16,10 @@ name = "route96"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["nip96", "blossom", "analytics"]
|
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"]
|
labels = ["nip96", "dep:candle-core", "dep:candle-nn", "dep:candle-transformers"]
|
||||||
nip96 = ["dep:ffmpeg-sys-the-third", "dep:blurhash", "dep:libc"]
|
nip96 = ["media-compression"]
|
||||||
blossom = ["dep:ffmpeg-sys-the-third", "dep:libc"]
|
blossom = []
|
||||||
bin-void-cat-migrate = ["dep:sqlx-postgres", "dep:clap", "dep:clap_derive"]
|
bin-void-cat-migrate = ["dep:sqlx-postgres", "dep:clap", "dep:clap_derive"]
|
||||||
torrent-v2 = []
|
torrent-v2 = []
|
||||||
analytics = []
|
analytics = []
|
||||||
|
@ -11,13 +11,15 @@ Image hosting service
|
|||||||
- [BUD-05](https://github.com/hzrd149/blossom/blob/master/buds/05.md)
|
- [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-06](https://github.com/hzrd149/blossom/blob/master/buds/06.md)
|
||||||
- [BUD-08](https://github.com/hzrd149/blossom/blob/master/buds/08.md)
|
- [BUD-08](https://github.com/hzrd149/blossom/blob/master/buds/08.md)
|
||||||
- Image compression to WebP (FFMPEG, NIP-96 only)
|
- Image compression to WebP
|
||||||
- Blurhash calculation (NIP-96 only)
|
- Blurhash calculation
|
||||||
- AI image labeling ([ViT224](https://huggingface.co/google/vit-base-patch16-224))
|
- AI image labeling ([ViT224](https://huggingface.co/google/vit-base-patch16-224))
|
||||||
|
- Plausible analytics
|
||||||
|
|
||||||
## Planned
|
## Planned
|
||||||
|
|
||||||
- Torrent seed V2
|
- Torrent seed V2
|
||||||
|
- Payment system
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
@ -45,11 +47,12 @@ docker run --rm -it \
|
|||||||
|
|
||||||
### Feature Flags
|
### Feature Flags
|
||||||
|
|
||||||
Default = `nip96` & `blossom`
|
Default = `nip96` & `blossom` & `analytics`
|
||||||
|
|
||||||
- `nip96`: Enable NIP-96 support
|
- `nip96`: Enable NIP-96 support
|
||||||
- `blossom`: Enable blossom support
|
- `blossom`: Enable blossom support
|
||||||
- `labels`: Enable AI image labeling (Depends on `nip96`)
|
- `labels`: Enable AI image labeling (Depends on `nip96`)
|
||||||
|
- `analytics`: Enable pageview analytics reporting (Plausible)
|
||||||
|
|
||||||
### Default build:
|
### Default build:
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ use crate::db::FileLabel;
|
|||||||
use crate::db::FileUpload;
|
use crate::db::FileUpload;
|
||||||
#[cfg(feature = "labels")]
|
#[cfg(feature = "labels")]
|
||||||
use crate::processing::labeling::label_frame;
|
use crate::processing::labeling::label_frame;
|
||||||
#[cfg(feature = "nip96")]
|
#[cfg(feature = "media-compression")]
|
||||||
use crate::processing::{compress_file, probe_file, FileProcessorResult, ProbeStream};
|
use crate::processing::{compress_file, probe_file, FileProcessorResult, ProbeStream};
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
|
|
||||||
@ -97,14 +97,14 @@ impl FileStore {
|
|||||||
|
|
||||||
info!("File saved to temp path: {}", tmp_path.to_str().unwrap());
|
info!("File saved to temp path: {}", tmp_path.to_str().unwrap());
|
||||||
|
|
||||||
#[cfg(feature = "nip96")]
|
#[cfg(feature = "media-compression")]
|
||||||
if compress {
|
if compress {
|
||||||
let start = SystemTime::now();
|
let start = SystemTime::now();
|
||||||
let proc_result = compress_file(tmp_path.clone(), mime_type)?;
|
let proc_result = compress_file(tmp_path.clone(), mime_type)?;
|
||||||
if let FileProcessorResult::NewFile(new_temp) = proc_result {
|
if let FileProcessorResult::NewFile(new_temp) = proc_result {
|
||||||
let old_size = tmp_path.metadata()?.len();
|
let old_size = tmp_path.metadata()?.len();
|
||||||
let new_size = new_temp.result.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 start = SystemTime::now();
|
||||||
let blur_hash = blurhash::encode(
|
let blur_hash = blurhash::encode(
|
||||||
9,
|
9,
|
||||||
@ -113,7 +113,7 @@ impl FileStore {
|
|||||||
new_temp.height as u32,
|
new_temp.height as u32,
|
||||||
new_temp.image.as_slice(),
|
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();
|
let start = SystemTime::now();
|
||||||
|
|
||||||
#[cfg(feature = "labels")]
|
#[cfg(feature = "labels")]
|
||||||
@ -131,7 +131,7 @@ impl FileStore {
|
|||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
|
||||||
let time_labels = SystemTime::now().duration_since(start).unwrap();
|
let time_labels = SystemTime::now().duration_since(start)?;
|
||||||
|
|
||||||
// delete old temp
|
// delete old temp
|
||||||
fs::remove_file(tmp_path)?;
|
fs::remove_file(tmp_path)?;
|
||||||
|
@ -4,7 +4,7 @@ pub mod auth;
|
|||||||
pub mod cors;
|
pub mod cors;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod filesystem;
|
pub mod filesystem;
|
||||||
#[cfg(feature = "nip96")]
|
#[cfg(feature = "media-compression")]
|
||||||
pub mod processing;
|
pub mod processing;
|
||||||
pub mod routes;
|
pub mod routes;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
@ -56,10 +56,16 @@ struct BlossomError {
|
|||||||
pub message: String,
|
pub message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "media-compression")]
|
||||||
pub fn blossom_routes() -> Vec<Route> {
|
pub fn blossom_routes() -> Vec<Route> {
|
||||||
routes![delete_blob, upload, list_files, upload_head, upload_media]
|
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 {
|
impl BlossomError {
|
||||||
pub fn new(msg: String) -> Self {
|
pub fn new(msg: String) -> Self {
|
||||||
Self { message: msg }
|
Self { message: msg }
|
||||||
@ -210,6 +216,7 @@ async fn upload(
|
|||||||
process_upload("upload", false, auth, fs, db, settings, webhook, data).await
|
process_upload("upload", false, auth, fs, db, settings, webhook, data).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "media-compression")]
|
||||||
#[rocket::put("/media", data = "<data>")]
|
#[rocket::put("/media", data = "<data>")]
|
||||||
async fn upload_media(
|
async fn upload_media(
|
||||||
auth: BlossomAuth,
|
auth: BlossomAuth,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user