fix(app): close feature association gaps

This commit is contained in:
ShukeBta
2026-06-07 12:55:27 +08:00
parent a3b4dbf1c1
commit d77e890f51
7 changed files with 145 additions and 25 deletions
+1
View File
@@ -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 {
+88
View File
@@ -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(`<?xml version="1.0"?>
<rss><channel>
<item>
<title>Some Show S01E01 1080p</title>
<guid>episode-1</guid>
<link>magnet:?xt=urn:btih:1111111111111111111111111111111111111111&amp;dn=Some+Show+S01E01</link>
</item>
<item>
<title>Some Show S01E01 1080p</title>
<guid>episode-1</guid>
<link>magnet:?xt=urn:btih:1111111111111111111111111111111111111111&amp;dn=Some+Show+S01E01</link>
</item>
</channel></rss>`))
}))
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 {
+1 -1
View File
@@ -182,7 +182,7 @@ export default function App() {
/>
<Route
path="api-configs"
element={<Navigate to="/admin" replace />}
element={<Navigate to="/admin?tab=api" replace />}
/>
<Route
path="tasks"
+20 -16
View File
@@ -310,24 +310,28 @@ export function Layout() {
</Link>
{/* Quick Discover shortcut button */}
<Link
to="/discover"
className="hidden md:flex items-center gap-2 rounded-xl border border-gray-200 px-4 py-2.5 text-xs font-bold text-gray-500 hover:bg-gray-50 hover:text-gray-900 transition-all"
>
<Sparkles size={14} className="text-brand-500" />
<span>发现新片</span>
</Link>
{can('can_view_discover') && (
<Link
to="/discover"
className="hidden md:flex items-center gap-2 rounded-xl border border-gray-200 px-4 py-2.5 text-xs font-bold text-gray-500 hover:bg-gray-50 hover:text-gray-900 transition-all"
>
<Sparkles size={14} className="text-brand-500" />
<span>发现新片</span>
</Link>
)}
{/* Notification alert bubble */}
<Link
to="/notify-channels"
title="通知配置"
aria-label="打开通知配置"
className="relative rounded-xl border border-gray-200 p-2.5 text-gray-500 hover:bg-gray-100 hover:text-gray-900 transition-all"
>
<Bell size={18} />
<span className="absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-brand-500 ring-2 ring-white animate-pulse" />
</Link>
{isAdmin && (
<Link
to="/notify-channels"
title="通知配置"
aria-label="打开通知配置"
className="relative rounded-xl border border-gray-200 p-2.5 text-gray-500 hover:bg-gray-100 hover:text-gray-900 transition-all"
>
<Bell size={18} />
<span className="absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-brand-500 ring-2 ring-white animate-pulse" />
</Link>
)}
{/* Horizontal divider lines */}
<span className="h-6 w-px bg-gray-200" />
+1 -1
View File
@@ -324,7 +324,7 @@ export function AIAssistantPage() {
{!status?.enabled && (
<p className="text-xs text-sand-500">
提示: 当前未配置外部 AI Provider,系统将使用本地规则引擎解析查询。
管理员可在 <Link to="/api-configs" className="text-brand-500">API 配置</Link>{' '}
管理员可在 <Link to="/admin?tab=api" className="text-brand-500">API 配置</Link>{' '}
中接入 OpenAI / DeepSeek 等服务以获得更好效果。
</p>
)}
+21 -2
View File
@@ -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<AdminTab>(() => 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 (
<div className="space-y-6">
<h1 className="font-display text-3xl font-bold text-ink-600">管理后台</h1>
@@ -35,7 +54,7 @@ export function AdminPage() {
{tabs.map((k) => (
<button
key={k.key}
onClick={() => setTab(k.key)}
onClick={() => selectTab(k.key)}
className={
'border-b-2 px-4 py-2 text-sm transition ' +
(tab === k.key
+13 -5
View File
@@ -1,4 +1,5 @@
import { FormEvent, useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import toast from 'react-hot-toast'
import { ArrowDown, ArrowUp, Download, Film, HardDrive, Rss, ShieldCheck, Trash2 } from 'lucide-react'
@@ -280,11 +281,18 @@ export function DownloadsPage() {
</div>
{torrents === null && (
<div className="glass-panel text-sand-500">
尚未连接到下载器 — 请到{' '}
<a href="/download-clients" className="text-brand-500 hover:underline">
下载器
</a>{' '}
页面添加并测试连接。
尚未连接到下载器 —{' '}
{role === 'admin' ? (
<>
请到{' '}
<Link to="/download-clients" className="text-brand-500 hover:underline">
下载器
</Link>{' '}
页面添加并测试连接。
</>
) : (
'请联系管理员添加并测试下载器连接。'
)}
</div>
)}
{torrents && torrents.length === 0 && (