Skip to content

Commit

Permalink
fix: Radarr & Sonarr requests fail due to wrong indexerId, fix: Inval…
Browse files Browse the repository at this point in the history
…id backdrop urls
  • Loading branch information
aleksilassila committed Aug 15, 2023
1 parent 4732cc1 commit 3cba296
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/lib/apis/radarr/radarrApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ export const fetchRadarrReleases = (movieId: number) =>
(r) => r.data || []
) || Promise.resolve([]);

export const downloadRadarrMovie = (guid: string) =>
export const downloadRadarrMovie = (guid: string, indexerId: number) =>
RadarrApi?.post('/api/v3/release', {
params: {},
body: {
indexerId: 2,
indexerId,
guid
}
}).then((res) => res.response.ok) || Promise.resolve(false);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/apis/sonarr/sonarrApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ export const cancelDownloadSonarrEpisode = async (downloadId: number) => {
return !!deleteResponse?.response.ok;
};

export const downloadSonarrEpisode = (guid: string) =>
export const downloadSonarrEpisode = (guid: string, indexerId: number) =>
SonarrApi?.post('/api/v3/release', {
params: {},
body: {
indexerId: 2,
indexerId,
guid
}
}).then((res) => res.response.ok) || Promise.resolve(false);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/components/Card/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type Card from './Card.svelte';
import { TMDB_BACKDROP_SMALL } from '$lib/constants';

export const fetchCardTmdbMovieProps = async (movie: TmdbMovie2): Promise<ComponentProps<Card>> => {
const backdropUri = getTmdbMovieBackdrop(movie.id || 0);
const backdropUri = await getTmdbMovieBackdrop(movie.id || 0);

const movieAny = movie as any;
const genres =
Expand All @@ -25,15 +25,15 @@ export const fetchCardTmdbMovieProps = async (movie: TmdbMovie2): Promise<Compon
title: movie.title || '',
genres,
runtimeMinutes: movie.runtime,
backdropUrl: TMDB_BACKDROP_SMALL + (await backdropUri) || '',
backdropUrl: backdropUri ? TMDB_BACKDROP_SMALL + backdropUri : '',
rating: movie.vote_average || 0
};
};

export const fetchCardTmdbSeriesProps = async (
series: TmdbSeries2
): Promise<ComponentProps<Card>> => {
const backdropUri = getTmdbSeriesBackdrop(series.id || 0);
const backdropUri = await getTmdbSeriesBackdrop(series.id || 0);

const seriesAny = series as any;
const genres =
Expand All @@ -48,7 +48,7 @@ export const fetchCardTmdbSeriesProps = async (
title: series.name || '',
genres,
runtimeMinutes: series.episode_run_time?.[0],
backdropUrl: TMDB_BACKDROP_SMALL + (await backdropUri) || '',
backdropUrl: backdropUri ? TMDB_BACKDROP_SMALL + backdropUri : '',
rating: series.vote_average || 0,
type: 'series'
};
Expand Down
12 changes: 6 additions & 6 deletions src/lib/components/Modal/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { writable } from 'svelte/store';
import TitlePageModal from '../TitlePageLayout/TitlePageModal.svelte';

type ModalItem = {
id: Symbol;
group: Symbol;
id: symbol;
group: symbol;
component: ConstructorOfATypedSvelteComponent;
props: Record<string, any>;
};
Expand All @@ -14,15 +14,15 @@ function createDynamicModalStack() {
top: undefined
});

