From 517d05f9cc79298faaef68dba02b287a8cf04df6 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Mon, 14 Sep 2026 21:28:59 +0800 Subject: [PATCH] style: format useSmartMatch.ts with prettier (#1899 #1900) --- .../hooks/step2-materials/useSmartMatch.ts | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/apps/web/src/pages/generate/hooks/step2-materials/useSmartMatch.ts b/apps/web/src/pages/generate/hooks/step2-materials/useSmartMatch.ts index 4f4af7f47..1d24e02ba 100755 --- a/apps/web/src/pages/generate/hooks/step2-materials/useSmartMatch.ts +++ b/apps/web/src/pages/generate/hooks/step2-materials/useSmartMatch.ts @@ -1,32 +1,32 @@ -import { useState, useCallback } from "react" -import { message } from "antd" -import type { AssetItem } from "@/api/assets" -import { smartMatchAssets, isAssetUsable } from "@/api/assets" +import { useState, useCallback } from "react"; +import { message } from "antd"; +import type { AssetItem } from "@/api/assets"; +import { smartMatchAssets, isAssetUsable } from "@/api/assets"; interface UseSmartMatchOptions { - libraryId: string - materials: { items: AssetItem[]; total: number } - onSmartSelectedIdsChange: (ids: string[]) => void + libraryId: string; + materials: { items: AssetItem[]; total: number }; + onSmartSelectedIdsChange: (ids: string[]) => void; /** 片段数量(#1899) */ - clipCount: number + clipCount: number; } /** 默认 limit(拿不到目标时长时的兜底上限) */ -const DEFAULT_LIMIT = 30 +const DEFAULT_LIMIT = 30; /** * 候选池放大倍数:批量 N 个变体独立选片、跨变体 20% 区间避让需要 * 足够大的素材池才能保证 N 条成片素材排布互不相同。 */ -const ASSET_POOL_MULTIPLIER = 3 +const ASSET_POOL_MULTIPLIER = 3; /** * 根据片段数量计算智能匹配候选素材数量上限(#1899)。 * 候选池 = clipCount × 倍数;结果钳制到 [1, 200] 区间。 */ export function computeLimitFromClipCount(clipCount: number): number { - if (clipCount <= 0) return DEFAULT_LIMIT - const limit = clipCount * ASSET_POOL_MULTIPLIER - return Math.max(1, Math.min(limit, 200)) + if (clipCount <= 0) return DEFAULT_LIMIT; + const limit = clipCount * ASSET_POOL_MULTIPLIER; + return Math.max(1, Math.min(limit, 200)); } /** @@ -38,58 +38,62 @@ export function useSmartMatch({ onSmartSelectedIdsChange, clipCount, }: UseSmartMatchOptions) { - const [smartMatching, setSmartMatching] = useState(false) - const [hasMatched, setHasMatched] = useState(false) + const [smartMatching, setSmartMatching] = useState(false); + const [hasMatched, setHasMatched] = useState(false); const handleSmartMatch = useCallback(async () => { if (!libraryId) { - message.warning("请先选择视频库") - return + message.warning("请先选择视频库"); + return; } - const usableItems = materials.items.filter(isAssetUsable) + const usableItems = materials.items.filter(isAssetUsable); if (usableItems.length === 0) { message.warning( - materials.items.length === 0 ? "当前视频库暂无素材" : "素材可能已用尽,请先上传新素材", - ) - return + materials.items.length === 0 + ? "当前视频库暂无素材" + : "素材可能已用尽,请先上传新素材", + ); + return; } - setSmartMatching(true) + setSmartMatching(true); try { - const limit = computeLimitFromClipCount(clipCount) + const limit = computeLimitFromClipCount(clipCount); - const result = await smartMatchAssets(libraryId, limit) - const matched = (result.items ?? []).filter((a) => !!a?.id && isAssetUsable(a)) - const matchedIds = matched.map((a: AssetItem) => a.id) + const result = await smartMatchAssets(libraryId, limit); + const matched = (result.items ?? []).filter( + (a) => !!a?.id && isAssetUsable(a), + ); + const matchedIds = matched.map((a: AssetItem) => a.id); if (matchedIds.length > 0) { - onSmartSelectedIdsChange(matchedIds) - setHasMatched(true) - message.success(`AI 已为你选择 ${matchedIds.length} 个素材`) + onSmartSelectedIdsChange(matchedIds); + setHasMatched(true); + message.success(`AI 已为你选择 ${matchedIds.length} 个素材`); } else { - onSmartSelectedIdsChange(usableItems.map((a) => a.id)) - setHasMatched(true) - message.info("AI 暂未找到匹配素材,已全选当前库素材") + onSmartSelectedIdsChange(usableItems.map((a) => a.id)); + setHasMatched(true); + message.info("AI 暂未找到匹配素材,已全选当前库素材"); } } catch { - onSmartSelectedIdsChange(usableItems.map((a) => a.id)) - setHasMatched(true) - message.info("已为你全选当前库素材(智能匹配功能即将上线)") + onSmartSelectedIdsChange(usableItems.map((a) => a.id)); + setHasMatched(true); + message.info("已为你全选当前库素材(智能匹配功能即将上线)"); } finally { - setSmartMatching(false) + setSmartMatching(false); } - }, [libraryId, materials.items, onSmartSelectedIdsChange, clipCount]) + }, [libraryId, materials.items, onSmartSelectedIdsChange, clipCount]); const handleRefreshMatch = useCallback(async () => { - await handleSmartMatch() - }, [handleSmartMatch]) + await handleSmartMatch(); + }, [handleSmartMatch]); return { smartMatching, hasMatched, handleSmartMatch, handleRefreshMatch, - } + }; }