feat: add CLI args, health endpoint, and fix torznab search
- Add clap for CLI argument parsing (-c config, -p port)
- Add health endpoint showing service status at /api/health
- Add IndexerType enum for auto URL construction (jackett/prowlarr/torznab)
- Fix Axum 0.8 route syntax ({param} instead of :param)
- Fix torznab search to use 'q' param instead of artist/album (Jackett only supports q)
This commit is contained in:
+19
-4
@@ -2,6 +2,7 @@ use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use axum::Router;
|
||||
use clap::Parser;
|
||||
use music_agregator::{
|
||||
api, config,
|
||||
services::{IndexerService, MetadataService, TorrentService},
|
||||
@@ -11,6 +12,17 @@ use tower_http::cors::{Any, CorsLayer};
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "music-agregator")]
|
||||
#[command(about = "Music aggregation service with torrent and metadata integration")]
|
||||
struct Args {
|
||||
#[arg(short, long, default_value = "config.yaml")]
|
||||
config: String,
|
||||
|
||||
#[arg(short, long)]
|
||||
port: Option<u16>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::registry()
|
||||
@@ -18,10 +30,11 @@ async fn main() {
|
||||
.with(tracing_subscriber::EnvFilter::from_default_env())
|
||||
.init();
|
||||
|
||||
let config_path = std::env::var("CONFIG_PATH").unwrap_or_else(|_| "config.yaml".to_string());
|
||||
let config = match config::Config::load(&config_path) {
|
||||
let args = Args::parse();
|
||||
|
||||
let config = match config::Config::load(&args.config) {
|
||||
Ok(cfg) => {
|
||||
tracing::info!("loaded config from {}", config_path);
|
||||
tracing::info!("loaded config from {}", args.config);
|
||||
cfg
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -92,7 +105,9 @@ async fn main() {
|
||||
.layer(cors)
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||
let port = args.port.unwrap_or(config.app.port);
|
||||
let addr = format!("0.0.0.0:{}", port);
|
||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||
tracing::info!("listening on {}", listener.local_addr().unwrap());
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user