function close(symbol: Symbol) {
function close(symbol: symbol) {
store.update((s) => {
s.stack = s.stack.filter((i) => i.id !== symbol);
s.top = s.stack[s.stack.length - 1];
return s;
});
}

function closeGroup(group: Symbol) {
function closeGroup(group: symbol) {
store.update((s) => {
s.stack = s.stack.filter((i) => i.group !== group);
s.top = s.stack[s.stack.length - 1];
Expand All @@ -33,7 +33,7 @@ function createDynamicModalStack() {
function create(
component: ConstructorOfATypedSvelteComponent,
props: Record<string, any>,
group: Symbol | undefined = undefined
group: symbol | undefined = undefined
) {
const id = Symbol();
const item = { id, component, props, group: group || id };
Expand All @@ -60,7 +60,7 @@ function createDynamicModalStack() {

export const modalStack = createDynamicModalStack();

let lastTitleModal: Symbol | undefined = undefined;
let lastTitleModal: symbol | undefined = undefined;
export function openTitleModal(tmdbId: number, type: TitleType) {
if (lastTitleModal) {
modalStack.close(lastTitleModal);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Navbar/TitleSearchModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { onMount } from 'svelte';
import type { TitleType } from '$lib/types';
export let modalId: Symbol;
export let modalId: symbol;
let inputValue = '';
let inputElement: HTMLInputElement;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/components/RequestModal/EpisodeSelectModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import ModalHeader from '../Modal/ModalHeader.svelte';
import RequestModal from './RequestModal.svelte';
export let modalId: Symbol;
export let groupId: Symbol;
export let modalId: symbol;
export let groupId: symbol;
export let sonarrId: number;
export let seasonNumber: number;
Expand All @@ -22,8 +22,8 @@
modalStack.create(
RequestModal,
{
episode,
sonarrId,
sonarrEpisodeId: episode.id,
// sonarrId,
groupId
},
groupId
Expand Down
16 changes: 10 additions & 6 deletions src/lib/components/RequestModal/RequestModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
const dispatch = createEventDispatcher();
export let modalId: Symbol;
export let groupId: Symbol | undefined = undefined;
export let modalId: symbol;
export let groupId: symbol | undefined = undefined;
export let title = 'Releases';
export let radarrId: number | undefined = undefined;
export let sonarrEpisodeId: number | undefined = undefined;
export let seasonPack: { sonarrId: number; seasonNumber: number } | undefined = undefined;
Expand Down Expand Up @@ -66,18 +67,18 @@
};
}
function handleDownload(guid: string) {
function handleDownload(guid: string, indexerId: number) {
downloadFetchingGuid = guid;
if (radarrId) {
downloadRadarrMovie(guid).then((ok) => {
downloadRadarrMovie(guid, indexerId).then((ok) => {
dispatch('download');
downloadFetchingGuid = undefined;
if (ok) {
downloadingGuid = guid;
}
});
} else {
downloadSonarrEpisode(guid).then((ok) => {
downloadSonarrEpisode(guid, indexerId).then((ok) => {
dispatch('download');
downloadFetchingGuid = undefined;
if (ok) {
Expand Down Expand Up @@ -130,7 +131,10 @@
<div class="text-zinc-400">{formatSize(release?.size || 0)}</div>
{#if release.guid !== downloadingGuid}
<IconButton
on:click={() => release.guid && handleDownload(release.guid)}
on:click={() =>
release.guid &&
release.indexerId &&
handleDownload(release.guid, release.indexerId)}
disabled={downloadFetchingGuid === release.guid}
>
<Plus size={20} />
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/RequestModal/SeriesRequestModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import EpisodeSelectModal from './EpisodeSelectModal.svelte';
import RequestModal from './RequestModal.svelte';
export let modalId: Symbol;
export let modalId: symbol;
export let sonarrId: number;
export let seasons: number;
export let heading = 'Seasons';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/TitlePageLayout/TitlePageModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let tmdbId: number;
export let type: TitleType;
export let modalId: Symbol;
export let modalId: symbol;
function handleCloseModal() {
modalStack.close(modalId);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/VideoPlayer/VideoPlayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { playerState } from './VideoPlayer';
import { modalStack } from '../Modal/Modal';
export let modalId: Symbol;
export let modalId: symbol;
let uiVisible = true;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/stores/library.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ async function getLibrary(): Promise<Library> {
type: 'movie' as const,
tmdbId: radarrMovie.tmdbId || 0,
tmdbRating: radarrMovie.ratings?.tmdb?.value || 0,
backdropUrl: TMDB_BACKDROP_SMALL + (backdropUri || ''),
posterUrl: TMDB_POSTER_SMALL + (posterUri || ''),
backdropUrl: backdropUri ? TMDB_BACKDROP_SMALL + backdropUri : '',
posterUrl: posterUri ? TMDB_POSTER_SMALL + posterUri : '',
download,
continueWatching,
isPlayed: jellyfinItem?.UserData?.Played || false,
Expand Down Expand Up @@ -177,8 +177,8 @@ async function getLibrary(): Promise<Library> {
type: 'series' as const,
tmdbId: tmdbId || 0,
tmdbRating: tmdbItem?.vote_average || 0,
backdropUrl: TMDB_BACKDROP_SMALL + (backdropUrl || ''),
posterUrl: TMDB_POSTER_SMALL + posterUri,
backdropUrl: backdropUrl ? TMDB_BACKDROP_SMALL + backdropUrl : '',
posterUrl: posterUri ? TMDB_POSTER_SMALL + posterUri : '',
download,
continueWatching,
isPlayed: jellyfinItem?.UserData?.Played || false,
Expand Down

0 comments on commit 3cba296

Please sign in to comment.