mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +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.",
|
"description": "Displays a calendar with upcoming releases, from supported integrations.",
|
||||||
"settings": {
|
"settings": {
|
||||||
"title": "Settings for Calendar widget",
|
"title": "Settings for Calendar widget",
|
||||||
|
"useSonarrv4": {
|
||||||
|
"label": "Use Sonarr v4 API"
|
||||||
|
},
|
||||||
"sundayStart": {
|
"sundayStart": {
|
||||||
"label": "Start the week on Sunday"
|
"label": "Start the week on Sunday"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -152,6 +152,10 @@ export function RadarrMediaDisplay(props: any) {
|
|||||||
|
|
||||||
export function SonarrMediaDisplay(props: any) {
|
export function SonarrMediaDisplay(props: any) {
|
||||||
const { media }: { media: any } = props;
|
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
|
// Find a poster CoverType
|
||||||
const poster = media.series.images.find((image: any) => image.coverType === 'poster');
|
const poster = media.series.images.find((image: any) => image.coverType === 'poster');
|
||||||
// Return a movie poster containting the title and the description
|
// Return a movie poster containting the title and the description
|
||||||
@@ -162,7 +166,7 @@ export function SonarrMediaDisplay(props: any) {
|
|||||||
genres: media.series.genres ?? [],
|
genres: media.series.genres ?? [],
|
||||||
overview: media.overview ?? media.series.overview ?? '',
|
overview: media.overview ?? media.series.overview ?? '',
|
||||||
title: media.series.title,
|
title: media.series.title,
|
||||||
poster: poster ? poster.url : undefined,
|
poster: useSonarrv4 ? poster.remoteUrl : poster.url,
|
||||||
episodeNumber: media.episodeNumber,
|
episodeNumber: media.episodeNumber,
|
||||||
seasonNumber: media.seasonNumber,
|
seasonNumber: media.seasonNumber,
|
||||||
episodetitle: media.title,
|
episodetitle: media.title,
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
const config = getConfig(configName);
|
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'][] = [
|
const mediaAppIntegrationTypes: AppIntegrationType['type'][] = [
|
||||||
'sonarr',
|
'sonarr',
|
||||||
'radarr',
|
'radarr',
|
||||||
@@ -45,6 +49,13 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
(app) => app.integration && mediaAppIntegrationTypes.includes(app.integration.type)
|
(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 {
|
try {
|
||||||
const medias = await Promise.all(
|
const medias = await Promise.all(
|
||||||
await mediaApps.map(async (app) => {
|
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 };
|
if (!apiKey) return { type: integration.type, items: [], success: false };
|
||||||
return axios
|
return axios
|
||||||
.get(
|
.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 }))
|
.then((x) => ({ type: integration.type, items: x.data as any[], success: true }))
|
||||||
.catch((err) => {
|
.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) {
|
if (countFailed > 0) {
|
||||||
Consola.warn(`A total of ${countFailed} apps for the calendar widget failed`);
|
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',
|
id: 'calendar',
|
||||||
icon: IconCalendarTime,
|
icon: IconCalendarTime,
|
||||||
options: {
|
options: {
|
||||||
|
useSonarrv4: {
|
||||||
|
type: 'switch',
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
sundayStart: {
|
sundayStart: {
|
||||||
type: 'switch',
|
type: 'switch',
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user