fix: build variants

This commit is contained in:
2025-03-31 10:17:55 +01:00
parent 6ba1f2ae9c
commit 915624b2d7
9 changed files with 42 additions and 51 deletions

View File

@ -24,7 +24,7 @@ required-features = ["r96util"]
name = "route96"
[features]
default = ["nip96", "blossom", "analytics", "ranges", "react-ui", "r96util"]
default = ["nip96", "blossom", "analytics", "react-ui", "r96util"]
media-compression = ["dep:ffmpeg-rs-raw", "dep:libc"]
labels = ["nip96", "dep:candle-core", "dep:candle-nn", "dep:candle-transformers"]
nip96 = ["media-compression"]
@ -34,7 +34,6 @@ bin-void-cat-force-migrate = ["dep:regex", "dep:nostr-cursor"]
torrent-v2 = []
analytics = []
void-cat-redirects = ["dep:sqlx-postgres"]
ranges = ["dep:http-range-header"]
react-ui = []
r96util = ["dep:walkdir", "dep:indicatif"]
@ -58,6 +57,7 @@ reqwest = { version = "0.12.8", features = ["stream"] }
clap = { version = "4.5.18", features = ["derive"] }
mime2ext = "0.1.53"
infer = "0.16.0"
http-range-header = { version = "0.4.2" }
tokio-util = { version = "0.7.13", features = ["io", "io-util"] }
@ -67,7 +67,7 @@ candle-core = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1"
candle-nn = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1", optional = true }
candle-transformers = { git = "https://git.v0l.io/huggingface/candle.git", tag = "0.8.1", optional = true }
sqlx-postgres = { version = "0.8.2", optional = true, features = ["chrono", "uuid"] }
http-range-header = { version = "0.4.2", optional = true }
nostr-cursor = { git = "https://git.v0l.io/Kieran/nostr-backup-util.git", branch = "main", optional = true }
regex = { version = "1.11.1", optional = true }
walkdir = { version = "2.5.0", optional = true }

View File

@ -1,7 +1,6 @@
use crate::db::Database;
use crate::filesystem::FileStore;
use anyhow::Result;
use log::info;
use tokio::task::JoinHandle;
#[cfg(feature = "media-compression")]
@ -13,10 +12,10 @@ pub fn start_background_tasks(db: Database, file_store: FileStore) -> Vec<JoinHa
#[cfg(feature = "media-compression")]
{
ret.push(tokio::spawn(async move {
info!("Starting MediaMetadata background task");
log::info!("Starting MediaMetadata background task");
let mut m = media_metadata::MediaMetadata::new(db.clone(), file_store.clone());
m.process().await?;
info!("MediaMetadata background task completed");
log::info!("MediaMetadata background task completed");
Ok(())
}));
}

View File

@ -54,7 +54,7 @@ async fn main() -> Result<(), Error> {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
pretty_env_logger::init();
env_logger::init();
let args: Args = Args::parse();

View File

@ -24,7 +24,7 @@ struct ProgramArgs {
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
pretty_env_logger::init();
env_logger::init();
let args: ProgramArgs = ProgramArgs::parse();

View File

@ -34,7 +34,7 @@ struct Args {
#[tokio::main]
async fn main() -> Result<(), Error> {
pretty_env_logger::init();
env_logger::init();
let builder = Config::builder()
.add_source(config::File::with_name("config.yaml"))

View File

@ -1,6 +1,6 @@
#[cfg(feature = "labels")]
use crate::db::FileLabel;
use crate::processing::can_compress;
#[cfg(feature = "labels")]
use crate::processing::labeling::label_frame;
#[cfg(feature = "media-compression")]
@ -78,7 +78,7 @@ impl FileStore {
return Ok(FileSystemResult::AlreadyExists(hash));
}
let mut res = if compress && can_compress(mime_type) {
let mut res = if compress && crate::can_compress(mime_type) {
#[cfg(feature = "media-compression")]
{
let res = match self.compress_file(&temp_file, mime_type).await {
@ -180,7 +180,8 @@ impl FileStore {
}
}
async fn compress_file(&self, input: &PathBuf, mime_type: &str) -> Result<NewFileResult> {
#[cfg(feature = "media-compression")]
async fn compress_file(&self, input: &Path, mime_type: &str) -> Result<NewFileResult> {
let compressed_result = compress_file(input, mime_type, &self.temp_dir())?;
#[cfg(feature = "labels")]
let labels = if let Some(mp) = &self.settings.vit_model {

View File

@ -12,3 +12,7 @@ pub mod settings;
#[cfg(any(feature = "void-cat-redirects", feature = "bin-void-cat-migrate"))]
pub mod void_db;
pub mod void_file;
pub fn can_compress(mime_type: &str) -> bool {
mime_type.starts_with("image/")
}

View File

@ -136,16 +136,12 @@ pub struct NewFileProcessorResult {
pub bitrate: u32,
}
pub fn can_compress(mime_type: &str) -> bool {
mime_type.starts_with("image/")
}
pub fn compress_file(
path: &Path,
mime_type: &str,
out_dir: &Path,
) -> Result<NewFileProcessorResult, Error> {
if !can_compress(mime_type) {
if !crate::can_compress(mime_type) {
bail!("MIME type not supported");
}

View File

@ -219,8 +219,6 @@ impl<'r> Responder<'r, 'static> for FilePayload {
response.set_header(Header::new("cache-control", "max-age=31536000, immutable"));
// handle ranges
#[cfg(feature = "ranges")]
{
// only use range response for files > 1MiB
if self.info.size < MAX_UNBOUNDED_RANGE {
response.set_sized_body(None, self.file);
@ -229,9 +227,7 @@ impl<'r> Responder<'r, 'static> for FilePayload {
if let Some(r) = request.headers().get("range").next() {
if let Ok(ranges) = parse_range_header(r) {
if ranges.ranges.len() > 1 {
warn!(
"Multipart ranges are not supported, fallback to non-range request"
);
warn!("Multipart ranges are not supported, fallback to non-range request");
response.set_streamed_body(self.file);
} else {
let single_range = ranges.ranges.first().unwrap();
@ -250,11 +246,6 @@ impl<'r> Responder<'r, 'static> for FilePayload {
response.set_sized_body(None, self.file);
}
}
}
#[cfg(not(feature = "ranges"))]
{
response.set_sized_body(None, self.file);
}
if let Ok(ct) = ContentType::from_str(&self.info.mime_type) {
response.set_header(ct);