Dont return HTTP errors when LastFM no-ops

This commit is contained in:
Antoine Gersant 2020-01-07 23:28:26 -08:00
parent d823dce7db
commit b83f16e6f5
2 changed files with 13 additions and 2 deletions

View file

@ -399,13 +399,17 @@ fn delete_playlist(db: State<'_, Arc<DB>>, auth: Auth, name: String) -> Result<(
#[put("/lastfm/now_playing/<path>")]
fn lastfm_now_playing(db: State<'_, Arc<DB>>, auth: Auth, path: VFSPathBuf) -> Result<()> {
lastfm::now_playing(db.deref().deref(), &auth.username, &path.into() as &PathBuf)?;
if user::is_lastfm_linked(db.deref().deref(), &auth.username) {
lastfm::now_playing(db.deref().deref(), &auth.username, &path.into() as &PathBuf)?;
}
Ok(())
}
#[post("/lastfm/scrobble/<path>")]
fn lastfm_scrobble(db: State<'_, Arc<DB>>, auth: Auth, path: VFSPathBuf) -> Result<()> {
lastfm::scrobble(db.deref().deref(), &auth.username, &path.into() as &PathBuf)?;
if user::is_lastfm_linked(db.deref().deref(), &auth.username) {
lastfm::scrobble(db.deref().deref(), &auth.username, &path.into() as &PathBuf)?;
}
Ok(())
}

View file

@ -112,6 +112,13 @@ where
}
}
pub fn is_lastfm_linked<T>(db: &T, username: &str) -> bool
where
T: ConnectionSource,
{
get_lastfm_session_key(db, username).is_ok()
}
pub fn lastfm_unlink<T>(db: &T, username: &str) -> Result<()>
where
T: ConnectionSource,