feat(organize/scan): transfer modes, seeding-safe relocation, inode dedup, incremental scanning

- Organizer: add move/copy/hardlink/symlink transfer modes (default move),
  per-request target_path/transfer_mode overrides, and honor organize.target_dir
  / organize.transfer_mode settings.
- keep_seeding (default on): escalate move->hardlink (cross-device->copy) so the
  qBittorrent source stays in place and continues seeding after organize.
- qBittorrent SetLocation + POST /downloads/relocate to migrate whole torrents
  while keeping them seeding.
- Scanner: FileID (device:inode) hardlink dedup to avoid duplicate recognition
  and double-counted storage; extract single-file ingest.
- Watcher: recursive watch + incremental per-file ingest/remove instead of full
  re-scan; periodic full library scan now gated behind scan.periodic_enabled
  (default off) to reduce disk wear.
- Telegram bot: handle callback_query in polling, declare allowed_updates in
  webhook, answer callbacks.
- Frontend: settings for transfer mode / keep_seeding / periodic scan; organize
  panel target dir + transfer mode overrides.
- Tests for transfer modes, organizer resolution, SetLocation, inode dedup,
  incremental ingest/remove.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
soldosluka857
2026-05-30 03:56:15 +00:00
committed by Shuke
parent 518e7aa685
commit b9b7b7052a
23 changed files with 1284 additions and 119 deletions
+14 -4
View File
@@ -3,15 +3,25 @@ import { api } from './client'
// toolsAPI groups admin-only endpoints that don't fit the other domain
// modules: organizing media files into the canonical naming layout, and
// dispatching a test notification through the configured channels.
// OrganizeOverrides are optional single-request overrides for an organize
// action. Empty fields fall back to the system settings.
export interface OrganizeOverrides {
target_path?: string
transfer_mode?: string
}
export const toolsAPI = {
organizeMedia: (mediaID: string) =>
organizeMedia: (mediaID: string, opts?: OrganizeOverrides) =>
api
.post<{ path: string }>(`/admin/media/${mediaID}/organize`)
.post<{ path: string }>(`/admin/media/${mediaID}/organize`, opts ?? {})
.then((r) => r.data),
organizeLibrary: (libraryID: string) =>
organizeLibrary: (libraryID: string, opts?: OrganizeOverrides) =>
api
.post<Record<string, unknown>>(`/admin/libraries/${libraryID}/organize`)
.post<Record<string, unknown>>(
`/admin/libraries/${libraryID}/organize`,
opts ?? {},
)
.then((r) => r.data),
notifyTest: (title: string, body: string) =>
+24
View File
@@ -158,6 +158,24 @@ const GROUPS: SettingGroup[] = [
hint: '留空则默认整理到各媒体库对应路径(见下方参考)',
placeholder: '/mnt/media/organized',
},
{
key: 'organize.transfer_mode',
label: '默认转移方式',
type: 'select',
hint: '移动会删除源文件;复制/硬链接/软链接保留源文件,PT 做种不中断。硬链接同盘零额外占用。',
options: [
{ value: 'move', label: '移动(删除源文件)' },
{ value: 'copy', label: '复制(保留源文件)' },
{ value: 'hardlink', label: '硬链接(保留源,做种不中断,不占双倍空间)' },
{ value: 'symlink', label: '软链接(符号链接,保留源)' },
],
},
{
key: 'organize.keep_seeding',
label: '保种(整理后继续做种上传)',
type: 'toggle',
hint: '开启后即使选择「移动」也会自动改用硬链接(跨盘退化为复制)保留源文件,确保 qBittorrent 转移后继续做种上传。',
},
{
key: 'organize.movie_format',
label: '电影命名格式',
@@ -195,6 +213,12 @@ const GROUPS: SettingGroup[] = [
type: 'text',
placeholder: 'zh-CN',
},
{
key: 'scan.periodic_enabled',
label: '周期性整库重扫',
type: 'toggle',
hint: '默认关闭。文件新增/变更由实时监听增量入库,无需定时全量重扫。开启会每 60 分钟重扫整库,频繁读盘会损伤硬盘,一般无需开启。',
},
],
},
{
+40 -3
View File
@@ -61,6 +61,17 @@ function OrganizePanel() {
const [smartClassify, setSmartClassify] = useState(false)
const [loadingSettings, setLoadingSettings] = useState(true)
// 单次整理覆盖项:留空则沿用设置页的默认整理目录与转移方式。
const [targetPath, setTargetPath] = useState('')
const [transferMode, setTransferMode] = useState('')
const overrides = () => {
const o: { target_path?: string; transfer_mode?: string } = {}
if (targetPath.trim()) o.target_path = targetPath.trim()
if (transferMode) o.transfer_mode = transferMode
return o
}
useEffect(() => {
libraryAPI.list().then(setLibraries).catch(() => undefined)
}, [])
@@ -87,7 +98,7 @@ function OrganizePanel() {
if (!libraryID) return
setRunning(true)
try {
await toolsAPI.organizeLibrary(libraryID)
await toolsAPI.organizeLibrary(libraryID, overrides())
toast.success('已触发媒体库整理')
} catch (err: unknown) {
const msg =
@@ -116,8 +127,8 @@ function OrganizePanel() {
const onOrganizeOne = async (m: Media) => {
setBusyID(m.id)
try {
const r = await toolsAPI.organizeMedia(m.id)
toast.success(`已移动到 ${r.path}`)
const r = await toolsAPI.organizeMedia(m.id, overrides())
toast.success(`已整理到 ${r.path}`)
} catch (err: unknown) {
const msg =
(err as { response?: { data?: { error?: string } } })?.response?.data?.error ??
@@ -151,6 +162,32 @@ function OrganizePanel() {
</div>
)}
<div className="grid gap-3 rounded-xl border border-gray-200 bg-gray-50 p-3 sm:grid-cols-2">
<label className="space-y-1">
<span className="text-xs text-ink-50">整理目标目录(可选,覆盖默认设置)</span>
<input
className="input-base w-full"
placeholder="留空则使用「整理目标目录」设置或媒体库路径"
value={targetPath}
onChange={(e) => setTargetPath(e.target.value)}
/>
</label>
<label className="space-y-1">
<span className="text-xs text-ink-50">转移方式(可选,覆盖默认设置)</span>
<select
className="input-base w-full"
value={transferMode}
onChange={(e) => setTransferMode(e.target.value)}
>
<option value="">使用默认设置</option>
<option value="move">移动(删除源文件)</option>
<option value="copy">复制(保留源文件)</option>
<option value="hardlink">硬链接(保留源,做种不中断)</option>
<option value="symlink">软链接(符号链接,保留源)</option>
</select>
</label>
</div>
<form onSubmit={onOrganizeLibrary} className="flex flex-wrap gap-2">
<select
required