mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-02 12:26:36 +08:00
Fix subscription restore and media library entry links
This commit is contained in:
@@ -39,6 +39,9 @@ export const subscriptionsAPI = {
|
||||
|
||||
remove: (id: string) => api.delete(`/subscriptions/${id}`).then((r) => r.data),
|
||||
|
||||
restore: (id: string) =>
|
||||
api.post<Subscription>(`/subscriptions/${id}/restore`).then((r) => r.data),
|
||||
|
||||
runNow: (id: string) =>
|
||||
api.post<{ queued: number }>(`/subscriptions/${id}/run`).then((r) => r.data),
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { playbackAPI, type HistoryItem } from '../api/playback'
|
||||
import { imageURL } from '../api/client'
|
||||
import { MediaCard } from '../components/MediaCard'
|
||||
import type { Library, Media } from '../types'
|
||||
import { groupSeries } from '../utils/groupSeries'
|
||||
import { groupSeries, seriesCardLink } from '../utils/groupSeries'
|
||||
|
||||
const hasArtwork = (media?: Media | null) => !!(media?.poster_url || media?.backdrop_url)
|
||||
const asArray = <T,>(value: unknown): T[] => (Array.isArray(value) ? value as T[] : [])
|
||||
@@ -220,7 +220,7 @@ export function HomePage() {
|
||||
key={card.key}
|
||||
media={card.rep}
|
||||
count={card.count}
|
||||
linkTo={card.count > 1 ? `/library/${card.rep.library_id}?series=${encodeURIComponent(card.key)}` : undefined}
|
||||
linkTo={card.count > 1 ? seriesCardLink(card) : undefined}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { FormEvent, useEffect, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { Archive, CalendarClock, CheckCircle2, Film, Pencil, Play, Plus, Save, ShieldCheck, Trash2 } from 'lucide-react'
|
||||
import { Archive, CalendarClock, CheckCircle2, Film, Pencil, Play, Plus, RotateCcw, Save, ShieldCheck, Trash2 } from 'lucide-react'
|
||||
|
||||
import { subscriptionsAPI } from '../api/subscriptions'
|
||||
import { imageURL } from '../api/client'
|
||||
@@ -117,6 +117,22 @@ export function SubscriptionsPage() {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}
|
||||
|
||||
const restoreHistorySubscription = async (subscription: Subscription, runAfterRestore = false) => {
|
||||
try {
|
||||
const restored = await subscriptionsAPI.restore(subscription.id)
|
||||
if (runAfterRestore) {
|
||||
const result = await subscriptionsAPI.runNow(restored.id)
|
||||
toast.success(`已恢复订阅并加入 ${result.queued} 项`)
|
||||
} else {
|
||||
toast.success('已恢复到正在订阅')
|
||||
}
|
||||
await refresh()
|
||||
} catch (err: unknown) {
|
||||
const msg = (err as { response?: { data?: { error?: string } } })?.response?.data?.error || '恢复订阅失败'
|
||||
toast.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="font-display text-3xl font-bold text-ink-600">RSS 订阅</h1>
|
||||
@@ -344,6 +360,22 @@ export function SubscriptionsPage() {
|
||||
{subscription.archived_at ? new Date(subscription.archived_at).toLocaleString() : '完成时间未知'}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-ink-50">{subscriptionProgressLabel(subscription)}</p>
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
<button
|
||||
className="rounded-xl border border-gray-300 bg-white px-3 py-1.5 text-xs font-semibold text-ink-100 hover:bg-gray-50"
|
||||
onClick={() => restoreHistorySubscription(subscription)}
|
||||
>
|
||||
<RotateCcw size={13} className="mr-1 inline" />
|
||||
恢复订阅
|
||||
</button>
|
||||
<button
|
||||
className="rounded-xl border border-primary-400/40 bg-white px-3 py-1.5 text-xs font-semibold text-brand-500 hover:bg-primary-400/10"
|
||||
onClick={() => restoreHistorySubscription(subscription, true)}
|
||||
>
|
||||
<Play size={13} className="mr-1 inline" />
|
||||
恢复并运行
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
@@ -106,6 +106,11 @@ export interface Library {
|
||||
export interface Media {
|
||||
id: string
|
||||
library_id: string
|
||||
library_name?: string
|
||||
library_path?: string
|
||||
display_library_id?: string
|
||||
display_library_name?: string
|
||||
display_library_path?: string
|
||||
series_id?: string
|
||||
title: string
|
||||
original_name?: string
|
||||
|
||||
@@ -16,7 +16,7 @@ import type { Media } from '../types'
|
||||
*
|
||||
* 同一组内取最早 created_at 的那条作为代表卡片,并带 count 表示集数。
|
||||
*/
|
||||
export type SeriesCard = { key: string; rep: Media; count: number }
|
||||
export type SeriesCard = { key: string; rep: Media; linkMedia: Media; count: number }
|
||||
|
||||
export function getSeriesKey(media: Media): string {
|
||||
if (media.series_id) return `series:${media.series_id}`
|
||||
@@ -74,9 +74,12 @@ export function groupSeries(items: Media[] = []): SeriesCard[] {
|
||||
|
||||
const g = groups.get(key)
|
||||
if (!g) {
|
||||
groups.set(key, { key, rep: m, count: 1 })
|
||||
groups.set(key, { key, rep: m, linkMedia: m, count: 1 })
|
||||
} else {
|
||||
g.count += 1
|
||||
if (betterSeriesLinkMedia(m, g.linkMedia)) {
|
||||
g.linkMedia = m
|
||||
}
|
||||
const currentArtwork = artworkScore(m)
|
||||
const representativeArtwork = artworkScore(g.rep)
|
||||
if (currentArtwork > representativeArtwork) {
|
||||
@@ -93,11 +96,36 @@ export function groupSeries(items: Media[] = []): SeriesCard[] {
|
||||
|
||||
export function seriesCardLink(card: SeriesCard): string {
|
||||
if (card.count > 1) {
|
||||
return `/library/${card.rep.library_id}?series=${encodeURIComponent(card.key)}`
|
||||
return `/library/${targetLibraryID(card.linkMedia)}`
|
||||
}
|
||||
return `/media/${card.rep.id}`
|
||||
}
|
||||
|
||||
function betterSeriesLinkMedia(candidate: Media, current: Media): boolean {
|
||||
const candidateScore = librarySpecificityScore(candidate)
|
||||
const currentScore = librarySpecificityScore(current)
|
||||
if (candidateScore !== currentScore) return candidateScore > currentScore
|
||||
return artworkScore(candidate) > artworkScore(current)
|
||||
}
|
||||
|
||||
function librarySpecificityScore(media: Media): number {
|
||||
const rawPath = (media.display_library_path || media.library_path || '').trim()
|
||||
if (!rawPath) return 0
|
||||
const normalized = rawPath.replace(/\\/g, '/').replace(/\/+$/, '')
|
||||
const lower = normalized.toLowerCase()
|
||||
if (lower.startsWith('cloud://')) {
|
||||
const rest = normalized.slice('cloud://'.length)
|
||||
const slash = rest.indexOf('/')
|
||||
if (slash < 0 || slash === rest.length - 1) return 0
|
||||
return 100 + rest.slice(slash + 1).split('/').filter(Boolean).length
|
||||
}
|
||||
return 200 + normalized.split('/').filter(Boolean).length
|
||||
}
|
||||
|
||||
function targetLibraryID(media: Media): string {
|
||||
return media.display_library_id || media.library_id
|
||||
}
|
||||
|
||||
export function artworkScore(media: Media): number {
|
||||
const poster = (media.poster_url ?? '').toLowerCase()
|
||||
const backdrop = (media.backdrop_url ?? '').toLowerCase()
|
||||
|
||||
Reference in New Issue
Block a user