From 3cba296db1038b5e61a7968dc8257545869ab5aa Mon Sep 17 00:00:00 2001 From: Aleksi Lassila Date: Tue, 15 Aug 2023 15:12:17 +0300 Subject: [PATCH] fix: Radarr & Sonarr requests fail due to wrong indexerId, fix: Invalid backdrop urls --- src/lib/apis/radarr/radarrApi.ts | 4 ++-- src/lib/apis/sonarr/sonarrApi.ts | 4 ++-- src/lib/components/Card/card.ts | 8 ++++---- src/lib/components/Modal/Modal.ts | 12 ++++++------ .../components/Navbar/TitleSearchModal.svelte | 2 +- .../RequestModal/EpisodeSelectModal.svelte | 8 ++++---- .../components/RequestModal/RequestModal.svelte | 16 ++++++++++------ .../RequestModal/SeriesRequestModal.svelte | 2 +- .../TitlePageLayout/TitlePageModal.svelte | 2 +- .../components/VideoPlayer/VideoPlayer.svelte | 2 +- src/lib/stores/library.store.ts | 8 ++++---- 11 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/lib/apis/radarr/radarrApi.ts b/src/lib/apis/radarr/radarrApi.ts index 82f14069..33171e3a 100644 --- a/src/lib/apis/radarr/radarrApi.ts +++ b/src/lib/apis/radarr/radarrApi.ts @@ -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); diff --git a/src/lib/apis/sonarr/sonarrApi.ts b/src/lib/apis/sonarr/sonarrApi.ts index 5c6cb6e4..89b1a65a 100644 --- a/src/lib/apis/sonarr/sonarrApi.ts +++ b/src/lib/apis/sonarr/sonarrApi.ts @@ -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); diff --git a/src/lib/components/Card/card.ts b/src/lib/components/Card/card.ts index 6d8cdb5e..66146732 100644 --- a/src/lib/components/Card/card.ts +++ b/src/lib/components/Card/card.ts @@ -10,7 +10,7 @@ import type Card from './Card.svelte'; import { TMDB_BACKDROP_SMALL } from '$lib/constants'; export const fetchCardTmdbMovieProps = async (movie: TmdbMovie2): Promise> => { - const backdropUri = getTmdbMovieBackdrop(movie.id || 0); + const backdropUri = await getTmdbMovieBackdrop(movie.id || 0); const movieAny = movie as any; const genres = @@ -25,7 +25,7 @@ export const fetchCardTmdbMovieProps = async (movie: TmdbMovie2): Promise> => { - const backdropUri = getTmdbSeriesBackdrop(series.id || 0); + const backdropUri = await getTmdbSeriesBackdrop(series.id || 0); const seriesAny = series as any; const genres = @@ -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' }; diff --git a/src/lib/components/Modal/Modal.ts b/src/lib/components/Modal/Modal.ts index aa129669..49efd8eb 100644 --- a/src/lib/components/Modal/Modal.ts +++ b/src/lib/components/Modal/Modal.ts @@ -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; }; @@ -14,7 +14,7 @@ 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]; @@ -22,7 +22,7 @@ function createDynamicModalStack() { }); } - 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]; @@ -33,7 +33,7 @@ function createDynamicModalStack() { function create( component: ConstructorOfATypedSvelteComponent, props: Record, - group: Symbol | undefined = undefined + group: symbol | undefined = undefined ) { const id = Symbol(); const item = { id, component, props, group: group || id }; @@ -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); diff --git a/src/lib/components/Navbar/TitleSearchModal.svelte b/src/lib/components/Navbar/TitleSearchModal.svelte index 06b3188a..954eeb67 100644 --- a/src/lib/components/Navbar/TitleSearchModal.svelte +++ b/src/lib/components/Navbar/TitleSearchModal.svelte @@ -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; diff --git a/src/lib/components/RequestModal/EpisodeSelectModal.svelte b/src/lib/components/RequestModal/EpisodeSelectModal.svelte index 4b0dee14..38708439 100644 --- a/src/lib/components/RequestModal/EpisodeSelectModal.svelte +++ b/src/lib/components/RequestModal/EpisodeSelectModal.svelte @@ -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; @@ -22,8 +22,8 @@ modalStack.create( RequestModal, { - episode, - sonarrId, + sonarrEpisodeId: episode.id, + // sonarrId, groupId }, groupId diff --git a/src/lib/components/RequestModal/RequestModal.svelte b/src/lib/components/RequestModal/RequestModal.svelte index 5d4a0dac..92b271e7 100644 --- a/src/lib/components/RequestModal/RequestModal.svelte +++ b/src/lib/components/RequestModal/RequestModal.svelte @@ -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; @@ -66,10 +67,10 @@ }; } - 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) { @@ -77,7 +78,7 @@ } }); } else { - downloadSonarrEpisode(guid).then((ok) => { + downloadSonarrEpisode(guid, indexerId).then((ok) => { dispatch('download'); downloadFetchingGuid = undefined; if (ok) { @@ -130,7 +131,10 @@
{formatSize(release?.size || 0)}
{#if release.guid !== downloadingGuid} release.guid && handleDownload(release.guid)} + on:click={() => + release.guid && + release.indexerId && + handleDownload(release.guid, release.indexerId)} disabled={downloadFetchingGuid === release.guid} > diff --git a/src/lib/components/RequestModal/SeriesRequestModal.svelte b/src/lib/components/RequestModal/SeriesRequestModal.svelte index e768bdac..c80c6e65 100644 --- a/src/lib/components/RequestModal/SeriesRequestModal.svelte +++ b/src/lib/components/RequestModal/SeriesRequestModal.svelte @@ -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'; diff --git a/src/lib/components/TitlePageLayout/TitlePageModal.svelte b/src/lib/components/TitlePageLayout/TitlePageModal.svelte index b294fc5c..5fed4796 100644 --- a/src/lib/components/TitlePageLayout/TitlePageModal.svelte +++ b/src/lib/components/TitlePageLayout/TitlePageModal.svelte @@ -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); diff --git a/src/lib/components/VideoPlayer/VideoPlayer.svelte b/src/lib/components/VideoPlayer/VideoPlayer.svelte index 9892881b..a58b8096 100644 --- a/src/lib/components/VideoPlayer/VideoPlayer.svelte +++ b/src/lib/components/VideoPlayer/VideoPlayer.svelte @@ -16,7 +16,7 @@ import { playerState } from './VideoPlayer'; import { modalStack } from '../Modal/Modal'; - export let modalId: Symbol; + export let modalId: symbol; let uiVisible = true; diff --git a/src/lib/stores/library.store.ts b/src/lib/stores/library.store.ts index c65b481e..56579ab9 100644 --- a/src/lib/stores/library.store.ts +++ b/src/lib/stores/library.store.ts @@ -121,8 +121,8 @@ async function getLibrary(): Promise { 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, @@ -177,8 +177,8 @@ async function getLibrary(): Promise { 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,