From 92701ed5586eb720144bda2330e82069bd71476b Mon Sep 17 00:00:00 2001 From: zyc <1439655764@qq.com> Date: Mon, 25 May 2026 16:26:03 +0800 Subject: [PATCH] fix(generation): exclude asset refs from image upload limit --- backend/apps/generation/views.py | 8 ++++++-- web/src/components/PromptInput.tsx | 7 ++++--- web/src/store/inputBar.ts | 13 ++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/apps/generation/views.py b/backend/apps/generation/views.py index bd320cb..ed9db0d 100644 --- a/backend/apps/generation/views.py +++ b/backend/apps/generation/views.py @@ -359,8 +359,12 @@ def video_generate_view(request): }, status=status.HTTP_429_TOO_MANY_REQUESTS) # 构建参考素材 - # 火山限制最多 9 张参考图片 - image_count = sum(1 for r in references if r.get('type', 'image') == 'image') + # 直接上传的参考图片最多 9 张;素材库 asset:// 引用不计入该上传槽位限制。 + image_count = sum( + 1 for r in references + if r.get('type', 'image') == 'image' + and not str(r.get('url', '')).startswith('asset://') + ) if image_count > 9: return Response({ 'error': 'too_many_references', diff --git a/web/src/components/PromptInput.tsx b/web/src/components/PromptInput.tsx index ecc0f21..7666071 100644 --- a/web/src/components/PromptInput.tsx +++ b/web/src/components/PromptInput.tsx @@ -416,14 +416,15 @@ export function PromptInput() { }, [extractText]); const insertAssetMention = useCallback((asset: AssetSearchResult) => { - // Instant check: count limit + // Instant check: count limit. Image assets from the library do not consume + // the 9 direct-upload image slots. const stats = editorRef.current ? parseAssetMentionsFromDOM(editorRef.current) : { counts: { image: 0, video: 0, audio: 0 }, durations: { video: 0, audio: 0 } }; const refs = useInputBarStore.getState().references; const refCounts = { image: 0, video: 0, audio: 0 }; refs.forEach((r) => refCounts[r.type]++); const typeKey = asset.asset_type === 'Video' ? 'video' : asset.asset_type === 'Audio' ? 'audio' : 'image'; - const maxMap = { image: 9, video: 3, audio: 3 }; - if (refCounts[typeKey] + stats.counts[typeKey] >= maxMap[typeKey]) { + const maxMap = { video: 3, audio: 3 }; + if (typeKey !== 'image' && refCounts[typeKey] + stats.counts[typeKey] >= maxMap[typeKey]) { const typeLabel = asset.asset_type === 'Video' ? '视频' : asset.asset_type === 'Audio' ? '音频' : '图片'; showToast(`${typeLabel}已达上限`); return; diff --git a/web/src/store/inputBar.ts b/web/src/store/inputBar.ts index 79fc093..796012c 100644 --- a/web/src/store/inputBar.ts +++ b/web/src/store/inputBar.ts @@ -261,13 +261,10 @@ export const useInputBarStore = create((set, get) => ({ prevReferences: [], addReferences: (files) => { const state = get(); - // Count existing references by type + merge @ asset mentions + // Count direct uploaded references by type. Asset library mentions do not + // consume direct upload slots. const counts = { image: 0, video: 0, audio: 0 }; for (const ref of state.references) counts[ref.type]++; - const { counts: assetCounts } = parseAssetMentions(state.editorHtml); - counts.image += assetCounts.image; - counts.video += assetCounts.video; - counts.audio += assetCounts.audio; // Separate images (sync) from audio/video (need async duration check) const imageFiles: File[] = []; @@ -559,8 +556,7 @@ async function _validateAndAddImages(files: File[]) { // Passed — add to store + upload fileCounter++; - const existingSameType = state.references.filter(r => r.type === 'image').length - + (state.assetMentions || []).filter((m: Record) => m.type === 'image').length; + const existingSameType = state.references.filter(r => r.type === 'image').length; const refId = `ref_${fileCounter}`; const newRef: UploadedFile = { id: refId, @@ -659,8 +655,7 @@ async function _validateAndAddMedia(files: File[]) { // Passed all checks — add to store fileCounter++; const labelPrefix = type === 'video' ? '视频' : '音频'; - const existingSameType = state.references.filter(r => r.type === type).length - + (state.assetMentions || []).filter((m: Record) => m.type === type).length; + const existingSameType = state.references.filter(r => r.type === type).length; const refId = `ref_${fileCounter}`; const newRef: UploadedFile = { id: refId,