diff --git a/frontend/src/components/folder/list.rs b/frontend/src/components/folder/list.rs index af13e7d4f..3b88a35a8 100644 --- a/frontend/src/components/folder/list.rs +++ b/frontend/src/components/folder/list.rs @@ -1,6 +1,6 @@ use dioxus::prelude::*; -use nghe_types::music_folder::get_folder_stats::{ - GetFolderStatsParams, SubsonicGetFolderStatsBody, +use nghe_types::music_folder::get_music_folder_stats::{ + GetMusicFolderStatsParams, SubsonicGetMusicFolderStatsBody, }; use readable::byte::*; use readable::num::*; @@ -20,9 +20,9 @@ pub fn Folders() -> Element { let get_folder_stats_fut = use_resource(move || async move { Ok(common_state() .ok_or_else(|| anyhow::anyhow!("common state is none"))? - .send_with_common::<_, SubsonicGetFolderStatsBody>( + .send_with_common::<_, SubsonicGetMusicFolderStatsBody>( "/rest/getFolderStats", - GetFolderStatsParams {}, + GetMusicFolderStatsParams {}, ) .await? .root diff --git a/src/open_subsonic/music_folder/get_folder_stats.rs b/src/open_subsonic/music_folder/get_music_folder_stats.rs similarity index 86% rename from src/open_subsonic/music_folder/get_folder_stats.rs rename to src/open_subsonic/music_folder/get_music_folder_stats.rs index 45006ebf8..791eb9d6a 100644 --- a/src/open_subsonic/music_folder/get_folder_stats.rs +++ b/src/open_subsonic/music_folder/get_music_folder_stats.rs @@ -11,15 +11,15 @@ use crate::models::*; use crate::open_subsonic::id3::*; use crate::{Database, DatabasePool}; -add_common_validate!(GetFolderStatsParams, admin); -add_axum_response!(GetFolderStatsBody); +add_common_validate!(GetMusicFolderStatsParams, admin); +add_axum_response!(GetMusicFolderStatsBody); -#[add_convert_types(into = nghe_types::music_folder::get_folder_stats::FolderStats)] +#[add_convert_types(into = nghe_types::music_folder::get_music_folder_stats::MusicFolderStat)] #[derive(Debug, Queryable)] #[diesel(table_name = music_folders)] #[diesel(check_for_backend(diesel::pg::Pg))] #[cfg_attr(test, derive(PartialEq, Eq))] -struct FolderStats { +struct MusicFolderStat { #[diesel(embed)] music_folder: music_folders::MusicFolder, artist_count: i64, @@ -29,7 +29,7 @@ struct FolderStats { total_size: i64, } -async fn get_folder_stats(pool: &DatabasePool) -> Result> { +async fn get_music_folder_stats(pool: &DatabasePool) -> Result> { let songs_total_size = diesel::alias!(songs as songs_total_size); get_basic_artist_id3_db() @@ -52,21 +52,21 @@ async fn get_folder_stats(pool: &DatabasePool) -> Result> { .single_value() .assume_not_null(), )) - .get_results::(&mut pool.get().await?) + .get_results::(&mut pool.get().await?) .await .map_err(anyhow::Error::from) } -pub async fn get_folder_stats_handler( +pub async fn get_music_folder_stats_handler( State(database): State, - _: GetFolderStatsRequest, -) -> GetFolderStatsJsonResponse { + _: GetMusicFolderStatsRequest, +) -> GetMusicFolderStatsJsonResponse { Ok(axum::Json( - GetFolderStatsBody { - folder_stats: get_folder_stats(&database.pool) + GetMusicFolderStatsBody { + folder_stats: get_music_folder_stats(&database.pool) .await? .into_iter() - .map(FolderStats::into) + .map(MusicFolderStat::into) .collect(), } .into(), @@ -117,7 +117,7 @@ mod tests { }); infra.scan(.., None).await; - let folder_stats = get_folder_stats(infra.pool()) + let folder_stats = get_music_folder_stats(infra.pool()) .await .unwrap() .into_iter() @@ -138,7 +138,7 @@ mod tests { let song_count = song_fs_infos.len() as _; let total_size = song_fs_infos.iter().fold(0_u32, |aac, s| aac + s.file_size) as _; - FolderStats { + MusicFolderStat { music_folder, artist_count, album_count, diff --git a/src/open_subsonic/music_folder/mod.rs b/src/open_subsonic/music_folder/mod.rs index 720d140e6..af3adf1fd 100644 --- a/src/open_subsonic/music_folder/mod.rs +++ b/src/open_subsonic/music_folder/mod.rs @@ -1,10 +1,16 @@ -mod get_folder_stats; +mod get_music_folder_stats; use axum::routing::get; use axum::Router; pub fn router() -> Router { Router::new() - .route("/rest/getFolderStats", get(get_folder_stats::get_folder_stats_handler)) - .route("/rest/getFolderStats.view", get(get_folder_stats::get_folder_stats_handler)) + .route( + "/rest/getMusicFolderStats", + get(get_music_folder_stats::get_music_folder_stats_handler), + ) + .route( + "/rest/getMusicFolderStats.view", + get(get_music_folder_stats::get_music_folder_stats_handler), + ) } diff --git a/types/src/music_folder/get_folder_stats.rs b/types/src/music_folder/get_music_folder_stats.rs similarity index 67% rename from types/src/music_folder/get_folder_stats.rs rename to types/src/music_folder/get_music_folder_stats.rs index 4643f4cb7..a79e3e530 100644 --- a/types/src/music_folder/get_folder_stats.rs +++ b/types/src/music_folder/get_music_folder_stats.rs @@ -5,11 +5,11 @@ use nghe_proc_macros::{ use super::MusicFolderPath; #[add_common_convert] -pub struct GetFolderStatsParams {} +pub struct GetMusicFolderStatsParams {} #[add_types_derive] #[derive(Debug)] -pub struct FolderStats { +pub struct MusicFolderStat { pub music_folder: MusicFolderPath, pub artist_count: u32, pub album_count: u32, @@ -20,8 +20,8 @@ pub struct FolderStats { #[add_subsonic_response] #[derive(Debug)] -pub struct GetFolderStatsBody { - pub folder_stats: Vec, +pub struct GetMusicFolderStatsBody { + pub folder_stats: Vec, } -add_request_types_test!(GetFolderStatsParams); +add_request_types_test!(GetMusicFolderStatsParams); diff --git a/types/src/music_folder/mod.rs b/types/src/music_folder/mod.rs index 6bd62e53f..f69afaf7b 100644 --- a/types/src/music_folder/mod.rs +++ b/types/src/music_folder/mod.rs @@ -1,4 +1,4 @@ -pub mod get_folder_stats; +pub mod get_music_folder_stats; use nghe_proc_macros::add_types_derive; use uuid::Uuid;