From d77e890f51c309f2bfb286dc1efd2201504d40a9 Mon Sep 17 00:00:00 2001 From: ShukeBta Date: Sun, 7 Jun 2026 12:55:27 +0800 Subject: [PATCH] fix(app): close feature association gaps --- internal/service/subscription.go | 1 + internal/service/subscription_test.go | 88 +++++++++++++++++++++++++++ web/src/App.tsx | 2 +- web/src/components/Layout.tsx | 36 ++++++----- web/src/pages/AIAssistantPage.tsx | 2 +- web/src/pages/AdminPage.tsx | 23 ++++++- web/src/pages/DownloadsPage.tsx | 18 ++++-- 7 files changed, 145 insertions(+), 25 deletions(-) diff --git a/internal/service/subscription.go b/internal/service/subscription.go index 058e983..f563a3e 100644 --- a/internal/service/subscription.go +++ b/internal/service/subscription.go @@ -265,6 +265,7 @@ func (s *SubscriptionService) runOne(ctx context.Context, sub *model.Subscriptio } queued++ seen = append(seen, guid) + seenSet[guid] = struct{}{} } // Remember the last 200 GUIDs so the seen set doesn't grow forever. if len(seen) > 200 { diff --git a/internal/service/subscription_test.go b/internal/service/subscription_test.go index a0856e5..b8b489f 100644 --- a/internal/service/subscription_test.go +++ b/internal/service/subscription_test.go @@ -1,12 +1,20 @@ package service import ( + "net/http" + "net/http/httptest" "os" "path/filepath" "strings" + "sync/atomic" "testing" + "github.com/glebarez/sqlite" + "go.uber.org/zap" + "gorm.io/gorm" + "github.com/ShukeBta/MediaStationGo/internal/model" + "github.com/ShukeBta/MediaStationGo/internal/repository" ) func TestSelectSiteSearchCandidatesPrefersSeriesPack(t *testing.T) { @@ -211,6 +219,86 @@ func TestSubscriptionPendingDownloadAvailabilitySkipsUnorganizedEpisodes(t *test } } +func TestSubscriptionRunOneDeduplicatesDuplicateRSSGUIDInSameFeed(t *testing.T) { + rss := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/rss+xml") + _, _ = w.Write([]byte(` + + + Some Show S01E01 1080p + episode-1 + magnet:?xt=urn:btih:1111111111111111111111111111111111111111&dn=Some+Show+S01E01 + + + Some Show S01E01 1080p + episode-1 + magnet:?xt=urn:btih:1111111111111111111111111111111111111111&dn=Some+Show+S01E01 + +`)) + })) + defer rss.Close() + + var addCalls int32 + qb := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/api/v2/auth/login": + _, _ = w.Write([]byte("Ok.")) + case "/api/v2/torrents/info": + if atomic.LoadInt32(&addCalls) > 0 { + _, _ = w.Write([]byte(`[{"hash":"abc123","name":"Some Show S01E01 1080p","state":"downloading","progress":0.1}]`)) + return + } + _, _ = w.Write([]byte(`[]`)) + case "/api/v2/torrents/add": + atomic.AddInt32(&addCalls, 1) + _, _ = w.Write([]byte("Ok.")) + default: + http.NotFound(w, r) + } + })) + defer qb.Close() + + db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{}) + if err != nil { + t.Fatal(err) + } + if err := db.AutoMigrate(&model.Subscription{}, &model.Setting{}, &model.DownloadTask{}, &model.Media{}); err != nil { + t.Fatal(err) + } + repos := repository.New(db) + downloads := NewDownloadService(zap.NewNop(), repos, NewHub(zap.NewNop()), nil) + downloads.qb.Configure(QBitConfig{BaseURL: qb.URL, Username: "admin", Password: "admin"}) + svc := NewSubscriptionService(nil, zap.NewNop(), repos, downloads, nil, NewHub(zap.NewNop())) + + sub := &model.Subscription{ + Name: "Some Show 自动订阅", + FeedURL: rss.URL, + Filter: "Some Show", + MediaType: "tv", + SavePath: "/downloads/tv", + } + if err := repos.Subscription.Create(t.Context(), sub); err != nil { + t.Fatal(err) + } + queued, err := svc.runOne(t.Context(), sub) + if err != nil { + t.Fatal(err) + } + if queued != 1 { + t.Fatalf("queued = %d, want 1", queued) + } + if got := atomic.LoadInt32(&addCalls); got != 1 { + t.Fatalf("qb add calls = %d, want 1", got) + } + rows, err := repos.Download.List(t.Context()) + if err != nil { + t.Fatal(err) + } + if len(rows) != 1 { + t.Fatalf("download rows = %d, want 1", len(rows)) + } +} + func TestMatchesSubscriptionRulesUserExcludeWords(t *testing.T) { sub := &model.Subscription{ExcludeWords: "10bit,dolby vision,杜比"} cases := []struct { diff --git a/web/src/App.tsx b/web/src/App.tsx index 63ea7ed..33aed60 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -182,7 +182,7 @@ export default function App() { /> } + element={} /> {/* Quick Discover shortcut button */} - - - 发现新片 - + {can('can_view_discover') && ( + + + 发现新片 + + )} {/* Notification alert bubble */} - - - - + {isAdmin && ( + + + + + )} {/* Horizontal divider lines */} diff --git a/web/src/pages/AIAssistantPage.tsx b/web/src/pages/AIAssistantPage.tsx index e3bb23e..d806e70 100644 --- a/web/src/pages/AIAssistantPage.tsx +++ b/web/src/pages/AIAssistantPage.tsx @@ -324,7 +324,7 @@ export function AIAssistantPage() { {!status?.enabled && (

