From e851cea12aa6ba5da296447cb6f9e99ed2ebc80e Mon Sep 17 00:00:00 2001 From: saas-backend-agent Date: Wed, 2 Sep 2026 14:38:05 +0800 Subject: [PATCH] feat(assets): auto-create default video library when none exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When users first visit the asset library page and no video-type library exists, automatically call ensureDefaultLibrary to create one — mirroring the existing pattern in useVoiceMaterials. This fixes the production 404 issue where new projects had no video library, causing upload API calls to fail. --- apps/web/src/pages/assets/hooks/useAssetsData.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/web/src/pages/assets/hooks/useAssetsData.ts b/apps/web/src/pages/assets/hooks/useAssetsData.ts index 4ec192400..61074e30c 100644 --- a/apps/web/src/pages/assets/hooks/useAssetsData.ts +++ b/apps/web/src/pages/assets/hooks/useAssetsData.ts @@ -3,9 +3,11 @@ import { useQuery } from "@tanstack/react-query" import { getAssetLibraries, getAssets, + ensureDefaultLibrary, type AssetLibraryItem, type AssetItem as ApiAssetItem, } from "@/api/assets" +import { getOrCreateDefaultProject } from "@/api/projects" import { mapLibrary, mapAsset, type AssetItem, type LibraryItem } from "../types" /** @@ -16,7 +18,18 @@ export function useAssetsData() { /* ── 视频库列表查询 ── */ const { data: apiLibraries = [], isLoading: libLoading } = useQuery({ queryKey: ["asset-libraries"], - queryFn: getAssetLibraries, + queryFn: async () => { + const libs = await getAssetLibraries() + // 如果没有 video 类型的库,自动创建默认视频素材库(与 useVoiceMaterials 保持一致) + const hasVideoLib = libs.some((lib) => lib.kind === "video") + if (!hasVideoLib) { + const project = await getOrCreateDefaultProject() + await ensureDefaultLibrary({ project_id: project.id, kind: "video" }) + // 创建后重新拉取最新列表 + return getAssetLibraries() + } + return libs + }, staleTime: 60_000, }) -- 2.54.0