feat: 支持删除视频源 (#525)

This commit is contained in:
ᴀᴍᴛᴏᴀᴇʀ
2025-11-07 15:15:03 +08:00
committed by GitHub
parent 854d39cf88
commit a871db655f
8 changed files with 148 additions and 3 deletions

View File

@@ -217,6 +217,10 @@ class ApiClient {
return this.put<UpdateVideoSourceResponse>(`/video-sources/${type}/${id}`, request);
}
async removeVideoSource(type: string, id: number): Promise<ApiResponse<boolean>> {
return this.request<boolean>(`/video-sources/${type}/${id}`, 'DELETE');
}
async evaluateVideoSourceRules(type: string, id: number): Promise<ApiResponse<boolean>> {
return this.post<boolean>(`/video-sources/${type}/${id}/evaluate`, null);
}
@@ -270,6 +274,7 @@ const api = {
getVideoSourcesDetails: () => apiClient.getVideoSourcesDetails(),
updateVideoSource: (type: string, id: number, request: UpdateVideoSourceRequest) =>
apiClient.updateVideoSource(type, id, request),
removeVideoSource: (type: string, id: number) => apiClient.removeVideoSource(type, id),
evaluateVideoSourceRules: (type: string, id: number) =>
apiClient.evaluateVideoSourceRules(type, id),
getDefaultPath: (type: string, name: string) => apiClient.getDefaultPath(type, name),

View File

@@ -14,6 +14,7 @@
import ClockIcon from '@lucide/svelte/icons/clock';
import PlusIcon from '@lucide/svelte/icons/plus';
import InfoIcon from '@lucide/svelte/icons/info';
import TrashIcon2 from '@lucide/svelte/icons/trash-2';
import * as Tooltip from '$lib/components/ui/tooltip/index.js';
import { toast } from 'svelte-sonner';
import { setBreadcrumb } from '$lib/stores/breadcrumb';
@@ -45,6 +46,13 @@
let evaluateType = '';
let evaluating = false;
// 删除对话框状态
let showRemoveDialog = false;
let removeSource: VideoSourceDetail | null = null;
let removeType = '';
let removeIdx: number = 0;
let removing = false;
// 编辑表单数据
let editForm = {
path: '',
@@ -100,6 +108,13 @@
showEvaluateDialog = true;
}
function openRemoveDialog(type: string, source: VideoSourceDetail, idx: number) {
removeSource = source;
removeType = type;
removeIdx = idx;
showRemoveDialog = true;
}
// 保存编辑
async function saveEdit() {
if (!editingSource) return;
@@ -162,6 +177,33 @@
}
}
async function removeVideoSource() {
if (!removeSource) return;
removing = true;
try {
let response = await api.removeVideoSource(removeType, removeSource.id);
if (response && response.data) {
if (videoSourcesData) {
const sources = videoSourcesData[
removeType as keyof VideoSourcesDetailsResponse
] as VideoSourceDetail[];
sources.splice(removeIdx, 1);
videoSourcesData = { ...videoSourcesData };
}
showRemoveDialog = false;
toast.success('删除视频源成功');
} else {
toast.error('删除视频源失败');
}
} catch (error) {
toast.error('删除视频源失败', {
description: (error as ApiError).message
});
} finally {
removing = false;
}
}
function getSourcesForTab(tabValue: string): VideoSourceDetail[] {
if (!videoSourcesData) return [];
return videoSourcesData[tabValue as keyof VideoSourcesDetailsResponse] as VideoSourceDetail[];
@@ -342,6 +384,17 @@
>
<ListRestartIcon class="h-3 w-3" />
</Button>
{#if activeTab !== 'watch_later'}
<Button
size="sm"
variant="outline"
onclick={() => openRemoveDialog(key, source, index)}
class="h-8 w-8 p-0"
title="删除"
>
<TrashIcon2 class="h-3 w-3" />
</Button>
{/if}
</Table.Cell>
</Table.Row>
{/each}
@@ -471,6 +524,31 @@
</AlertDialog.Content>
</AlertDialog.Root>
<AlertDialog.Root bind:open={showRemoveDialog}>
<AlertDialog.Content>
<AlertDialog.Header>
<AlertDialog.Title>删除视频源</AlertDialog.Title>
<AlertDialog.Description>
确定要删除视频源 <strong>"{removeSource?.name}"</strong> 吗?<br />
删除后该视频源相关的所有条目将从数据库中移除(不影响磁盘文件),该操作<span
class="text-destructive font-medium">无法撤销</span
><br />
</AlertDialog.Description>
</AlertDialog.Header>
<AlertDialog.Footer>
<AlertDialog.Cancel
disabled={removing}
onclick={() => {
showRemoveDialog = false;
}}>取消</AlertDialog.Cancel
>
<AlertDialog.Action onclick={removeVideoSource} disabled={removing}>
{removing ? '删除中' : '删除'}
</AlertDialog.Action>
</AlertDialog.Footer>
</AlertDialog.Content>
</AlertDialog.Root>
<!-- 添加对话框 -->
<Dialog.Root bind:open={showAddDialog}>
<Dialog.Content>