fix(search): add offset parameter for proper pagination

- Add offset parameter to search_albums, search_tracks, search_artists
- Backend now properly passes offset to Qobuz API
- Fixes duplicate results when loading more search results
This commit is contained in:
vicrodh committed 2026-01-09 12:35:29 -06:00
1 parent 5669ae023a
commit 7a53d62341
6 files changed
+503 -11

No files matched your search

+40 -7
View File
@@ -157,13 +157,17 @@ impl QobuzClient {
// === Search endpoints ===
/// Search for albums
pub async fn search_albums(&self, query: &str, limit: u32) -> Result<SearchResultsPage<Album>> {
pub async fn search_albums(&self, query: &str, limit: u32, offset: u32) -> Result<SearchResultsPage<Album>> {
let url = endpoints::build_url(paths::ALBUM_SEARCH);
let response: Value = self
.http
.get(&url)
.header("X-App-Id", self.app_id().await?)
.query(&[("query", query), ("limit", &limit.to_string())])
.query(&[
("query", query),
("limit", &limit.to_string()),
("offset", &offset.to_string()),
])
.send()
.await?
.json()
@@ -177,13 +181,17 @@ impl QobuzClient {
}
/// Search for tracks
pub async fn search_tracks(&self, query: &str, limit: u32) -> Result<SearchResultsPage<Track>> {
pub async fn search_tracks(&self, query: &str, limit: u32, offset: u32) -> Result<SearchResultsPage<Track>> {
let url = endpoints::build_url(paths::TRACK_SEARCH);
let response: Value = self
.http
.get(&url)
.header("X-App-Id", self.app_id().await?)
.query(&[("query", query), ("limit", &limit.to_string())])
.query(&[
("query", query),
("limit", &limit.to_string()),
("offset", &offset.to_string()),
])
.send()
.await?
.json()
@@ -197,13 +205,17 @@ impl QobuzClient {
}
/// Search for artists
pub async fn search_artists(&self, query: &str, limit: u32) -> Result<SearchResultsPage<Artist>> {
pub async fn search_artists(&self, query: &str, limit: u32, offset: u32) -> Result<SearchResultsPage<Artist>> {
let url = endpoints::build_url(paths::ARTIST_SEARCH);
let response: Value = self
.http
.get(&url)
.header("X-App-Id", self.app_id().await?)
.query(&[("query", query), ("limit", &limit.to_string())])
.query(&[
("query", query),
("limit", &limit.to_string()),
("offset", &offset.to_string()),
])
.send()
.await?
.json()
@@ -251,12 +263,33 @@ impl QobuzClient {
}
/// Get artist by ID
pub async fn get_artist(&self, artist_id: u64, with_albums: bool) -> Result<Artist> {
pub async fn get_artist(
&self,
artist_id: u64,
with_albums: bool,
) -> Result<Artist> {
self.get_artist_with_pagination(artist_id, with_albums, None, None).await
}
/// Get artist by ID with album pagination
pub async fn get_artist_with_pagination(
&self,
artist_id: u64,
with_albums: bool,
limit: Option<u32>,
offset: Option<u32>,
) -> Result<Artist> {
let url = endpoints::build_url(paths::ARTIST_GET);
let mut query = vec![("artist_id", artist_id.to_string())];
if with_albums {
query.push(("extra", "albums".to_string()));
}
if let Some(l) = limit {
query.push(("limit", l.to_string()));
}
if let Some(o) = offset {
query.push(("offset", o.to_string()));
}
let response: Value = self
.http
+25
View File
@@ -136,6 +136,31 @@ pub struct Artist {
pub image: Option<ImageSet>,
#[serde(default)]
pub albums_count: Option<u32>,
/// Biography (available when fetching full artist details)
#[serde(default)]
pub biography: Option<ArtistBiography>,
/// Albums (available when fetching with extra=albums)
#[serde(default)]
pub albums: Option<ArtistAlbums>,
}
/// Artist biography content
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArtistBiography {
pub summary: Option<String>,
pub content: Option<String>,
pub source: Option<String>,
}
/// Artist albums container
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArtistAlbums {
pub items: Vec<Album>,
pub total: u32,
#[serde(default)]
pub offset: u32,
#[serde(default)]
pub limit: u32,
}
/// Playlist model
+20 -3
View File
@@ -9,11 +9,12 @@ use crate::AppState;
pub async fn search_albums(
query: String,
limit: Option<u32>,
offset: Option<u32>,
state: State<'_, AppState>,
) -> Result<SearchResultsPage<Album>, String> {
let client = state.client.lock().await;
client
.search_albums(&query, limit.unwrap_or(20))
.search_albums(&query, limit.unwrap_or(20), offset.unwrap_or(0))
.await
.map_err(|e| e.to_string())
}
@@ -22,11 +23,12 @@ pub async fn search_albums(
pub async fn search_tracks(
query: String,
limit: Option<u32>,
offset: Option<u32>,
state: State<'_, AppState>,
) -> Result<SearchResultsPage<Track>, String> {
let client = state.client.lock().await;
client
.search_tracks(&query, limit.unwrap_or(20))
.search_tracks(&query, limit.unwrap_or(20), offset.unwrap_or(0))
.await
.map_err(|e| e.to_string())
}
@@ -35,11 +37,12 @@ pub async fn search_tracks(
pub async fn search_artists(
query: String,
limit: Option<u32>,
offset: Option<u32>,
state: State<'_, AppState>,
) -> Result<SearchResultsPage<Artist>, String> {
let client = state.client.lock().await;
client
.search_artists(&query, limit.unwrap_or(20))
.search_artists(&query, limit.unwrap_or(20), offset.unwrap_or(0))
.await
.map_err(|e| e.to_string())
}
@@ -55,3 +58,17 @@ pub async fn get_track(track_id: u64, state: State<'_, AppState>) -> Result<Trac
let client = state.client.lock().await;
client.get_track(track_id).await.map_err(|e| e.to_string())
}
/// Get artist with albums
#[tauri::command]
pub async fn get_artist(
artist_id: u64,
state: State<'_, AppState>,
) -> Result<Artist, String> {
log::info!("Command: get_artist {}", artist_id);
let client = state.client.lock().await;
client
.get_artist(artist_id, true)
.await
.map_err(|e| e.to_string())
}
+1
View File
@@ -99,6 +99,7 @@ pub fn run() {
commands::search_artists,
commands::get_album,
commands::get_track,
commands::get_artist,
// Playback commands
commands::play_track,
commands::pause_playback,