Fix Clippy format string lints

This commit is contained in:
2025-04-29 21:32:18 +00:00
parent cf35961516
commit ff8fd283b6
18 changed files with 79 additions and 79 deletions

View File

@ -23,7 +23,7 @@ pub async fn get_album(id: i32) -> Result<Option<frontend::Album>, ServerFnError
.find(id)
.first::<Album>(db_con)
.optional()
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {e}")))?;
let Some(album) = album else { return Ok(None) };

View File

@ -50,7 +50,7 @@ pub async fn add_album(album_title: String, release_date: Option<String>, image_
diesel::insert_into(albums::table)
.values(&new_album)
.execute(db)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error adding album: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error adding album: {e}")))?;
Ok(())
}

View File

@ -38,7 +38,7 @@ pub async fn add_artist(artist_name: String) -> Result<(), ServerFnError> {
diesel::insert_into(artists)
.values(&new_artist)
.execute(db)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error adding artist: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error adding artist: {e}")))?;
Ok(())
}
@ -53,7 +53,7 @@ pub async fn get_artist_by_id(artist_id: i32) -> Result<Option<Artist>, ServerFn
.filter(id.eq(artist_id))
.first::<Artist>(db)
.optional()
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting artist: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting artist: {e}")))?;
Ok(artist)
}
@ -66,7 +66,7 @@ pub async fn top_songs_by_artist(artist_id: i32, limit: Option<i64>) -> Result<V
use leptos::server_fn::error::NoCustomError;
let user_id = get_user().await
.map_err(|e| ServerFnError::ServerError::<NoCustomError>(format!("Error getting user: {}", e)))?.id.unwrap();
.map_err(|e| ServerFnError::ServerError::<NoCustomError>(format!("Error getting user: {e}")))?.id.unwrap();
let db = &mut get_db_conn();
let song_play_counts: Vec<(i32, i64)> =

View File

