mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
✨ Add sonarr-v4 compatibility (#689)
This commit is contained in:
@@ -35,6 +35,10 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const config = getConfig(configName);
|
||||
|
||||
// Find the calendar widget in the config
|
||||
const calendar = config.widgets.find((w) => w.id === 'calendar');
|
||||
const useSonarrv4 = calendar?.properties.useSonarrv4 ?? false;
|
||||
|
||||
const mediaAppIntegrationTypes: AppIntegrationType['type'][] = [
|
||||
'sonarr',
|
||||
'radarr',
|
||||
@@ -45,6 +49,13 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
(app) => app.integration && mediaAppIntegrationTypes.includes(app.integration.type)
|
||||
);
|
||||
|
||||
const IntegrationTypeEndpointMap = new Map<AppIntegrationType['type'], string>([
|
||||
['sonarr', useSonarrv4 ? '/api/v3/calendar' : '/api/calendar'],
|
||||
['radarr', '/api/v3/calendar'],
|
||||
['lidarr', '/api/v1/calendar'],
|
||||
['readarr', '/api/v1/calendar'],
|
||||
]);
|
||||
|
||||
try {
|
||||
const medias = await Promise.all(
|
||||
await mediaApps.map(async (app) => {
|
||||
@@ -71,7 +82,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!apiKey) return { type: integration.type, items: [], success: false };
|
||||
return axios
|
||||
.get(
|
||||
`${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}`
|
||||
`${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}&includeSeries=true&includeEpisodeFile=true&includeEpisodeImages=true`
|
||||
)
|
||||
.then((x) => ({ type: integration.type, items: x.data as any[], success: true }))
|
||||
.catch((err) => {
|
||||
@@ -87,7 +98,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
})
|
||||
);
|
||||
|
||||
const countFailed = medias.filter(x => !x.success).length;
|
||||
const countFailed = medias.filter((x) => !x.success).length;
|
||||
if (countFailed > 0) {
|
||||
Consola.warn(`A total of ${countFailed} apps for the calendar widget failed`);
|
||||
}
|
||||
@@ -111,10 +122,3 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const IntegrationTypeEndpointMap = new Map<AppIntegrationType['type'], string>([
|
||||
['sonarr', '/api/calendar'],
|
||||
['radarr', '/api/v3/calendar'],
|
||||
['lidarr', '/api/v1/calendar'],
|
||||
['readarr', '/api/v1/calendar'],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user