refactor: make PALDRA match PDCA style exactly - remove redundant instanceConfig parameter and convert to pure singleton
All checks were successful
All checks were successful
- Remove instanceConfig parameter from all retriever methods (getTags, getQueue, getHistory) - Retriever instances now use this.url, this.apiKey, this.id instead of passed parameter - Convert ArrRetrieverRegistry from class with convenience functions to pure singleton object - Export singleton instance directly instead of class + convenience functions - Update poller.js and historyFetcher.js to call methods on singleton directly - All 261 tests pass with zero behavior changes
This commit is contained in:
@@ -44,25 +44,22 @@ class ArrRetriever {
|
||||
|
||||
/**
|
||||
* Get tags from this *arr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @returns {Promise<Array>} Array of tag objects
|
||||
*/
|
||||
async getTags(instanceConfig) {
|
||||
async getTags() {
|
||||
throw new Error('getTags() must be implemented by subclass');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queue from this *arr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @returns {Promise<Object>} Queue object with records array
|
||||
*/
|
||||
async getQueue(instanceConfig) {
|
||||
async getQueue() {
|
||||
throw new Error('getQueue() must be implemented by subclass');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get history from this *arr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @param {Object} options - Optional parameters for history fetch
|
||||
* @param {number} [options.pageSize] - Number of records to fetch
|
||||
* @param {string} [options.sortKey] - Field to sort by
|
||||
@@ -73,7 +70,7 @@ class ArrRetriever {
|
||||
* @param {string} [options.startDate] - ISO date string for filtering
|
||||
* @returns {Promise<Object>} History object with records array
|
||||
*/
|
||||
async getHistory(instanceConfig, options = {}) {
|
||||
async getHistory(options = {}) {
|
||||
throw new Error('getHistory() must be implemented by subclass');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,42 +18,39 @@ class PollingRadarrRetriever extends ArrRetriever {
|
||||
|
||||
/**
|
||||
* Get tags from Radarr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @returns {Promise<Array>} Array of tag objects
|
||||
*/
|
||||
async getTags(instanceConfig) {
|
||||
async getTags() {
|
||||
try {
|
||||
const response = await axios.get(`${instanceConfig.url}/api/v3/tag`, {
|
||||
headers: { 'X-Api-Key': instanceConfig.apiKey }
|
||||
const response = await axios.get(`${this.url}/api/v3/tag`, {
|
||||
headers: { 'X-Api-Key': this.apiKey }
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logToFile(`[PollingRadarrRetriever] ${instanceConfig.id} tags error: ${error.message}`);
|
||||
logToFile(`[PollingRadarrRetriever] ${this.id} tags error: ${error.message}`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queue from Radarr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @returns {Promise<Object>} Queue object with records array
|
||||
*/
|
||||
async getQueue(instanceConfig) {
|
||||
async getQueue() {
|
||||
try {
|
||||
const response = await axios.get(`${instanceConfig.url}/api/v3/queue`, {
|
||||
headers: { 'X-Api-Key': instanceConfig.apiKey },
|
||||
const response = await axios.get(`${this.url}/api/v3/queue`, {
|
||||
headers: { 'X-Api-Key': this.apiKey },
|
||||
params: { includeMovie: true }
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logToFile(`[PollingRadarrRetriever] ${instanceConfig.id} queue error: ${error.message}`);
|
||||
logToFile(`[PollingRadarrRetriever] ${this.id} queue error: ${error.message}`);
|
||||
return { records: [] };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get history from Radarr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @param {Object} options - Optional parameters for history fetch
|
||||
* @param {number} [options.pageSize=10] - Number of records to fetch
|
||||
* @param {string} [options.sortKey] - Field to sort by
|
||||
@@ -62,7 +59,7 @@ class PollingRadarrRetriever extends ArrRetriever {
|
||||
* @param {string} [options.startDate] - ISO date string for filtering
|
||||
* @returns {Promise<Object>} History object with records array
|
||||
*/
|
||||
async getHistory(instanceConfig, options = {}) {
|
||||
async getHistory(options = {}) {
|
||||
const {
|
||||
pageSize = 10,
|
||||
sortKey,
|
||||
@@ -81,13 +78,13 @@ class PollingRadarrRetriever extends ArrRetriever {
|
||||
if (sortDir) params.sortDir = sortDir;
|
||||
if (startDate) params.startDate = startDate;
|
||||
|
||||
const response = await axios.get(`${instanceConfig.url}/api/v3/history`, {
|
||||
headers: { 'X-Api-Key': instanceConfig.apiKey },
|
||||
const response = await axios.get(`${this.url}/api/v3/history`, {
|
||||
headers: { 'X-Api-Key': this.apiKey },
|
||||
params
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logToFile(`[PollingRadarrRetriever] ${instanceConfig.id} history error: ${error.message}`);
|
||||
logToFile(`[PollingRadarrRetriever] ${this.id} history error: ${error.message}`);
|
||||
return { records: [] };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,42 +18,39 @@ class PollingSonarrRetriever extends ArrRetriever {
|
||||
|
||||
/**
|
||||
* Get tags from Sonarr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @returns {Promise<Array>} Array of tag objects
|
||||
*/
|
||||
async getTags(instanceConfig) {
|
||||
async getTags() {
|
||||
try {
|
||||
const response = await axios.get(`${instanceConfig.url}/api/v3/tag`, {
|
||||
headers: { 'X-Api-Key': instanceConfig.apiKey }
|
||||
const response = await axios.get(`${this.url}/api/v3/tag`, {
|
||||
headers: { 'X-Api-Key': this.apiKey }
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logToFile(`[PollingSonarrRetriever] ${instanceConfig.id} tags error: ${error.message}`);
|
||||
logToFile(`[PollingSonarrRetriever] ${this.id} tags error: ${error.message}`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get queue from Sonarr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @returns {Promise<Object>} Queue object with records array
|
||||
*/
|
||||
async getQueue(instanceConfig) {
|
||||
async getQueue() {
|
||||
try {
|
||||
const response = await axios.get(`${instanceConfig.url}/api/v3/queue`, {
|
||||
headers: { 'X-Api-Key': instanceConfig.apiKey },
|
||||
const response = await axios.get(`${this.url}/api/v3/queue`, {
|
||||
headers: { 'X-Api-Key': this.apiKey },
|
||||
params: { includeSeries: true, includeEpisode: true }
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logToFile(`[PollingSonarrRetriever] ${instanceConfig.id} queue error: ${error.message}`);
|
||||
logToFile(`[PollingSonarrRetriever] ${this.id} queue error: ${error.message}`);
|
||||
return { records: [] };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get history from Sonarr instance
|
||||
* @param {Object} instanceConfig - Configuration for the instance
|
||||
* @param {Object} options - Optional parameters for history fetch
|
||||
* @param {number} [options.pageSize=10] - Number of records to fetch
|
||||
* @param {string} [options.sortKey] - Field to sort by
|
||||
@@ -63,7 +60,7 @@ class PollingSonarrRetriever extends ArrRetriever {
|
||||
* @param {string} [options.startDate] - ISO date string for filtering
|
||||
* @returns {Promise<Object>} History object with records array
|
||||
*/
|
||||
async getHistory(instanceConfig, options = {}) {
|
||||
async getHistory(options = {}) {
|
||||
const {
|
||||
pageSize = 10,
|
||||
sortKey,
|
||||
@@ -84,13 +81,13 @@ class PollingSonarrRetriever extends ArrRetriever {
|
||||
if (sortDir) params.sortDir = sortDir;
|
||||
if (startDate) params.startDate = startDate;
|
||||
|
||||
const response = await axios.get(`${instanceConfig.url}/api/v3/history`, {
|
||||
headers: { 'X-Api-Key': instanceConfig.apiKey },
|
||||
const response = await axios.get(`${this.url}/api/v3/history`, {
|
||||
headers: { 'X-Api-Key': this.apiKey },
|
||||
params
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logToFile(`[PollingSonarrRetriever] ${instanceConfig.id} history error: ${error.message}`);
|
||||
logToFile(`[PollingSonarrRetriever] ${this.id} history error: ${error.message}`);
|
||||
return { records: [] };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user