Remove unused recycle bin and add optional local file delete (#26)

Soft-delete restore/purge/list and the recycle_purge job are gone.
Admin delete now removes library index rows, with an optional
delete_files query that also deletes local media + sidecar NFO.
UI copy is renamed from 移入回收站 to 删除, with a confirm checkbox.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
This commit is contained in:
truewhile
2026-09-03 14:12:52 +08:00
committed by GitHub
parent 205c71b0ad
commit a79bbb80a8
28 changed files with 362 additions and 338 deletions
+13
View File
@@ -225,6 +225,19 @@ export const mediaAPI = {
{ timeout: BATCH_REQUEST_TIMEOUT },
)
.then((r) => r.data),
delete: (id: string, options?: { deleteFiles?: boolean }) =>
api
.delete(`/media/${id}`, {
params: options?.deleteFiles ? { delete_files: true } : undefined,
})
.then((r) => r.data),
exportNFO: (id: string) =>
api.post<{ path: string }>(`/media/${id}/nfo`).then((r) => r.data),
exportLibraryNFO: (id: string) =>
api.post<{ written: number }>(`/libraries/${id}/nfo`).then((r) => r.data),
}
function episodeImageOption(options?: ScrapeOptions): boolean | undefined {
-15
View File
@@ -1,15 +0,0 @@
import { api } from './client'
export const recycleAPI = {
softDelete: (id: string) => api.delete(`/media/${id}`).then((r) => r.data),
restore: (id: string) => api.post(`/media/${id}/restore`).then((r) => r.data),
purge: (id: string) => api.delete(`/media/${id}/purge`).then((r) => r.data),
exportNFO: (id: string) =>
api.post<{ path: string }>(`/media/${id}/nfo`).then((r) => r.data),
exportLibraryNFO: (id: string) =>
api.post<{ written: number }>(`/libraries/${id}/nfo`).then((r) => r.data),
}
+26 -5
View File
@@ -1,3 +1,4 @@
import { useState } from 'react'
import { AlertTriangle } from 'lucide-react'
export type ConfirmOptions = {
@@ -6,6 +7,13 @@ export type ConfirmOptions = {
confirmText?: string
cancelText?: string
danger?: boolean
checkboxLabel?: string
checkboxDefaultChecked?: boolean
}
export type ConfirmResult = {
confirmed: boolean
checked: boolean
}
export function ConfirmDialog({
@@ -13,13 +21,15 @@ export function ConfirmDialog({
onClose,
}: {
options: ConfirmOptions
onClose: (value: boolean) => void
onClose: (value: ConfirmResult) => void
}) {
const danger = options.danger ?? true
const hasCheckbox = Boolean(options.checkboxLabel)
const [checked, setChecked] = useState(Boolean(options.checkboxDefaultChecked))
return (
<div
className="fixed inset-0 z-[100] flex items-center justify-center bg-black/35 p-4 backdrop-blur-sm"
onClick={() => onClose(false)}
onClick={() => onClose({ confirmed: false, checked })}
>
<div
role="dialog"
@@ -40,20 +50,31 @@ export function ConfirmDialog({
<h3 className="font-display text-lg font-bold text-ink-600">
{options.title || '确认操作'}
</h3>
<p className="mt-2 text-sm leading-6 text-ink-50">{options.message}</p>
<p className="mt-2 whitespace-pre-line text-sm leading-6 text-ink-50">{options.message}</p>
{hasCheckbox ? (
<label className="mt-4 flex cursor-pointer items-start gap-2.5 text-sm text-ink-100">
<input
type="checkbox"
className="mt-0.5 h-4 w-4 rounded border-gray-300 text-red-500 focus:ring-red-400"
checked={checked}
onChange={(event) => setChecked(event.target.checked)}
/>
<span>{options.checkboxLabel}</span>
</label>
) : null}
</div>
</div>
<div className="flex justify-end gap-2 border-t border-gray-100 bg-gray-50/80 px-5 py-4">
<button
type="button"
onClick={() => onClose(false)}
onClick={() => onClose({ confirmed: false, checked })}
className="rounded-xl border border-gray-200 bg-white px-4 py-2 text-sm font-semibold text-ink-100 hover:bg-gray-50"
>
{options.cancelText || '取消'}
</button>
<button
type="button"
onClick={() => onClose(true)}
onClick={() => onClose({ confirmed: true, checked })}
className={
'rounded-xl px-4 py-2 text-sm font-semibold text-white shadow-sm transition ' +
(danger ? 'bg-red-500 hover:bg-red-600' : 'bg-brand-500 hover:bg-brand-600')
+6 -2
View File
@@ -1,13 +1,17 @@
import { createRoot } from 'react-dom/client'
import { ConfirmDialog, type ConfirmOptions } from './ConfirmDialog'
import { ConfirmDialog, type ConfirmOptions, type ConfirmResult } from './ConfirmDialog'
export function confirmAction(options: ConfirmOptions): Promise<boolean> {
return confirmActionResult(options).then((result) => result.confirmed)
}
export function confirmActionResult(options: ConfirmOptions): Promise<ConfirmResult> {
return new Promise((resolve) => {
const host = document.createElement('div')
document.body.appendChild(host)
const root = createRoot(host)
const close = (value: boolean) => {
const close = (value: ConfirmResult) => {
root.unmount()
host.remove()
resolve(value)
+4 -4
View File
@@ -10,7 +10,7 @@ type LibraryMovieActionsProps = {
onManualScrape: (media: Media) => void
onProbe: (media: Media) => void
onNFO: (media: Media) => void
onSoftDelete: (media: Media) => void
onDelete: (media: Media) => void
}
export function LibraryMovieActions({
@@ -20,11 +20,11 @@ export function LibraryMovieActions({
onManualScrape,
onProbe,
onNFO,
onSoftDelete,
onDelete,
}: LibraryMovieActionsProps) {
const buttonClass = 'flex h-8 w-8 items-center justify-center rounded-lg border border-white/70 bg-white/90 text-gray-700 shadow-sm backdrop-blur transition hover:bg-brand-50 hover:text-brand-600 disabled:opacity-50'
// 远程 Emby 条目为只读视图:刮削/探测/NFO/回收站不适用。
// 远程 Emby 条目为只读视图:刮削/探测/NFO/删除不适用。
if (isRemoteEmbyID(media.id)) {
return null
}
@@ -43,7 +43,7 @@ export function LibraryMovieActions({
<button title="写出本地 NFO" disabled={busy} onClick={() => onNFO(media)} className={buttonClass}>
<FileText size={13} />
</button>
<button title="移入回收站" disabled={busy} onClick={() => onSoftDelete(media)} className={`${buttonClass} hover:!bg-red-50 hover:!text-red-500`}>
<button title="删除" disabled={busy} onClick={() => onDelete(media)} className={`${buttonClass} hover:!bg-red-50 hover:!text-red-500`}>
<Trash2 size={13} />
</button>
</>
+2 -2
View File
@@ -162,7 +162,7 @@ export function LibraryPage() {
handleSeriesProbe,
handleSeriesNFO,
handleSeriesOrganize,
handleSeriesSoftDelete,
handleSeriesDelete,
movieActions,
} = useLibraryAdminActions({
libraryID: id,
@@ -283,7 +283,7 @@ export function LibraryPage() {
onProbe={handleSeriesProbe}
onNFO={handleSeriesNFO}
onOrganize={handleSeriesOrganize}
onSoftDelete={handleSeriesSoftDelete}
onDelete={handleSeriesDelete}
onSeasonChange={setSelectedSeason}
/>
+4 -4
View File
@@ -26,7 +26,7 @@ type LibrarySeriesDetailHeaderProps = {
onProbe: () => void
onNFO: () => void
onOrganize: () => void
onSoftDelete: () => void
onDelete: () => void
}
export function LibrarySeriesDetailHeader({
@@ -47,7 +47,7 @@ export function LibrarySeriesDetailHeader({
onProbe,
onNFO,
onOrganize,
onSoftDelete,
onDelete,
}: LibrarySeriesDetailHeaderProps) {
const firstEpisode = firstPlayableEpisode(visibleEpisodes.length > 0 ? visibleEpisodes : allEpisodes)
@@ -131,9 +131,9 @@ export function LibrarySeriesDetailHeader({
<FolderInput size={13} />
<span>{seriesToolBusy === 'organize' ? '整理中…' : '整理当前合集'}</span>
</button>
<button onClick={onSoftDelete} disabled={!!seriesToolBusy} className="btn-outline px-3.5 py-2 text-xs gap-1.5 !border-red-100 !text-red-500 hover:!border-red-200 hover:!bg-red-50">
<button onClick={onDelete} disabled={!!seriesToolBusy} className="btn-outline px-3.5 py-2 text-xs gap-1.5 !border-red-100 !text-red-500 hover:!border-red-200 hover:!bg-red-50">
<Trash2 size={13} />
<span>{seriesToolBusy === 'delete' ? '处理中…' : '移入回收站'}</span>
<span>{seriesToolBusy === 'delete' ? '处理中…' : '删除'}</span>
</button>
</div>
</div>
+3 -3
View File
@@ -31,7 +31,7 @@ type LibrarySeriesDetailSectionProps = {
onProbe: () => void
onNFO: () => void
onOrganize: () => void
onSoftDelete: () => void
onDelete: () => void
onSeasonChange: (season: number) => void
}
@@ -56,7 +56,7 @@ export function LibrarySeriesDetailSection({
onProbe,
onNFO,
onOrganize,
onSoftDelete,
onDelete,
onSeasonChange,
}: LibrarySeriesDetailSectionProps) {
return (
@@ -86,7 +86,7 @@ export function LibrarySeriesDetailSection({
onProbe={onProbe}
onNFO={onNFO}
onOrganize={onOrganize}
onSoftDelete={onSoftDelete}
onDelete={onDelete}
/>
<LibrarySeriesEpisodesPanel
+4 -4
View File
@@ -14,7 +14,7 @@ type MediaDetailAdminPanelProps = {
onOrganize: () => void
onProbe: () => void
onExportNFO: () => void
onSoftDelete: () => void
onDelete: () => void
}
export function MediaDetailAdminPanel({
@@ -27,7 +27,7 @@ export function MediaDetailAdminPanel({
onOrganize,
onProbe,
onExportNFO,
onSoftDelete,
onDelete,
}: MediaDetailAdminPanelProps) {
if (isRemoteEmbyID(media.id)) {
return null
@@ -70,11 +70,11 @@ export function MediaDetailAdminPanel({
<span>写出本地 NFO 属性</span>
</button>
<button
onClick={onSoftDelete}
onClick={onDelete}
className="btn-outline py-2 px-3.5 text-xs gap-1.5 !border-red-100 !text-red-500 hover:!bg-red-50 hover:!border-red-200"
>
<Trash2 size={13} />
<span>移入回收站</span>
<span>删除</span>
</button>
</div>
</div>
+1 -1
View File
@@ -42,7 +42,7 @@ export function MediaDetailPage() {
onOrganize={() => detail.setOrganizeOpen(true)}
onProbe={detail.reprobe}
onExportNFO={detail.exportNFO}
onSoftDelete={detail.softDelete}
onDelete={detail.deleteMedia}
/>
{detail.hasEpisodes && (
+3 -3
View File
@@ -31,7 +31,7 @@ interface MediaDetailMainContentProps extends MediaDetailPlaybackActionsProps {
onOrganize: () => void
onProbe: () => void
onExportNFO: () => void
onSoftDelete: () => void
onDelete: () => void
}
interface MediaDetailDialogsProps {
@@ -147,7 +147,7 @@ export function MediaDetailMainContent({
onOrganize,
onProbe,
onExportNFO,
onSoftDelete,
onDelete,
}: MediaDetailMainContentProps) {
return (
<div className="relative z-10 p-6 sm:p-10 flex flex-col md:flex-row gap-8 lg:gap-12">
@@ -174,7 +174,7 @@ export function MediaDetailMainContent({
onOrganize={onOrganize}
onProbe={onProbe}
onExportNFO={onExportNFO}
onSoftDelete={onSoftDelete}
onDelete={onDelete}
/>
)}
</div>
+24 -20
View File
@@ -3,9 +3,9 @@ import toast from 'react-hot-toast'
import { api } from '../api/client'
import { libraryAPI } from '../api/library'
import { recycleAPI } from '../api/recycle'
import { mediaAPI } from '../api/library'
import { toolsAPI } from '../api/tools'
import { confirmAction } from '../components/confirmAction'
import { confirmAction, confirmActionResult } from '../components/confirmAction'
import type { Library, Media } from '../types'
import { seriesTitle, type SeriesCard } from '../utils/groupSeries'
import { LibraryMovieActions } from './LibraryMovieActions'
@@ -92,7 +92,7 @@ export function useLibraryAdminActions({
}
const handleSeriesNFO = () => {
runSeriesTool('nfo', '整剧 NFO 写出', (media) => recycleAPI.exportNFO(media.id))
runSeriesTool('nfo', '整剧 NFO 写出', (media) => mediaAPI.exportNFO(media.id))
}
const handleSeriesOrganize = async () => {
@@ -128,14 +128,16 @@ export function useLibraryAdminActions({
}
}
const handleSeriesSoftDelete = async () => {
const handleSeriesDelete = async () => {
if (!selectedSeries || selectedSeriesEpisodes.length === 0) return
if (!(await confirmAction({
title: '移入回收站',
message: `将「${seriesTitle(selectedSeries.rep)}」的 ${selectedSeriesEpisodes.length} 个媒体移至回收站? (磁盘文件保留)`,
confirmText: '移入回收站',
}))) return
await runSeriesTool('delete', '整剧移入回收站', (media) => recycleAPI.softDelete(media.id))
const result = await confirmActionResult({
title: '删除整剧',
message: `确定从媒体库删除「${seriesTitle(selectedSeries.rep)}」的 ${selectedSeriesEpisodes.length} 个媒体?\n默认仅移除索引记录,磁盘文件会保留。`,
confirmText: '删除',
checkboxLabel: '同时删除本地文件(含同名 NFO)',
})
if (!result.confirmed) return
await runSeriesTool('delete', '整剧删除', (media) => mediaAPI.delete(media.id, { deleteFiles: result.checked }))
clearSelectedSeries()
}
@@ -166,16 +168,18 @@ export function useLibraryAdminActions({
}
const handleMovieNFO = (media: Media) => {
runMovieTool(media, 'nfo', 'NFO 写出', (item) => recycleAPI.exportNFO(item.id))
runMovieTool(media, 'nfo', 'NFO 写出', (item) => mediaAPI.exportNFO(item.id))
}
const handleMovieSoftDelete = async (media: Media) => {
if (!(await confirmAction({
title: '移入回收站',
message: `将「${media.title}」移至回收站? (磁盘文件保留)`,
confirmText: '移入回收站',
}))) return
await runMovieTool(media, 'delete', '移入回收站', (item) => recycleAPI.softDelete(item.id))
const handleMovieDelete = async (media: Media) => {
const result = await confirmActionResult({
title: '删除媒体',
message: `确定从媒体库删除「${media.title}」?\n默认仅移除索引记录,磁盘文件会保留。`,
confirmText: '删除',
checkboxLabel: '同时删除本地文件(含同名 NFO)',
})
if (!result.confirmed) return
await runMovieTool(media, 'delete', '删除', (item) => mediaAPI.delete(item.id, { deleteFiles: result.checked }))
}
const movieActions = (media: Media): ReactNode => {
@@ -188,7 +192,7 @@ export function useLibraryAdminActions({
onManualScrape={setManualMovie}
onProbe={handleMovieProbe}
onNFO={handleMovieNFO}
onSoftDelete={handleMovieSoftDelete}
onDelete={handleMovieDelete}
/>
)
}
@@ -205,7 +209,7 @@ export function useLibraryAdminActions({
handleSeriesProbe,
handleSeriesNFO,
handleSeriesOrganize,
handleSeriesSoftDelete,
handleSeriesDelete,
movieActions,
}
}
+14 -14
View File
@@ -5,8 +5,7 @@ import toast from 'react-hot-toast'
import { api } from '../api/client'
import { mediaAPI } from '../api/library'
import { playbackAPI } from '../api/playback'
import { recycleAPI } from '../api/recycle'
import { confirmAction } from '../components/confirmAction'
import { confirmActionResult } from '../components/confirmAction'
import type { Media } from '../types'
import { mediaLibraryBackTarget } from './MediaDetailPageModel'
@@ -181,11 +180,11 @@ function useMediaDetailActions({
)
const reprobe = useCallback(() => reprobeMedia(media, refresh), [media, refresh])
const exportNFO = useCallback(() => exportMediaNFO(media), [media])
const softDelete = useCallback(
() => softDeleteMedia(media, navigate),
const deleteMedia = useCallback(
() => deleteMediaFromLibrary(media, navigate),
[media, navigate],
)
return { goBack, toggleFavourite, rescrape, reprobe, exportNFO, softDelete }
return { goBack, toggleFavourite, rescrape, reprobe, exportNFO, deleteMedia }
}
function goBackFromMediaDetail(media: Media | null, navigate: NavigateFunction, replace = false): void {
@@ -237,23 +236,24 @@ async function reprobeMedia(media: Media | null, refresh: () => Promise<void>):
async function exportMediaNFO(media: Media | null): Promise<void> {
if (!media) return
try {
const result = await recycleAPI.exportNFO(media.id)
const result = await mediaAPI.exportNFO(media.id)
toast.success(`NFO 已成功写入 ${result.path}`)
} catch (err: unknown) {
toast.error(apiErrorMessage(err, '导出失败'))
}
}
async function softDeleteMedia(media: Media | null, navigate: NavigateFunction): Promise<void> {
async function deleteMediaFromLibrary(media: Media | null, navigate: NavigateFunction): Promise<void> {
if (!media) return
const confirmed = await confirmAction({
title: '移入回收站',
message: `将「${media.title}」移至回收站? (磁盘文件保留)`,
confirmText: '移入回收站',
const result = await confirmActionResult({
title: '删除媒体',
message: `确定从媒体库删除「${media.title}」?\n默认仅移除索引记录,磁盘文件会保留。`,
confirmText: '删除',
checkboxLabel: '同时删除本地文件(含同名 NFO)',
})
if (!confirmed) return
await recycleAPI.softDelete(media.id)
toast.success('已移至回收站')
if (!result.confirmed) return
await mediaAPI.delete(media.id, { deleteFiles: result.checked })
toast.success(result.checked ? '已删除媒体及本地文件' : '已从媒体库删除')
goBackFromMediaDetail(media, navigate, true)
}