mirror of
https://github.com/WonderAliceUwU/OmniArr.git
synced 2026-11-19 11:35:56 +00:00
feat: add movie deletion action
This commit is contained in:
1 parent
b06792cc24
commit
c70a8999cd
6 files changed
+142
-10
No files matched your search
@@ -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<MovieDeletePayload>(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/', ''));
|
||||
|
||||
@@ -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<void> {
|
||||
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<void> {
|
||||
if (!config.jellyfin.baseUrl || !config.jellyfin.apiKey || !config.jellyfin.userId) {
|
||||
throw new Error('Jellyfin is not configured.');
|
||||
|
||||
@@ -297,6 +297,10 @@ export interface SeasonDeletePayload {
|
||||
seasonNumber: number;
|
||||
}
|
||||
|
||||
export interface MovieDeletePayload {
|
||||
movieId: number;
|
||||
}
|
||||
|
||||
export interface HubSection {
|
||||
id: string;
|
||||
title: string;
|
||||
|
||||
+63
-7
@@ -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<HTMLButtonElement>,
|
||||
episodeId: string,
|
||||
@@ -2365,12 +2398,24 @@ function TitleDetailsModal(props: {
|
||||
<h2 className="title-details-title">{displayTitle}</h2>
|
||||
)}
|
||||
</div>
|
||||
{canPlay ? (
|
||||
<ActionButton className="title-mobile-summary-play" onClick={() => setPlayerTarget({ id: playId!, title: playLabel })} variant="play">
|
||||
<PlayGlyph />
|
||||
<span>Play</span>
|
||||
</ActionButton>
|
||||
) : null}
|
||||
<div className="title-mobile-summary-actions">
|
||||
{canPlay ? (
|
||||
<ActionButton className="title-mobile-summary-play" onClick={() => setPlayerTarget({ id: playId!, title: playLabel })} variant="play">
|
||||
<PlayGlyph />
|
||||
<span>Play</span>
|
||||
</ActionButton>
|
||||
) : null}
|
||||
{canDeleteMovieAction ? (
|
||||
<ActionButton
|
||||
aria-label="Delete movie files"
|
||||
className="title-mobile-summary-delete title-action-button-delete"
|
||||
disabled={movieDeleteBusy}
|
||||
onClick={() => void handleMovieDelete()}
|
||||
>
|
||||
<TrashGlyph />
|
||||
</ActionButton>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="title-details-summary-content">
|
||||
<p className="title-details-overview">
|
||||
{isOverviewExpanded ? displayOverview : truncatedOverview}
|
||||
@@ -2393,7 +2438,18 @@ function TitleDetailsModal(props: {
|
||||
<PlayGlyph />
|
||||
<span>Play</span>
|
||||
</ActionButton>
|
||||
) : canRequest && details?.mediaType !== 'series' ? (
|
||||
) : null}
|
||||
{canDeleteMovieAction ? (
|
||||
<ActionButton
|
||||
aria-label="Delete movie files"
|
||||
className="title-summary-header-delete title-action-button-delete"
|
||||
disabled={movieDeleteBusy}
|
||||
onClick={() => void handleMovieDelete()}
|
||||
>
|
||||
<TrashGlyph />
|
||||
</ActionButton>
|
||||
) : null}
|
||||
{!canPlay && canRequest && details?.mediaType !== 'series' ? (
|
||||
isMovieRequestActive ? (
|
||||
movieRequestStatus === 'downloading' ? (
|
||||
<div
|
||||
|
||||
@@ -10,6 +10,7 @@ import type {
|
||||
HubPageResponse,
|
||||
JellyfinLoginPayload,
|
||||
MediaCard,
|
||||
MovieDeletePayload,
|
||||
SearchResponse,
|
||||
ServiceOptionsResponse,
|
||||
SessionResponse,
|
||||
@@ -146,4 +147,9 @@ body: JSON.stringify({ tmdbId, user }),
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
deleteMovie: (payload: MovieDeletePayload) =>
|
||||
request<{ ok: boolean }>('/api/movies/delete', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
}
|
||||
+29
-3
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user