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:
+34
-2
@@ -16,10 +16,11 @@ use crate::AppState;
|
||||
|
||||
pub fn routes(state: AppState) -> Router {
|
||||
Router::new()
|
||||
.route("/health", get(health))
|
||||
.route("/tracks", get(list_tracks))
|
||||
.route("/tracks", post(create_track))
|
||||
.route("/tracks/:id", get(get_track))
|
||||
.route("/tracks/:id", delete(delete_track))
|
||||
.route("/tracks/{id}", get(get_track))
|
||||
.route("/tracks/{id}", delete(delete_track))
|
||||
.route("/tracks/search", get(search_tracks))
|
||||
.route("/stats", get(get_stats))
|
||||
.nest("/indexers", indexer_controller::routes())
|
||||
@@ -28,6 +29,37 @@ pub fn routes(state: AppState) -> Router {
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct Health {
|
||||
status: &'static str,
|
||||
services: ServiceStatus,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct ServiceStatus {
|
||||
torrent: bool,
|
||||
metadata: bool,
|
||||
indexers: Vec<String>,
|
||||
}
|
||||
|
||||
async fn health(State(state): State<AppState>) -> Json<Health> {
|
||||
let state = state.read().await;
|
||||
let indexers = state
|
||||
.indexer_service
|
||||
.list_indexers()
|
||||
.into_iter()
|
||||
.map(|i| i.name)
|
||||
.collect();
|
||||
Json(Health {
|
||||
status: "ok",
|
||||
services: ServiceStatus {
|
||||
torrent: state.torrent_service.is_connected().await,
|
||||
metadata: state.metadata_service.is_connected(),
|
||||
indexers,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async fn list_tracks(State(state): State<AppState>) -> Json<Vec<Track>> {
|
||||
let state = state.read().await;
|
||||
Json(state.aggregator.get_all().to_vec())
|
||||
|
||||
Reference in New Issue
Block a user