Auto handle sonarr and radarr API differences (#1548)

This commit is contained in:
Tagaishi
2023-11-03 21:07:37 +01:00
committed by GitHub
parent 388a856a42
commit 5eb4365a59
4 changed files with 7 additions and 22 deletions

View File

@@ -4,12 +4,6 @@
"description": "Displays a calendar with upcoming releases, from supported integrations.",
"settings": {
"title": "Settings for Calendar widget",
"useSonarrv4": {
"label": "Use Sonarr v4 API"
},
"useRadarrv5": {
"label": "Use Radarr v5 API"
},
"radarrReleaseType": {
"label": "Radarr release type",
"data":{

View File

@@ -18,6 +18,7 @@ export interface IMedia {
episodetitle?: string;
voteAverage?: string;
poster?: string;
altPoster?: string;
genres: string[];
seasonNumber?: number;
plexUrl?: string;
@@ -136,7 +137,6 @@ export function RadarrMediaDisplay(props: any) {
const { media }: { media: any } = props;
const { config } = useConfigContext();
const calendar = config?.widgets.find((w) => w.type === 'calendar');
const useRadarrv5 = calendar?.properties.useRadarrv5 ?? false;
// Find a poster CoverType
const poster = media.images.find((image: any) => image.coverType === 'poster');
@@ -147,7 +147,8 @@ export function RadarrMediaDisplay(props: any) {
title: media.title ?? media.originalTitle,
overview: media.overview ?? '',
genres: media.genres ?? [],
poster: useRadarrv5 ? poster.remoteUrl : poster.url,
poster: poster.url,
altPoster: poster.remoteUrl,
voteAverage: media.ratings.tmdb.value.toString(),
imdbId: media.imdbId,
type: 'movie',
@@ -160,7 +161,6 @@ export function SonarrMediaDisplay(props: any) {
const { media }: { media: any } = props;
const { config } = useConfigContext();
const calendar = config?.widgets.find((w) => w.type === 'calendar');
const useSonarrv4 = calendar?.properties.useSonarrv4 ?? false;
// Find a poster CoverType
const poster = media.series.images.find((image: any) => image.coverType === 'poster');
@@ -172,7 +172,8 @@ export function SonarrMediaDisplay(props: any) {
genres: media.series.genres ?? [],
overview: media.overview ?? media.series.overview ?? '',
title: media.series.title,
poster: useSonarrv4 ? poster.remoteUrl : poster.url,
poster: poster.url,
altPoster: poster.remoteUrl,
episodeNumber: media.episodeNumber,
seasonNumber: media.seasonNumber,
episodetitle: media.title,
@@ -191,7 +192,7 @@ export function MediaDisplay({ media }: { media: IMedia }) {
return (
<Group noWrap style={{ maxHeight: 250, maxWidth: 400 }} p={0} m={0} spacing="xs">
<Image src={media.poster} height={200} width={150} radius="md" fit="cover" />
<Image src={media.poster?? media.altPoster} height={200} width={150} radius="md" fit="cover" withPlaceholder/>
<Stack justify="space-around">
<Stack spacing="sm">
<Text lineClamp={2}>

View File

@@ -15,7 +15,6 @@ export const calendarRouter = createTRPCRouter({
month: z.number().min(1).max(12),
year: z.number().min(1900).max(2300),
options: z.object({
useSonarrv4: z.boolean().optional().default(false),
showUnmonitored: z.boolean().optional().default(false),
}),
})
@@ -35,7 +34,7 @@ export const calendarRouter = createTRPCRouter({
);
const integrationTypeEndpointMap = new Map<AppIntegrationType['type'], string>([
['sonarr', input.options.useSonarrv4 ? '/api/v3/calendar' : '/api/calendar'],
['sonarr', '/api/v3/calendar'],
['radarr', '/api/v3/calendar'],
['lidarr', '/api/v1/calendar'],
['readarr', '/api/v1/calendar'],

View File

@@ -26,14 +26,6 @@ const definition = defineWidget({
type: 'switch',
defaultValue: false,
},
useSonarrv4: {
type: 'switch',
defaultValue: false,
},
useRadarrv5: {
type: 'switch',
defaultValue: false,
},
radarrReleaseType: {
type: 'select',
defaultValue: 'inCinemas',
@@ -78,7 +70,6 @@ function CalendarTile({ widget }: CalendarTileProps) {
month: month.getMonth() + 1,
year: month.getFullYear(),
options: {
useSonarrv4: widget.properties.useSonarrv4,
showUnmonitored: widget.properties.showUnmonitored,
},
},