A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at setup-tracing 66 lines 3.1 kB view raw
1use std::sync::{Arc, Mutex}; 2 3use actix_web::{web, HttpRequest, HttpResponse}; 4use albums::{get_album_tracks, get_albums, get_top_albums}; 5use anyhow::Error; 6use artists::{get_artist_albums, get_artist_tracks, get_artists, get_top_artists}; 7use duckdb::Connection; 8use scrobbles::{get_distinct_scrobbles, get_scrobbles}; 9use stats::{ 10 get_album_scrobbles, get_artist_scrobbles, get_scrobbles_per_day, get_scrobbles_per_month, 11 get_scrobbles_per_year, get_stats, get_track_scrobbles, 12}; 13use tracks::{get_loved_tracks, get_top_tracks, get_tracks}; 14 15use crate::handlers::artists::get_artist_listeners; 16 17pub mod albums; 18pub mod artists; 19pub mod scrobbles; 20pub mod stats; 21pub mod tracks; 22 23#[macro_export] 24macro_rules! read_payload { 25 ($payload:expr) => {{ 26 let mut body = Vec::new(); 27 while let Some(chunk) = $payload.next().await { 28 match chunk { 29 Ok(bytes) => body.extend_from_slice(&bytes), 30 Err(err) => return Err(err.into()), 31 } 32 } 33 body 34 }}; 35} 36 37pub async fn handle( 38 method: &str, 39 payload: &mut web::Payload, 40 req: &HttpRequest, 41 conn: Arc<Mutex<Connection>>, 42) -> Result<HttpResponse, Error> { 43 match method { 44 "library.getAlbums" => get_albums(payload, req, conn.clone()).await, 45 "library.getArtists" => get_artists(payload, req, conn.clone()).await, 46 "library.getTracks" => get_tracks(payload, req, conn.clone()).await, 47 "library.getScrobbles" => get_scrobbles(payload, req, conn.clone()).await, 48 "library.getDistinctScrobbles" => get_distinct_scrobbles(payload, req, conn.clone()).await, 49 "library.getLovedTracks" => get_loved_tracks(payload, req, conn.clone()).await, 50 "library.getStats" => get_stats(payload, req, conn.clone()).await, 51 "library.getTopAlbums" => get_top_albums(payload, req, conn.clone()).await, 52 "library.getTopArtists" => get_top_artists(payload, req, conn.clone()).await, 53 "library.getTopTracks" => get_top_tracks(payload, req, conn.clone()).await, 54 "library.getScrobblesPerDay" => get_scrobbles_per_day(payload, req, conn.clone()).await, 55 "library.getScrobblesPerMonth" => get_scrobbles_per_month(payload, req, conn.clone()).await, 56 "library.getScrobblesPerYear" => get_scrobbles_per_year(payload, req, conn.clone()).await, 57 "library.getAlbumScrobbles" => get_album_scrobbles(payload, req, conn.clone()).await, 58 "library.getArtistScrobbles" => get_artist_scrobbles(payload, req, conn.clone()).await, 59 "library.getTrackScrobbles" => get_track_scrobbles(payload, req, conn.clone()).await, 60 "library.getAlbumTracks" => get_album_tracks(payload, req, conn.clone()).await, 61 "library.getArtistAlbums" => get_artist_albums(payload, req, conn.clone()).await, 62 "library.getArtistTracks" => get_artist_tracks(payload, req, conn.clone()).await, 63 "library.getArtistListeners" => get_artist_listeners(payload, req, conn.clone()).await, 64 _ => return Err(anyhow::anyhow!("Method not found")), 65 } 66}