fix(web): subscribe from a TMDB candidate by creating the entity first
The search page 订阅 button and the new-subscription wizard threw away the TMDB id and created a title-only subscription, which stays pending (metadata_pending) with no seasons, episode totals or coverage matrix until some release happens to be identified. Call /files/entity-from-candidate first and subscribe the entity; fall back to title tracking only if that fails. Picking a TMDB row in the wizard now creates the library entity even if the dialog is then cancelled (idempotent per TMDB id). Found in REAL-1b on the v0.2.2 test stack; needs an image rebuild to take effect. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
775344f597
commit
39f5897df6
2 files changed
+27
-9
No files matched your search
@@ -2,6 +2,7 @@ import type { TmdbCandidate } from "@umt/contracts";
|
||||
import { ArrowRight, Film, Plus } from "lucide-react";
|
||||
import { Link, useNavigate } from "react-router";
|
||||
import { toast } from "sonner";
|
||||
import { useEntityFromCandidate } from "~/api/files.ts";
|
||||
import { useSearch } from "~/api/search.ts";
|
||||
import { useCreateSubscription } from "~/api/subscriptions.ts";
|
||||
import { EmptyState, ErrorState, LoadingState } from "~/components/console/empty-state.tsx";
|
||||
@@ -22,17 +23,24 @@ function SectionTitle({ id, title, extra }: { id: string; title: string; extra?:
|
||||
);
|
||||
}
|
||||
|
||||
/** 从 TMDB 候选建订阅:按标题追踪(建档后自动关联作品) */
|
||||
/** 从 TMDB 候选建订阅:先按 TMDB id 建档(季/集与总集数随之就位)再订阅作品;建档失败退回按标题追踪 */
|
||||
export function useSubscribeTmdb() {
|
||||
const create = useCreateSubscription();
|
||||
const entity = useEntityFromCandidate();
|
||||
const navigate = useNavigate();
|
||||
return {
|
||||
pending: create.isPending,
|
||||
subscribe: (c: TmdbCandidate, onDone?: () => void) => {
|
||||
pending: create.isPending || entity.isPending,
|
||||
subscribe: async (c: TmdbCandidate, onDone?: () => void) => {
|
||||
const kind = c.entityType === "movie" ? "movie" : "series";
|
||||
const mediaEntityId =
|
||||
c.localEntityId ??
|
||||
(await entity
|
||||
.mutateAsync({ provider: "tmdb", externalId: c.externalId, kind: c.entityType === "movie" ? "movie" : "tv" })
|
||||
.then((r) => r.mediaEntityId)
|
||||
.catch(() => null));
|
||||
create.mutate(
|
||||
{
|
||||
titleQuery: c.year ? `${c.title} ${c.year}` : c.title,
|
||||
...(mediaEntityId ? { mediaEntityId } : { titleQuery: c.year ? `${c.title} ${c.year}` : c.title }),
|
||||
mediaKind: kind,
|
||||
mode: kind === "movie" ? "once" : "continuous",
|
||||
seasonScope: kind === "movie" ? "current_season" : "following_seasons",
|
||||
|
||||
Reference in new issue
Block a user