@ -34,10 +34,10 @@ pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
};
create_user(&new_user).await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error creating user: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error creating user: {e}")))?;
let mut auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
let credentials = UserCredentials {
username_or_email: new_user.username.clone(),
@ -47,13 +47,13 @@ pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
match auth_session.authenticate(credentials).await {
Ok(Some(user)) => {
auth_session.login(&user).await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error logging in user: {}", e)))
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error logging in user: {e}")))
},
Ok(None) => {
Err(ServerFnError::<NoCustomError>::ServerError("Error authenticating user: User not found".to_string()))
},
Err(e) => {
Err(ServerFnError::<NoCustomError>::ServerError(format!("Error authenticating user: {}", e)))
Err(ServerFnError::<NoCustomError>::ServerError(format!("Error authenticating user: {e}")))
}
}
}
@ -66,14 +66,14 @@ pub async fn login(credentials: UserCredentials) -> Result<Option<User>, ServerF
use crate::api::users::validate_user;
let mut auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
let user = validate_user(credentials).await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error validating user: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error validating user: {e}")))?;
if let Some(mut user) = user {
auth_session.login(&user).await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error logging in user: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error logging in user: {e}")))?;
user.password = None;
Ok(Some(user))
@ -87,10 +87,10 @@ pub async fn login(credentials: UserCredentials) -> Result<Option<User>, ServerF
#[server(endpoint = "logout")]
pub async fn logout() -> Result<(), ServerFnError> {
let mut auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
auth_session.logout().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
leptos_axum::redirect("/login");
Ok(())
@ -101,7 +101,7 @@ pub async fn logout() -> Result<(), ServerFnError> {
#[server(endpoint = "check_auth")]
pub async fn check_auth() -> Result<bool, ServerFnError> {
let auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
Ok(auth_session.user.is_some())
}
@ -148,7 +148,7 @@ pub async fn require_auth() -> Result<(), ServerFnError> {
#[cfg(feature = "ssr")]
pub async fn get_user() -> Result<User, ServerFnError> {
let auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
auth_session.user.ok_or(ServerFnError::<NoCustomError>::ServerError("User not logged in".to_string()))
}
@ -156,7 +156,7 @@ pub async fn get_user() -> Result<User, ServerFnError> {
#[server(endpoint = "get_logged_in_user")]
pub async fn get_logged_in_user() -> Result<Option<User>, ServerFnError> {
let auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
let user = auth_session.user.map(|mut user| {
user.password = None;
@ -171,7 +171,7 @@ pub async fn get_logged_in_user() -> Result<Option<User>, ServerFnError> {
#[server(endpoint = "check_admin")]
pub async fn check_admin() -> Result<bool, ServerFnError> {
let auth_session = extract::<AuthSession<AuthBackend>>().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting auth session: {e}")))?;
Ok(auth_session.user.as_ref().map(|u| u.admin).unwrap_or(false))
}

View File

@ -19,7 +19,7 @@ pub async fn get_history(limit: Option<i64>) -> Result<Vec<HistoryEntry>, Server
let user = get_user().await?;
let db_con = &mut get_db_conn();
let history = user.get_history(limit, db_con)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting history: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting history: {e}")))?;
Ok(history)
}
@ -29,7 +29,7 @@ pub async fn get_history_songs(limit: Option<i64>) -> Result<Vec<(NaiveDateTime,
let user = get_user().await?;
let db_con = &mut get_db_conn();
let songs = user.get_history_songs(limit, db_con)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting history songs: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting history songs: {e}")))?;
Ok(songs)
}
@ -39,6 +39,6 @@ pub async fn add_history(song_id: i32) -> Result<(), ServerFnError> {
let user = get_user().await?;
let db_con = &mut get_db_conn();
user.add_history(song_id, db_con)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error adding history: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error adding history: {e}")))?;
Ok(())
}

View File

@ -28,7 +28,7 @@ pub async fn upload_picture(data: MultipartData) -> Result<(), ServerFnError> {
let mut data = data.into_inner().unwrap();
let field = data.next_field().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting field: {}", e)))?
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting field: {e}")))?
.ok_or_else(|| ServerFnError::<NoCustomError>::ServerError("No field found".to_string()))?;
if field.name() != Some("picture") {
@ -37,7 +37,7 @@ pub async fn upload_picture(data: MultipartData) -> Result<(), ServerFnError> {
// Get user id from session
let user = get_user().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user: {e}")))?;
let user_id = user.id.ok_or_else(|| ServerFnError::<NoCustomError>::ServerError("User has no id".to_string()))?;
@ -45,16 +45,16 @@ pub async fn upload_picture(data: MultipartData) -> Result<(), ServerFnError> {
use image_convert::{to_webp, WEBPConfig, ImageResource};
let bytes = field.bytes().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting field bytes: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting field bytes: {e}")))?;
let reader = std::io::Cursor::new(bytes);
let image_source = ImageResource::from_reader(reader)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error creating image resource: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error creating image resource: {e}")))?;
let profile_picture_path = format!("assets/images/profile/{}.webp", user_id);
let profile_picture_path = format!("assets/images/profile/{user_id}.webp");
let mut image_target = ImageResource::from_path(&profile_picture_path);
to_webp(&mut image_target, &image_source, &WEBPConfig::new())
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error converting image to webp: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error converting image to webp: {e}")))?;
Ok(())
}
@ -67,7 +67,7 @@ pub async fn upload_picture(data: MultipartData) -> Result<(), ServerFnError> {
#[server(endpoint = "/profile/recent_songs")]
pub async fn recent_songs(for_user_id: i32, limit: Option<i64>) -> Result<Vec<(NaiveDateTime, frontend::Song)>, ServerFnError> {
let viewing_user_id = get_user().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user: {}", e)))?.id.unwrap();
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user: {e}")))?.id.unwrap();
let mut db_con = get_db_conn();
@ -161,7 +161,7 @@ pub async fn recent_songs(for_user_id: i32, limit: Option<i64>) -> Result<Vec<(N
pub async fn top_songs(for_user_id: i32, start_date: NaiveDateTime, end_date: NaiveDateTime, limit: Option<i64>)
-> Result<Vec<(i64, frontend::Song)>, ServerFnError>
{ let viewing_user_id = get_user().await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user: {}", e)))?.id.unwrap();
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user: {e}")))?.id.unwrap();
let mut db_con = get_db_conn();

View File

@ -18,31 +18,31 @@ cfg_if! {
#[server(endpoint = "songs/set_like")]
pub async fn set_like_song(song_id: i32, like: bool) -> Result<(), ServerFnError> {
let user = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting user: {}", e)))?;
ServerError(format!("Error getting user: {e}")))?;
let db_con = &mut get_db_conn();
user.set_like_song(song_id, like, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error liking song: {}", e)))
ServerError(format!("Error liking song: {e}")))
}
/// Dislike or remove dislike from a song
#[server(endpoint = "songs/set_dislike")]
pub async fn set_dislike_song(song_id: i32, dislike: bool) -> Result<(), ServerFnError> {
let user = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting user: {}", e)))?;
ServerError(format!("Error getting user: {e}")))?;
let db_con = &mut get_db_conn();
user.set_dislike_song(song_id, dislike, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error disliking song: {}", e)))
ServerError(format!("Error disliking song: {e}")))
}
/// Get the like and dislike status of a song
#[server(endpoint = "songs/get_like_dislike")]
pub async fn get_like_dislike_song(song_id: i32) -> Result<(bool, bool), ServerFnError> {
let user = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting user: {}", e)))?;
ServerError(format!("Error getting user: {e}")))?;
let db_con = &mut get_db_conn();
@ -50,9 +50,9 @@ pub async fn get_like_dislike_song(song_id: i32) -> Result<(bool, bool), ServerF
// doing so is much more complicated than it would initially seem
let like = user.get_like_song(song_id, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting song liked: {}", e)))?;
ServerError(format!("Error getting song liked: {e}")))?;
let dislike = user.get_dislike_song(song_id, db_con).await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting song disliked: {}", e)))?;
ServerError(format!("Error getting song disliked: {e}")))?;
Ok((like, dislike))
}
@ -62,7 +62,7 @@ pub async fn get_song_by_id(song_id: i32) -> Result<Option<frontend::Song>, Serv
use crate::schema::*;
let user_id: i32 = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting user: {}", e)))?.id.unwrap();
ServerError(format!("Error getting user: {e}")))?.id.unwrap();
let db_con = &mut get_db_conn();
@ -124,7 +124,7 @@ pub async fn get_song_plays(song_id: i32) -> Result<i64, ServerFnError> {
.count()
.get_result::<i64>(db_con)
.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting song plays: {}", e)))?;
ServerError(format!("Error getting song plays: {e}")))?;
Ok(plays)
}
@ -134,7 +134,7 @@ pub async fn get_my_song_plays(song_id: i32) -> Result<i64, ServerFnError> {
use crate::schema::*;
let user_id: i32 = get_user().await.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting user: {}", e)))?.id.unwrap();
ServerError(format!("Error getting user: {e}")))?.id.unwrap();
let db_con = &mut get_db_conn();
@ -143,7 +143,7 @@ pub async fn get_my_song_plays(song_id: i32) -> Result<i64, ServerFnError> {
.count()
.get_result::<i64>(db_con)
.map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error getting song plays: {}", e)))?;
ServerError(format!("Error getting song plays: {e}")))?;
Ok(plays)
}

View File

@ -19,7 +19,7 @@ cfg_if! {
async fn extract_field(field: Field<'static>) -> Result<String, ServerFnError> {
let field = match field.text().await {
Ok(field) => field,
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading field: {}", e)))?,
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading field: {e}")))?,
};
Ok(field)
@ -49,7 +49,7 @@ async fn validate_artist_ids(artist_ids: Field<'static>) -> Result<Vec<i32>, Ser
Err(NotFound) => Err(ServerFnError::<NoCustomError>::
ServerError("Artist does not exist".to_string())),
Err(e) => Err(ServerFnError::<NoCustomError>::
ServerError(format!("Error finding artist id: {}", e))),
ServerError(format!("Error finding artist id: {e}"))),
}
} else {
Err(ServerFnError::<NoCustomError>::ServerError("Error parsing artist id".to_string()))
@ -57,7 +57,7 @@ async fn validate_artist_ids(artist_ids: Field<'static>) -> Result<Vec<i32>, Ser
}).collect()
},
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading artist id: {}", e))),
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading artist id: {e}"))),
}
}
@ -86,13 +86,13 @@ async fn validate_album_id(album_id: Field<'static>) -> Result<Option<i32>, Serv
Err(NotFound) => Err(ServerFnError::<NoCustomError>::
ServerError("Album does not exist".to_string())),
Err(e) => Err(ServerFnError::<NoCustomError>::
ServerError(format!("Error finding album id: {}", e))),
ServerError(format!("Error finding album id: {e}"))),
}
} else {
Err(ServerFnError::<NoCustomError>::ServerError("Error parsing album id".to_string()))
}
},
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading album id: {}", e))),
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading album id: {e}"))),
}
}
@ -117,7 +117,7 @@ async fn validate_track_number(track_number: Field<'static>) -> Result<Option<i3
Err(ServerFnError::<NoCustomError>::ServerError("Error parsing track number".to_string()))
}
},
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading track number: {}", e)))?,
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading track number: {e}")))?,
}
}
@ -138,7 +138,7 @@ async fn validate_release_date(release_date: Field<'static>) -> Result<Option<Na
Err(_) => Err(ServerFnError::<NoCustomError>::ServerError("Invalid release date".to_string())),
}
},
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading release date: {}", e))),
Err(e) => Err(ServerFnError::<NoCustomError>::ServerError(format!("Error reading release date: {e}"))),
}
}
@ -181,8 +181,8 @@ pub async fn upload(data: MultipartData) -> Result<(), ServerFnError> {
let clean_title = title.replace(" ", "_").replace("/", "_");
let date_str = chrono::Utc::now().format("%Y-%m-%d_%H:%M:%S").to_string();
let upload_path = format!("assets/audio/upload-{}_{}.mp3", date_str, clean_title);
file_name = Some(format!("upload-{}_{}.mp3", date_str, clean_title));
let upload_path = format!("assets/audio/upload-{date_str}_{clean_title}.mp3");
file_name = Some(format!("upload-{date_str}_{clean_title}.mp3"));
debug!("Saving uploaded file {}", upload_path);
@ -207,13 +207,13 @@ pub async fn upload(data: MultipartData) -> Result<(), ServerFnError> {
// Get the codec and duration of the file
let (file_codec, file_duration) = extract_metadata(file)
.map_err(|e| {
let msg = format!("Error measuring duration of audio file {}: {}", upload_path, e);
let msg = format!("Error measuring duration of audio file {upload_path}: {e}");
warn!("{}", msg);
ServerFnError::<NoCustomError>::ServerError(msg)
})?;
if file_codec != CODEC_TYPE_MP3 {
let msg = format!("Invalid uploaded audio file codec: {}", file_codec);
let msg = format!("Invalid uploaded audio file codec: {file_codec}");
warn!("{}", msg);
return Err(ServerFnError::<NoCustomError>::ServerError(msg));
}
@ -232,7 +232,7 @@ pub async fn upload(data: MultipartData) -> Result<(), ServerFnError> {
let file_name = file_name.ok_or(ServerFnError::<NoCustomError>::ServerError("Missing file".to_string()))?;
let duration = duration.ok_or(ServerFnError::<NoCustomError>::ServerError("Missing duration".to_string()))?;
let duration = i32::try_from(duration).map_err(|e| ServerFnError::<NoCustomError>::
ServerError(format!("Error converting duration to i32: {}", e)))?;
ServerError(format!("Error converting duration to i32: {e}")))?;
let album_id = album_id.unwrap_or(None);
let track = track.unwrap_or(None);
@ -262,7 +262,7 @@ pub async fn upload(data: MultipartData) -> Result<(), ServerFnError> {
let song = song.insert_into(crate::schema::songs::table)
.get_result::<Song>(db_con)
.map_err(|e| {
let msg = format!("Error saving song to database: {}", e);
let msg = format!("Error saving song to database: {e}");
warn!("{}", msg);
ServerFnError::<NoCustomError>::ServerError(msg)
})?;
@ -285,7 +285,7 @@ pub async fn upload(data: MultipartData) -> Result<(), ServerFnError> {
.values(&artist_ids)
.execute(db_con)
.map_err(|e| {
let msg = format!("Error saving song artists to database: {}", e);
let msg = format!("Error saving song artists to database: {e}");
warn!("{}", msg);
ServerFnError::<NoCustomError>::ServerError(msg)
})?;

View File

@ -34,7 +34,7 @@ pub async fn find_user(username_or_email: String) -> Result<Option<User>, Server
let db_con = &mut get_db_conn();
let user = users.filter(username.eq(username_or_email.clone())).or_filter(email.eq(username_or_email))
.first::<User>(db_con).optional()
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {e}")))?;
Ok(user)
}
@ -49,7 +49,7 @@ pub async fn find_user_by_id(user_id: i32) -> Result<Option<User>, ServerFnError
let db_con = &mut get_db_conn();
let user = users.filter(id.eq(user_id))
.first::<User>(db_con).optional()
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {e}")))?;
Ok(user)
}
@ -76,7 +76,7 @@ pub async fn create_user(new_user: &User) -> Result<(), ServerFnError> {
let db_con = &mut get_db_conn();
diesel::insert_into(users).values(&new_user).execute(db_con)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error creating user: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error creating user: {e}")))?;
Ok(())
}
@ -88,7 +88,7 @@ pub async fn validate_user(credentials: UserCredentials) -> Result<Option<User>,
use leptos::server_fn::error::NoCustomError;
let db_user = find_user(credentials.username_or_email.clone()).await
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting user from database: {e}")))?;
// If the user is not found, return None
let db_user = match db_user {
@ -100,7 +100,7 @@ pub async fn validate_user(credentials: UserCredentials) -> Result<Option<User>,
.ok_or(ServerFnError::<NoCustomError>::ServerError(format!("No password found for user {}", db_user.username)))?;
let password_hash = PasswordHash::new(&db_password)
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error hashing supplied password: {}", e)))?;
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error hashing supplied password: {e}")))?;
match Pbkdf2.verify_password(credentials.password.as_bytes(), &password_hash) {
Ok(()) => {},
@ -108,7 +108,7 @@ pub async fn validate_user(credentials: UserCredentials) -> Result<Option<User>,
return Ok(None);
},
Err(e) => {
return Err(ServerFnError::<NoCustomError>::ServerError(format!("Error verifying password: {}", e)));
return Err(ServerFnError::<NoCustomError>::ServerError(format!("Error verifying password: {e}")));
}
}

View File

@ -19,7 +19,7 @@ pub fn ServerError<E: Display + 'static>(
<h1>{move || title.get()}</h1>
</div>
<p>{move || message.get()}</p>
<p>{error.map(|error| format!("{}", error))}</p>
<p>{error.map(|error| format!("{error}"))}</p>
</div>
}
}
@ -40,7 +40,7 @@ pub fn Error<E: Display + 'static>(
<h1 class="self-center">{move || title.get()}</h1>
</div>
<p>{move || message.get()}</p>
<p>{error.map(|error| format!("{}", error))}</p>
<p>{error.map(|error| format!("{error}"))}</p>
</div>
}
}

