From fc4606585d35eadd446245e17e302be3ffdbf835 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Fri, 17 Apr 2026 16:14:30 +0000 Subject: [PATCH] fix(lastfm): Fix total results reporting for librefm --- src/backend/common/vendor/LastfmApiClient.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/backend/common/vendor/LastfmApiClient.ts b/src/backend/common/vendor/LastfmApiClient.ts index 463ff6c6..6b10f191 100644 --- a/src/backend/common/vendor/LastfmApiClient.ts +++ b/src/backend/common/vendor/LastfmApiClient.ts @@ -291,6 +291,7 @@ export default class LastfmApiClient extends AbstractApiClient implements Pagina '@attr': { total, totalPages, + perPage, page } } = {}, @@ -331,7 +332,21 @@ export default class LastfmApiClient extends AbstractApiClient implements Pagina } }, []); - return { data: plays, meta: { ...fetchOptions, total: parseInt(total, 10), more: fetchOptions.cursor < parseInt(totalPages, 10) } }; + let totalNum: number | undefined; + // libre.fm does not return total, only perPage and totalPages + if(total !== undefined) { + if(typeof total === 'string') { + totalNum = parseInt(total, 10); + } else { + totalNum = total; + } + } else if(perPage !== undefined && totalPages !== undefined) { + const pp = typeof perPage === 'string' ? parseInt(perPage, 10) : perPage; + const tp = typeof totalPages === 'string' ? parseInt(totalPages, 10): totalPages; + totalNum = pp * tp; + } + + return { data: plays, meta: { ...fetchOptions, total: totalNum, more: fetchOptions.cursor < parseInt(totalPages, 10) } }; } -- 2.51.2