fix: full pagination + non-silent errors in PollingSonarrRetriever
Licence Check / Licence compatibility and copyright header verification (push) Successful in 43s
CI / Security audit (push) Successful in 59s
CI / Tests & coverage (push) Failing after 1m11s
Licence Check / Licence compatibility and copyright header verification (pull_request) Failing after 4s
CI / Tests & coverage (pull_request) Failing after 1m33s
CI / Security audit (pull_request) Successful in 1m39s

This commit is contained in:
2026-05-20 20:40:48 +01:00
parent 1f10414498
commit e772001c3f
+59 -21
View File
@@ -37,17 +37,35 @@ class PollingSonarrRetriever extends ArrRetriever {
* @returns {Promise<Object>} Queue object with records array * @returns {Promise<Object>} Queue object with records array
*/ */
async getQueue() { async getQueue() {
try { const instanceName = this.name;
// Fetch with large page size to get all items (Sonarr has pagination) let page = 1;
const response = await axios.get(`${this.url}/api/v3/queue`, { let allRecords = [];
headers: { 'X-Api-Key': this.apiKey }, let responseData = null;
params: { includeSeries: true, includeEpisode: true, pageSize: 1000 }
}); do {
return response.data; try {
} catch (error) { const response = await axios.get(`${this.url}/api/v3/queue`, {
logToFile(`[PollingSonarrRetriever] ${this.id} queue error: ${error.message}`); headers: { 'X-Api-Key': this.apiKey },
return { records: [] }; params: { includeSeries: true, includeEpisode: true, page, pageSize: 1000 }
} });
responseData = response.data;
} catch (error) {
console.error(`Sonarr queue fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
throw error;
}
const records = responseData.records || (Array.isArray(responseData) ? responseData : []);
allRecords = allRecords.concat(records);
page++;
} while (
(responseData.records || (Array.isArray(responseData) ? responseData : [])).length === 1000 &&
page <= 50
);
return {
...responseData,
records: allRecords
};
} }
/** /**
@@ -71,8 +89,14 @@ class PollingSonarrRetriever extends ArrRetriever {
startDate startDate
} = options; } = options;
try { const instanceName = this.name;
let page = 1;
let allRecords = [];
let responseData = null;
do {
const params = { const params = {
page,
pageSize, pageSize,
includeSeries, includeSeries,
includeEpisode includeEpisode
@@ -82,15 +106,29 @@ class PollingSonarrRetriever extends ArrRetriever {
if (sortDir) params.sortDir = sortDir; if (sortDir) params.sortDir = sortDir;
if (startDate) params.startDate = startDate; if (startDate) params.startDate = startDate;
const response = await axios.get(`${this.url}/api/v3/history`, { try {
headers: { 'X-Api-Key': this.apiKey }, const response = await axios.get(`${this.url}/api/v3/history`, {
params headers: { 'X-Api-Key': this.apiKey },
}); params
return response.data; });
} catch (error) { responseData = response.data;
logToFile(`[PollingSonarrRetriever] ${this.id} history error: ${error.message}`); } catch (error) {
return { records: [] }; console.error(`Sonarr history fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
} throw error;
}
const records = responseData.records || (Array.isArray(responseData) ? responseData : []);
allRecords = allRecords.concat(records);
page++;
} while (
(responseData.records || (Array.isArray(responseData) ? responseData : [])).length === pageSize &&
page <= 50
);
return {
...responseData,
records: allRecords
};
} }
} }