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:
@@ -4,6 +4,9 @@
|
||||
"description": "Displays a calendar with upcoming releases, from supported integrations.",
|
||||
"settings": {
|
||||
"title": "Settings for Calendar widget",
|
||||
"useSonarrv4": {
|
||||
"label": "Use Sonarr v4 API"
|
||||
},
|
||||
"sundayStart": {
|
||||
"label": "Start the week on Sunday"
|
||||
},
|
||||
|
||||
@@ -152,6 +152,10 @@ export function RadarrMediaDisplay(props: any) {
|
||||
|
||||
export function SonarrMediaDisplay(props: any) {
|
||||
const { media }: { media: any } = props;
|
||||
const { config } = useConfigContext();
|
||||
const calendar = config?.widgets.find((w) => w.id === 'calendar');
|
||||
const useSonarrv4 = calendar?.properties.useSonarrv4 ?? false;
|
||||
|
||||
// Find a poster CoverType
|
||||
const poster = media.series.images.find((image: any) => image.coverType === 'poster');
|
||||
// Return a movie poster containting the title and the description
|
||||
@@ -162,7 +166,7 @@ export function SonarrMediaDisplay(props: any) {
|
||||
genres: media.series.genres ?? [],
|
||||
overview: media.overview ?? media.series.overview ?? '',
|
||||
title: media.series.title,
|
||||
poster: poster ? poster.url : undefined,
|
||||
poster: useSonarrv4 ? poster.remoteUrl : poster.url,
|
||||
episodeNumber: media.episodeNumber,
|
||||
seasonNumber: media.seasonNumber,
|
||||
episodetitle: media.title,
|
||||
|
||||
@@ -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'],
|
||||
]);
|
||||
|
||||
@@ -16,6 +16,10 @@ const definition = defineWidget({
|
||||
id: 'calendar',
|
||||
icon: IconCalendarTime,
|
||||
options: {
|
||||
useSonarrv4: {
|
||||
type: 'switch',
|
||||
defaultValue: false,
|
||||
},
|
||||
sundayStart: {
|
||||
type: 'switch',
|
||||
defaultValue: false,
|
||||
|
||||
Reference in New Issue
Block a user