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++ queued++
seen = append(seen, guid) seen = append(seen, guid)
seenSet[guid] = struct{}{}
} }
// Remember the last 200 GUIDs so the seen set doesn't grow forever. // Remember the last 200 GUIDs so the seen set doesn't grow forever.
if len(seen) > 200 { if len(seen) > 200 {
+88
View File
@@ -1,12 +1,20 @@
package service package service
import ( import (
"net/http"
"net/http/httptest"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"github.com/glebarez/sqlite"
"go.uber.org/zap"
"gorm.io/gorm"
"github.com/ShukeBta/MediaStationGo/internal/model" "github.com/ShukeBta/MediaStationGo/internal/model"
"github.com/ShukeBta/MediaStationGo/internal/repository"
) )
func TestSelectSiteSearchCandidatesPrefersSeriesPack(t *testing.T) { 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) { func TestMatchesSubscriptionRulesUserExcludeWords(t *testing.T) {
sub := &model.Subscription{ExcludeWords: "10bit,dolby vision,杜比"} sub := &model.Subscription{ExcludeWords: "10bit,dolby vision,杜比"}
cases := []struct { cases := []struct {
+1 -1
View File
@@ -182,7 +182,7 @@ export default function App() {
/> />
<Route <Route
path="api-configs" path="api-configs"
element={<Navigate to="/admin" replace />} element={<Navigate to="/admin?tab=api" replace />}
/> />
<Route <Route
path="tasks" path="tasks"
+20 -16
View File
@@ -310,24 +310,28 @@ export function Layout() {
</Link> </Link>
{/* Quick Discover shortcut button */} {/* Quick Discover shortcut button */}
<Link {can('can_view_discover') && (
to="/discover" <Link
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" 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> <Sparkles size={14} className="text-brand-500" />
</Link> <span>发现新片</span>
</Link>
)}
{/* Notification alert bubble */} {/* Notification alert bubble */}
<Link {isAdmin && (
to="/notify-channels" <Link
title="通知配置" to="/notify-channels"
aria-label="打开通知配置" title="通知配置"
className="relative rounded-xl border border-gray-200 p-2.5 text-gray-500 hover:bg-gray-100 hover:text-gray-900 transition-all" 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" /> <Bell size={18} />
</Link> <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 */} {/* Horizontal divider lines */}
<span className="h-6 w-px bg-gray-200" /> <span className="h-6 w-px bg-gray-200" />
+1 -1
View File
@@ -324,7 +324,7 @@ export function AIAssistantPage() {
{!status?.enabled && ( {!status?.enabled && (
<p className="text-xs text-sand-500"> <p className="text-xs text-sand-500">
提示: 当前未配置外部 AI Provider,系统将使用本地规则引擎解析查询。 提示: 当前未配置外部 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 等服务以获得更好效果。 中接入 OpenAI / DeepSeek 等服务以获得更好效果。
</p> </p>
)} )}
+21 -2
View File
@@ -1,4 +1,5 @@
import { FormEvent, useEffect, useState } from 'react' import { FormEvent, useEffect, useState } from 'react'
import { useSearchParams } from 'react-router-dom'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { KeyRound, Pencil, Plus, ShieldCheck, Trash2, UserCheck, UserX, X } from 'lucide-react' 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 { confirmAction } from '../components/ConfirmDialog'
import { requestPassword } from '../components/PasswordDialog' 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() { 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 = [ const tabs = [
{ key: 'library' as const, label: '媒体库' }, { key: 'library' as const, label: '媒体库' },
{ key: 'users' as const, label: '用户' }, { key: 'users' as const, label: '用户' },
{ key: 'api' as const, label: '外部API' }, { 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 ( return (
<div className="space-y-6"> <div className="space-y-6">
<h1 className="font-display text-3xl font-bold text-ink-600">管理后台</h1> <h1 className="font-display text-3xl font-bold text-ink-600">管理后台</h1>
@@ -35,7 +54,7 @@ export function AdminPage() {
{tabs.map((k) => ( {tabs.map((k) => (
<button <button
key={k.key} key={k.key}
onClick={() => setTab(k.key)} onClick={() => selectTab(k.key)}
className={ className={
'border-b-2 px-4 py-2 text-sm transition ' + 'border-b-2 px-4 py-2 text-sm transition ' +
(tab === k.key (tab === k.key
+13 -5
View File
@@ -1,4 +1,5 @@
import { FormEvent, useEffect, useState } from 'react' import { FormEvent, useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { ArrowDown, ArrowUp, Download, Film, HardDrive, Rss, ShieldCheck, Trash2 } from 'lucide-react' import { ArrowDown, ArrowUp, Download, Film, HardDrive, Rss, ShieldCheck, Trash2 } from 'lucide-react'
@@ -280,11 +281,18 @@ export function DownloadsPage() {
</div> </div>
{torrents === null && ( {torrents === null && (
<div className="glass-panel text-sand-500"> <div className="glass-panel text-sand-500">
尚未连接到下载器 — 请到{' '} 尚未连接到下载器 —{' '}
<a href="/download-clients" className="text-brand-500 hover:underline"> {role === 'admin' ? (
下载器 <>
</a>{' '} 请到{' '}
页面添加并测试连接。 <Link to="/download-clients" className="text-brand-500 hover:underline">
下载器
</Link>{' '}
页面添加并测试连接。
</>
) : (
'请联系管理员添加并测试下载器连接。'
)}
</div> </div>
)} )}
{torrents && torrents.length === 0 && ( {torrents && torrents.length === 0 && (