提示: 当前未配置外部 AI Provider,系统将使用本地规则引擎解析查询。 - 管理员可在 API 配置{' '} + 管理员可在 API 配置{' '} 中接入 OpenAI / DeepSeek 等服务以获得更好效果。

)} diff --git a/web/src/pages/AdminPage.tsx b/web/src/pages/AdminPage.tsx index e6c1c04..a784a0f 100644 --- a/web/src/pages/AdminPage.tsx +++ b/web/src/pages/AdminPage.tsx @@ -1,4 +1,5 @@ import { FormEvent, useEffect, useState } from 'react' +import { useSearchParams } from 'react-router-dom' import toast from 'react-hot-toast' import { KeyRound, Pencil, Plus, ShieldCheck, Trash2, UserCheck, UserX, X } from 'lucide-react' @@ -11,13 +12,31 @@ import { ManagementShortcuts } from '../components/ManagementShortcuts' import { confirmAction } from '../components/ConfirmDialog' import { requestPassword } from '../components/PasswordDialog' +type AdminTab = 'library' | 'users' | 'api' + +function parseAdminTab(value: string | null): AdminTab { + if (value === 'users' || value === 'api') return value + return 'library' +} + export function AdminPage() { - const [tab, setTab] = useState<'library' | 'users' | 'api'>('library') + const [searchParams, setSearchParams] = useSearchParams() + const [tab, setTab] = useState(() => parseAdminTab(searchParams.get('tab'))) const tabs = [ { key: 'library' as const, label: '媒体库' }, { key: 'users' as const, label: '用户' }, { key: 'api' as const, label: '外部API' }, ] + + useEffect(() => { + setTab(parseAdminTab(searchParams.get('tab'))) + }, [searchParams]) + + const selectTab = (next: AdminTab) => { + setTab(next) + setSearchParams(next === 'library' ? {} : { tab: next }) + } + return (

管理后台

@@ -35,7 +54,7 @@ export function AdminPage() { {tabs.map((k) => (
{torrents === null && (
- 尚未连接到下载器 — 请到{' '} - - 下载器 - {' '} - 页面添加并测试连接。 + 尚未连接到下载器 —{' '} + {role === 'admin' ? ( + <> + 请到{' '} + + 下载器 + {' '} + 页面添加并测试连接。 + + ) : ( + '请联系管理员添加并测试下载器连接。' + )}
)} {torrents && torrents.length === 0 && (