View File

@ -173,7 +173,7 @@ fn PlayDuration(elapsed_secs: Signal<i64>, total_secs: Signal<i64>) -> impl Into
let total_secs = total_secs.get() % 60;
// Format as "MM:SS / MM:SS"
format!("{}:{:0>2} / {}:{:0>2}", elapsed_mins, elapsed_secs, total_mins, total_secs)
format!("{elapsed_mins}:{elapsed_secs:0>2} / {total_mins}:{total_secs:0>2}")
});
view! {

View File

@ -155,7 +155,7 @@ pub fn SongArtists(artists: Vec<Artist>) -> impl IntoView {
{
if let Some(id) = artist.id {
Either::Left(view! { <a class="hover:underline active:text-controls-active"
href={format!("/artist/{}", id)}>{artist.name.clone()}</a> })
href={format!("/artist/{id}")}>{artist.name.clone()}</a> })
} else {
Either::Right(view! { <span>{artist.name.clone()}</span> })
}
@ -182,7 +182,7 @@ pub fn SongAlbum(album: Option<Album>) -> impl IntoView {
{
if let Some(id) = album.id {
Either::Left(view! { <a class="hover:underline active:text-controls-active"
href={format!("/album/{}", id)}>{album.title.clone()}</a> })
href={format!("/album/{id}")}>{album.title.clone()}</a> })
} else {
Either::Right(view! { <span>{album.title.clone()}</span> })
}

View File

@ -36,7 +36,7 @@ async fn main() {
let redis_url = std::env::var("REDIS_URL").expect("REDIS_URL must be set");
let redis_config = fred::types::config::Config::from_url(&redis_url)
.unwrap_or_else(|_| panic!("Unable to parse Redis URL: {}", redis_url));
.unwrap_or_else(|_| panic!("Unable to parse Redis URL: {redis_url}"));
let redis_pool = fred::clients::Pool::new(redis_config, None, None, None, 1).expect("Unable to create Redis pool");
redis_pool.connect();
redis_pool.wait_for_connect().await.expect("Unable to connect to Redis");

View File

@ -86,7 +86,7 @@ fn ArtistIdProfile(#[prop(into)] id: Signal<i32>) -> impl IntoView {
#[component]
fn ArtistProfile(artist: Artist) -> impl IntoView {
let artist_id = artist.id.unwrap();
let profile_image_path = format!("/assets/images/artist/{}.webp", artist_id);
let profile_image_path = format!("/assets/images/artist/{artist_id}.webp");
leptos::logging::log!("Artist name: {}", artist.name);
@ -110,7 +110,7 @@ fn TopSongsByArtist(#[prop(into)] artist_id: Signal<i32>) -> impl IntoView {
let plays = if plays == 1 {
"1 play".to_string()
} else {
format!("{} plays", plays)
format!("{plays} plays")
};
(song, plays)

View File

@ -143,7 +143,7 @@ fn UserIdProfile(#[prop(into)] id: Signal<i32>) -> impl IntoView {
#[component]
fn UserProfile(user: User) -> impl IntoView {
let user_id = user.id.unwrap();
let profile_image_path = format!("/assets/images/profile/{}.webp", user_id);
let profile_image_path = format!("/assets/images/profile/{user_id}.webp");
view! {
<div class="flex">
@ -182,9 +182,9 @@ fn TopSongs(#[prop(into)] user_id: Signal<i32>) -> impl IntoView {
top_songs.map(|top_songs| {
top_songs.into_iter().map(|(plays, song)| {
let plays = if plays == 1 {
format!("{} Play", plays)
format!("{plays} Play")
} else {
format!("{} Plays", plays)
format!("{plays} Plays")
};
(song, plays)
@ -194,7 +194,7 @@ fn TopSongs(#[prop(into)] user_id: Signal<i32>) -> impl IntoView {
view! {
<h2 class="text-xl font-bold">{format!("Top Songs {}", HISTORY_MESSAGE)}</h2>
<h2 class="text-xl font-bold">{format!("Top Songs {HISTORY_MESSAGE}")}</h2>
<Transition
fallback=move || view! { <Loading /> }
>
@ -282,13 +282,13 @@ fn TopArtists(#[prop(into)] user_id: Signal<i32>) -> impl IntoView {
view! {
<Transition
fallback=move || view! {
<h2 class="text-xl font-bold">{format!("Top Artists {}", HISTORY_MESSAGE)}</h2>
<h2 class="text-xl font-bold">{format!("Top Artists {HISTORY_MESSAGE}")}</h2>
<Loading />
}
>
<ErrorBoundary
fallback=|errors| view! {
<h2 class="text-xl font-bold">{format!("Top Artists {}", HISTORY_MESSAGE)}</h2>
<h2 class="text-xl font-bold">{format!("Top Artists {HISTORY_MESSAGE}")}</h2>
{move || errors.get()
.into_iter()
.map(|(_, e)| view! { <p>{e.to_string()}</p>})

View File

@ -149,7 +149,7 @@ fn SongPlays(#[prop(into)] id: Signal<i32>) -> impl IntoView {
match plays {
Ok(plays) => {
Either::Left(view! {
<p>{format!("Plays: {}", plays)}</p>
<p>{format!("Plays: {plays}")}</p>
})
},
Err(error) => {
@ -178,7 +178,7 @@ fn MySongPlays(#[prop(into)] id: Signal<i32>) -> impl IntoView {
match plays {
Ok(plays) => {
Either::Left(view! {
<p>{format!("My Plays: {}", plays)}</p>
<p>{format!("My Plays: {plays}")}</p>
})
},
Err(error) => {

View File

@ -32,11 +32,11 @@ impl AuthnBackend for AuthBackend {
async fn authenticate(&self, creds: Self::Credentials) -> Result<Option<Self::User>, Self::Error> {
crate::api::users::validate_user(creds).await
.map_err(|e| ServerFnErrorErr::ServerError(format!("Error validating user: {}", e)))
.map_err(|e| ServerFnErrorErr::ServerError(format!("Error validating user: {e}")))
}
async fn get_user(&self, user_id: &UserId<Self>) -> Result<Option<Self::User>, Self::Error> {
crate::api::users::find_user_by_id(*user_id).await
.map_err(|e| ServerFnErrorErr::ServerError(format!("Error getting user: {}", e)))
.map_err(|e| ServerFnErrorErr::ServerError(format!("Error getting user: {e}")))
}
}

View File

@ -53,7 +53,7 @@ pub async fn get_asset_file(filename: String, asset_type: AssetType) -> Result<R
// Create a Uri from the filename
// ServeDir expects a leading `/`
let uri = Uri::from_str(format!("/{}", filename).as_str());
let uri = Uri::from_str(format!("/{filename}").as_str());
match uri {
Ok(uri) => get_static_file(uri, root.as_str()).await,