diff --git a/server/index.ts b/server/index.ts index f185127..7dd9af3 100644 --- a/server/index.ts +++ b/server/index.ts @@ -10,6 +10,7 @@ import { type DiskSpaceStatus, type HubPageResponse, type JellyfinLoginPayload, + type MovieDeletePayload, type SeasonDeletePayload, type SeasonRequestPayload, type TitleDetailsRequest @@ -25,6 +26,7 @@ import { searchTitles, getTitleDetails, getTmdbLogos, + deleteMovieFiles, deleteSeasonFiles, getServiceOptions, loadJellyfinUsers, @@ -426,6 +428,14 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse): return; } + if (url.pathname === '/api/movies/delete' && method === 'POST') { + const config = await readConfig(session!.encryptionKey); + const body = await readJson(request); + await deleteMovieFiles(config, body); + sendJson(response, 200, { ok: true }); + return; + } + if (url.pathname.startsWith('/api/assets/jellyfin/') && method === 'GET') { const config = await readConfig(session!.encryptionKey); const itemId = decodeURIComponent(url.pathname.replace('/api/assets/jellyfin/', '')); diff --git a/server/lib/services.ts b/server/lib/services.ts index 6976f46..cad2371 100644 --- a/server/lib/services.ts +++ b/server/lib/services.ts @@ -13,6 +13,7 @@ import type { HubPageResponse, HubSection, MediaCard, + MovieDeletePayload, ProcessingItem, SeasonDeletePayload, SeasonRequestPayload, @@ -2740,6 +2741,35 @@ export async function deleteSeasonFiles(config: AppConfig, payload: SeasonDelete ); } +export async function deleteMovieFiles(config: AppConfig, payload: MovieDeletePayload): Promise { + if (!config.radarr.baseUrl || !config.radarr.apiKey) { + throw new Error('Radarr is not configured.'); + } + + if (!payload.movieId) { + throw new Error('Movie id is required.'); + } + + const baseUrl = config.radarr.baseUrl.endsWith('/') ? config.radarr.baseUrl : `${config.radarr.baseUrl}/`; + const movieUrl = new URL(`api/v3/movie/${encodeURIComponent(String(payload.movieId))}`, baseUrl); + movieUrl.searchParams.set('deleteFiles', 'true'); + movieUrl.searchParams.set('addImportExclusion', 'false'); + + const response = await fetch(movieUrl, { + method: 'DELETE', + headers: { + 'X-Api-Key': config.radarr.apiKey + } + }); + + if (!response.ok) { + const detail = (await response.text()).trim(); + throw new Error(detail + ? `Radarr ${response.status} ${response.statusText}: ${detail}` + : `Radarr ${response.status} ${response.statusText}`); + } +} + export async function setEpisodeWatchState(config: AppConfig, payload: EpisodeWatchStateRequest): Promise { if (!config.jellyfin.baseUrl || !config.jellyfin.apiKey || !config.jellyfin.userId) { throw new Error('Jellyfin is not configured.'); diff --git a/shared/contracts.ts b/shared/contracts.ts index 24d09b7..8d80ee2 100644 --- a/shared/contracts.ts +++ b/shared/contracts.ts @@ -297,6 +297,10 @@ export interface SeasonDeletePayload { seasonNumber: number; } +export interface MovieDeletePayload { + movieId: number; +} + export interface HubSection { id: string; title: string; diff --git a/src/App.tsx b/src/App.tsx index d9695ea..d92b0c0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1575,6 +1575,7 @@ function TitleDetailsModal(props: { const [seasonActionBusy, setSeasonActionBusy] = useState<'download' | 'delete' | null>(null) const [seasonMenuOpen, setSeasonMenuOpen] = useState(false) const [movieRequestPending, setMovieRequestPending] = useState(false) + const [movieDeleteBusy, setMovieDeleteBusy] = useState(false) const [playerTarget, setPlayerTarget] = useState<{ id: string; title: string } | null>(null) const [isOverviewExpanded, setIsOverviewExpanded] = useState(false) const [episodeScrollState, setEpisodeScrollState] = useState({ canScrollLeft: false, canScrollRight: false }) @@ -1889,6 +1890,7 @@ function TitleDetailsModal(props: { : details?.requestStatus || 'idle' const movieRequestProgress = details?.requestProgress || 0 const isMovieRequestActive = details?.mediaType === 'movie' && (movieRequestStatus === 'processing' || movieRequestStatus === 'downloading') + const canDeleteMovieAction = Boolean(details?.mediaType === 'movie' && details.radarrMovieId) const activeSeasonNumber = effectiveActiveSeasonMeta?.seasonNumber const activeSeasonDownloadStatus = effectiveActiveSeasonMeta?.downloadStatus || 'idle' const currentSeasonIndex = details?.seasons.findIndex((season) => season.id === seasonValue) ?? -1 @@ -2262,6 +2264,37 @@ function TitleDetailsModal(props: { } } + async function handleMovieDelete() { + if (!details?.radarrMovieId) { + return + } + + if (!window.confirm(`Delete ${displayTitle} from Radarr and remove its downloaded files?`)) { + return + } + + setMovieDeleteBusy(true) + setDetailsError('') + try { + await api.deleteMovie({ movieId: details.radarrMovieId }) + setDetails((current) => current && current.mediaType === 'movie' + ? { + ...current, + availableInJellyfin: false, + providerId: undefined, + playTargetId: undefined, + radarrMovieId: undefined, + requestStatus: 'idle', + requestProgress: undefined, + } + : current) + } catch (error) { + setDetailsError(error instanceof Error ? error.message : 'Failed to delete movie files.') + } finally { + setMovieDeleteBusy(false) + } + } + function handleEpisodeDownload( event: MouseEvent, episodeId: string, @@ -2365,12 +2398,24 @@ function TitleDetailsModal(props: {

{displayTitle}

)} - {canPlay ? ( - setPlayerTarget({ id: playId!, title: playLabel })} variant="play"> - - Play - - ) : null} +
+ {canPlay ? ( + setPlayerTarget({ id: playId!, title: playLabel })} variant="play"> + + Play + + ) : null} + {canDeleteMovieAction ? ( + void handleMovieDelete()} + > + + + ) : null} +

{isOverviewExpanded ? displayOverview : truncatedOverview} @@ -2393,7 +2438,18 @@ function TitleDetailsModal(props: { Play - ) : canRequest && details?.mediaType !== 'series' ? ( + ) : null} + {canDeleteMovieAction ? ( + void handleMovieDelete()} + > + + + ) : null} + {!canPlay && canRequest && details?.mediaType !== 'series' ? ( isMovieRequestActive ? ( movieRequestStatus === 'downloading' ? (

+ request<{ ok: boolean }>('/api/movies/delete', { + method: 'POST', + body: JSON.stringify(payload), + }), } diff --git a/src/index.css b/src/index.css index e9551c3..e0a503e 100644 --- a/src/index.css +++ b/src/index.css @@ -1915,6 +1915,23 @@ img { border-color: rgba(255, 255, 255, 0.12); } +.title-action-button-delete { + justify-content: center; + width: 2.5rem; + min-width: 0; + height: 2.75rem; + padding: 0; + color: #f3f6ff; + background: rgba(255, 255, 255, 0.08); + border: 1px solid rgba(255, 255, 255, 0.08); +} + +.title-action-button-delete:hover, +.title-action-button-delete:focus-visible { + background: rgba(255, 255, 255, 0.12); + border-color: rgba(255, 255, 255, 0.12); +} + .title-seasons-panel { display: grid; gap: 1.3rem; @@ -2099,7 +2116,9 @@ img { } .mobile-season-select, -.title-mobile-summary-play { +.title-mobile-summary-actions, +.title-mobile-summary-play, +.title-mobile-summary-delete { display: none; } @@ -4310,10 +4329,17 @@ img { text-align: center; } - .title-mobile-summary-play { + .title-mobile-summary-actions { + display: flex; + justify-content: center; + gap: 0.65rem; + margin-top: 0.1rem; + } + + .title-mobile-summary-play, + .title-mobile-summary-delete { display: inline-flex; justify-self: center; - margin-top: 0.1rem; } .title-summary-header-play,