存至私人影库增加下载方式
This commit is contained in:
@@ -31,6 +31,13 @@ interface AcgSearchProps {
|
||||
}
|
||||
|
||||
type AcgSearchSource = 'acgrip' | 'mikan' | 'dmhy';
|
||||
type DownloadTool = 'aria2' | 'Transmission' | 'qBittorrent';
|
||||
|
||||
const downloadToolOptions: Array<{ value: DownloadTool; label: string }> = [
|
||||
{ value: 'aria2', label: 'aria2' },
|
||||
{ value: 'qBittorrent', label: 'qBittorrent' },
|
||||
{ value: 'Transmission', label: 'Transmission' },
|
||||
];
|
||||
|
||||
export default function AcgSearch({
|
||||
keyword,
|
||||
@@ -47,6 +54,7 @@ export default function AcgSearch({
|
||||
const [showNameDialog, setShowNameDialog] = useState(false);
|
||||
const [selectedItem, setSelectedItem] = useState<AcgSearchItem | null>(null);
|
||||
const [customName, setCustomName] = useState('');
|
||||
const [downloadTool, setDownloadTool] = useState<DownloadTool>('aria2');
|
||||
const [toast, setToast] = useState<ToastProps | null>(null);
|
||||
const loadMoreRef = useRef<HTMLDivElement>(null);
|
||||
const isLoadingMoreRef = useRef(false);
|
||||
@@ -204,6 +212,7 @@ export default function AcgSearch({
|
||||
body: JSON.stringify({
|
||||
url: selectedItem.torrentUrl,
|
||||
name: customName.trim(),
|
||||
tool: downloadTool,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -228,6 +237,7 @@ export default function AcgSearch({
|
||||
setDownloadingId(null);
|
||||
setSelectedItem(null);
|
||||
setCustomName('');
|
||||
setDownloadTool('aria2');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -365,12 +375,27 @@ export default function AcgSearch({
|
||||
className='w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-green-500'
|
||||
autoFocus
|
||||
/>
|
||||
<label className='mt-4 block text-sm font-medium text-gray-700 dark:text-gray-300'>
|
||||
下载方式
|
||||
</label>
|
||||
<select
|
||||
value={downloadTool}
|
||||
onChange={(e) => setDownloadTool(e.target.value as DownloadTool)}
|
||||
className='mt-1 w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-green-500'
|
||||
>
|
||||
{downloadToolOptions.map((option) => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className='mt-4 flex gap-2 justify-end'>
|
||||
<button
|
||||
onClick={() => {
|
||||
setShowNameDialog(false);
|
||||
setSelectedItem(null);
|
||||
setCustomName('');
|
||||
setDownloadTool('aria2');
|
||||
}}
|
||||
className='px-4 py-2 rounded-lg bg-gray-200 text-gray-700 hover:bg-gray-300 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600 transition-colors'
|
||||
>
|
||||
|
||||
@@ -6,13 +6,19 @@ import { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
import { AdminConfig } from '@/lib/admin.types';
|
||||
import { AnimeSubscription } from '@/types/anime-subscription';
|
||||
import { AnimeSubscription, AnimeSubscriptionDownloadTool } from '@/types/anime-subscription';
|
||||
|
||||
interface AnimeSubscriptionComponentProps {
|
||||
config: AdminConfig | null;
|
||||
refreshConfig: () => Promise<void>;
|
||||
}
|
||||
|
||||
const downloadToolOptions: Array<{ value: AnimeSubscriptionDownloadTool; label: string }> = [
|
||||
{ value: 'aria2', label: 'aria2' },
|
||||
{ value: 'qBittorrent', label: 'qBittorrent' },
|
||||
{ value: 'Transmission', label: 'Transmission' },
|
||||
];
|
||||
|
||||
// Switch 组件
|
||||
const Switch = ({ checked, onChange, disabled }: { checked: boolean; onChange: (checked: boolean) => void; disabled?: boolean }) => (
|
||||
<button
|
||||
@@ -141,6 +147,7 @@ export default function AnimeSubscriptionComponent({
|
||||
refreshConfig,
|
||||
}: AnimeSubscriptionComponentProps) {
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
const [downloadTool, setDownloadTool] = useState<AnimeSubscriptionDownloadTool>('aria2');
|
||||
const [subscriptions, setSubscriptions] = useState<AnimeSubscription[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showAddForm, setShowAddForm] = useState(false);
|
||||
@@ -181,6 +188,7 @@ export default function AnimeSubscriptionComponent({
|
||||
useEffect(() => {
|
||||
if (config?.AnimeSubscriptionConfig) {
|
||||
setEnabled(config.AnimeSubscriptionConfig.Enabled || false);
|
||||
setDownloadTool(config.AnimeSubscriptionConfig.DownloadTool || 'aria2');
|
||||
setSubscriptions(config.AnimeSubscriptionConfig.Subscriptions || []);
|
||||
}
|
||||
}, [config]);
|
||||
@@ -205,7 +213,7 @@ export default function AnimeSubscriptionComponent({
|
||||
const response = await fetch('/api/admin/anime-subscription/toggle', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ enabled: newEnabled }),
|
||||
body: JSON.stringify({ enabled: newEnabled, downloadTool }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -225,6 +233,35 @@ export default function AnimeSubscriptionComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadToolChange = async (newDownloadTool: AnimeSubscriptionDownloadTool) => {
|
||||
const previousDownloadTool = downloadTool;
|
||||
setDownloadTool(newDownloadTool);
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await fetch('/api/admin/anime-subscription/toggle', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ enabled, downloadTool: newDownloadTool }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('保存下载方式失败');
|
||||
}
|
||||
|
||||
await refreshConfig();
|
||||
} catch (error) {
|
||||
setDownloadTool(previousDownloadTool);
|
||||
showAlert({
|
||||
type: 'error',
|
||||
title: '保存失败',
|
||||
message: error instanceof Error ? error.message : '保存下载方式失败',
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 开始添加
|
||||
const handleAdd = () => {
|
||||
resetForm();
|
||||
@@ -408,12 +445,31 @@ export default function AnimeSubscriptionComponent({
|
||||
return (
|
||||
<div className='space-y-6'>
|
||||
{/* 顶部控制 */}
|
||||
<div className='flex items-center justify-between'>
|
||||
<div className='flex items-center gap-3'>
|
||||
<span className='text-sm font-medium text-gray-700 dark:text-gray-300'>
|
||||
启用追番功能
|
||||
</span>
|
||||
<Switch checked={enabled} onChange={handleToggleEnabled} disabled={loading} />
|
||||
<div className='flex flex-col gap-4 md:flex-row md:items-center md:justify-between'>
|
||||
<div className='flex flex-col gap-4 sm:flex-row sm:items-center sm:gap-6'>
|
||||
<div className='flex items-center gap-3'>
|
||||
<span className='text-sm font-medium text-gray-700 dark:text-gray-300'>
|
||||
启用追番功能
|
||||
</span>
|
||||
<Switch checked={enabled} onChange={handleToggleEnabled} disabled={loading} />
|
||||
</div>
|
||||
<div className='flex items-center gap-3'>
|
||||
<label className='text-sm font-medium text-gray-700 dark:text-gray-300'>
|
||||
下载方式
|
||||
</label>
|
||||
<select
|
||||
value={downloadTool}
|
||||
onChange={(e) => handleDownloadToolChange(e.target.value as AnimeSubscriptionDownloadTool)}
|
||||
disabled={loading}
|
||||
className='min-w-40 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-sm text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-green-500 disabled:opacity-50'
|
||||
>
|
||||
{downloadToolOptions.map((option) => (
|
||||
<option key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleAdd}
|
||||
|
||||
Reference in New Issue
Block a user