From 9a264d16d90b7388aa59438ee9fed350a7f6a1b6 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Wed, 27 May 2026 17:00:24 +0900 Subject: [PATCH] feat: wire bulk asset export to asset_bulk_export_enabled flag Replace the isCloud gate on the server-side ZIP bulk-export path in useMediaAssetActions.downloadAssets with the asset_bulk_export_enabled capability flag, so the branch reflects backend capability instead of environment. The flag getter defaults to isCloud, so behavior is unchanged before the backend advertises it (Cloud has the export endpoint today, OSS does not); the served value wins once BE-997 registers the flag. --- src/composables/useFeatureFlags.test.ts | 37 ++++++++ src/composables/useFeatureFlags.ts | 17 +++- .../composables/useMediaAssetActions.test.ts | 84 +++++++++++++++++-- .../composables/useMediaAssetActions.ts | 16 ++-- src/platform/remoteConfig/types.ts | 1 + 5 files changed, 142 insertions(+), 13 deletions(-) diff --git a/src/composables/useFeatureFlags.test.ts b/src/composables/useFeatureFlags.test.ts index 0b242d4b790..f45b93de1c5 100644 --- a/src/composables/useFeatureFlags.test.ts +++ b/src/composables/useFeatureFlags.test.ts @@ -176,6 +176,43 @@ describe('useFeatureFlags', () => { }) }) + describe('assetBulkExportEnabled', () => { + afterEach(() => { + vi.mocked(distributionTypes).isCloud = false + localStorage.clear() + }) + + it('defaults to isCloud when the backend does not advertise the flag', () => { + vi.mocked(api.getServerFeature).mockImplementation( + (_path, defaultValue) => defaultValue + ) + + vi.mocked(distributionTypes).isCloud = true + expect(useFeatureFlags().flags.assetBulkExportEnabled).toBe(true) + + vi.mocked(distributionTypes).isCloud = false + expect(useFeatureFlags().flags.assetBulkExportEnabled).toBe(false) + }) + + it('lets the served flag value override the isCloud default', () => { + vi.mocked(distributionTypes).isCloud = true + vi.mocked(api.getServerFeature).mockImplementation((path) => { + if (path === ServerFeatureFlag.ASSET_BULK_EXPORT_ENABLED) return false + return undefined + }) + + expect(useFeatureFlags().flags.assetBulkExportEnabled).toBe(false) + }) + + it('prefers a localStorage dev override over the served value', () => { + vi.mocked(distributionTypes).isCloud = false + vi.mocked(api.getServerFeature).mockReturnValue(false) + localStorage.setItem('ff:asset_bulk_export_enabled', 'true') + + expect(useFeatureFlags().flags.assetBulkExportEnabled).toBe(true) + }) + }) + describe('dev override via localStorage', () => { afterEach(() => { localStorage.clear() diff --git a/src/composables/useFeatureFlags.ts b/src/composables/useFeatureFlags.ts index 1cf199632a4..b005fd8aa5f 100644 --- a/src/composables/useFeatureFlags.ts +++ b/src/composables/useFeatureFlags.ts @@ -27,7 +27,8 @@ export enum ServerFeatureFlag { WORKFLOW_SHARING_ENABLED = 'workflow_sharing_enabled', COMFYHUB_UPLOAD_ENABLED = 'comfyhub_upload_enabled', COMFYHUB_PROFILE_GATE_ENABLED = 'comfyhub_profile_gate_enabled', - SHOW_SIGNIN_BUTTON = 'show_signin_button' + SHOW_SIGNIN_BUTTON = 'show_signin_button', + ASSET_BULK_EXPORT_ENABLED = 'asset_bulk_export_enabled' } /** @@ -163,6 +164,20 @@ export function useFeatureFlags() { ServerFeatureFlag.SHOW_SIGNIN_BUTTON, undefined ) + }, + /** + * Whether the backend supports bundling a multi-asset selection into a + * single ZIP via `POST /assets/export`, falling back to per-file direct + * downloads otherwise. Defaults to `isCloud` so behavior is unchanged + * before the backend advertises the flag (Cloud has the endpoint today, + * OSS does not); the served value wins once BE-997 registers it. + */ + get assetBulkExportEnabled() { + return resolveFlag( + ServerFeatureFlag.ASSET_BULK_EXPORT_ENABLED, + remoteConfig.value.asset_bulk_export_enabled, + isCloud + ) } }) diff --git a/src/platform/assets/composables/useMediaAssetActions.test.ts b/src/platform/assets/composables/useMediaAssetActions.test.ts index 60165076c96..3d66d1ef860 100644 --- a/src/platform/assets/composables/useMediaAssetActions.test.ts +++ b/src/platform/assets/composables/useMediaAssetActions.test.ts @@ -78,6 +78,12 @@ vi.mock('@/composables/useCopyToClipboard', () => ({ }) })) +// Capability flag gating the server-side ZIP bulk-export path (FE-781). +const mockFeatureFlags = vi.hoisted(() => ({ assetBulkExportEnabled: false })) +vi.mock('@/composables/useFeatureFlags', () => ({ + useFeatureFlags: () => ({ flags: mockFeatureFlags }) +})) + const mockExportWorkflowAction = vi.hoisted(() => vi.fn()) const mockOpenWorkflowAction = vi.hoisted(() => vi.fn()) vi.mock('@/platform/workflow/core/services/workflowActionsService', () => ({ @@ -280,6 +286,7 @@ describe('useMediaAssetActions', () => { vi.clearAllMocks() capturedFilenames.values = [] mockIsCloud.value = false + mockFeatureFlags.assetBulkExportEnabled = false mockGetOutputAssetMetadata.mockReset() mockGetOutputAssetMetadata.mockReturnValue(null) mockGetAssetType.mockReset() @@ -520,8 +527,8 @@ describe('useMediaAssetActions', () => { unmount() }) - it('keeps single explicit assets on the direct download path in cloud', () => { - mockIsCloud.value = true + it('keeps single single-output assets on the direct download path even with bulk export enabled', () => { + mockFeatureFlags.assetBulkExportEnabled = true mockGetOutputAssetMetadata.mockReturnValue({ jobId: 'job1', outputCount: 1 @@ -547,8 +554,8 @@ describe('useMediaAssetActions', () => { expect(mockTrackExport).not.toHaveBeenCalled() }) - it('uses ZIP export for an injected single multi-output asset in cloud', async () => { - mockIsCloud.value = true + it('uses ZIP export for an injected single multi-output asset when bulk export is enabled', async () => { + mockFeatureFlags.assetBulkExportEnabled = true mockGetAssetType.mockReturnValue('output') mockGetOutputAssetMetadata.mockReturnValue({ jobId: 'job1', @@ -581,9 +588,72 @@ describe('useMediaAssetActions', () => { }) }) - describe('downloadAssets - cloud zip filters', () => { - beforeEach(() => { + describe('downloadAssets - bulk export capability gating (FE-781)', () => { + function createMultiOutputAssets(): AssetItem[] { + mockGetAssetType.mockReturnValue('output') + mockGetOutputAssetMetadata.mockImplementation( + (meta: Record | undefined) => + meta && 'jobId' in meta ? meta : null + ) + return [ + createMockAsset({ + id: 'a1', + name: 'img1.png', + preview_url: 'https://example.com/img1.png', + tags: ['output'], + user_metadata: { jobId: 'job1', outputCount: 1 } + }), + createMockAsset({ + id: 'a2', + name: 'img2.png', + preview_url: 'https://example.com/img2.png', + tags: ['output'], + user_metadata: { jobId: 'job2', outputCount: 1 } + }) + ] + } + + it('falls back to per-file direct downloads when bulk export is disabled', () => { + mockFeatureFlags.assetBulkExportEnabled = false + const assets = createMultiOutputAssets() + + const actions = useMediaAssetActions() + actions.downloadAssets(assets) + + expect(mockCreateAssetExport).not.toHaveBeenCalled() + expect(mockTrackExport).not.toHaveBeenCalled() + expect(mockDownloadFile).toHaveBeenCalledTimes(2) + }) + + it('routes multi-asset selections to ZIP export when bulk export is enabled', async () => { + mockFeatureFlags.assetBulkExportEnabled = true + const assets = createMultiOutputAssets() + + const actions = useMediaAssetActions() + actions.downloadAssets(assets) + + await vi.waitFor(() => { + expect(mockCreateAssetExport).toHaveBeenCalledTimes(1) + }) + expect(mockDownloadFile).not.toHaveBeenCalled() + }) + + it('gates on the capability flag, not isCloud', () => { mockIsCloud.value = true + mockFeatureFlags.assetBulkExportEnabled = false + const assets = createMultiOutputAssets() + + const actions = useMediaAssetActions() + actions.downloadAssets(assets) + + expect(mockCreateAssetExport).not.toHaveBeenCalled() + expect(mockDownloadFile).toHaveBeenCalledTimes(2) + }) + }) + + describe('downloadAssets - zip export filters', () => { + beforeEach(() => { + mockFeatureFlags.assetBulkExportEnabled = true mockCreateAssetExport.mockClear() mockTrackExport.mockClear() mockGetAssetType.mockReturnValue('output') @@ -702,7 +772,7 @@ describe('useMediaAssetActions', () => { describe('downloadAssets - export toast file count', () => { beforeEach(() => { - mockIsCloud.value = true + mockFeatureFlags.assetBulkExportEnabled = true mockCreateAssetExport.mockClear() mockGetAssetType.mockReturnValue('output') mockGetOutputAssetMetadata.mockImplementation( diff --git a/src/platform/assets/composables/useMediaAssetActions.ts b/src/platform/assets/composables/useMediaAssetActions.ts index b45fed34587..ed5ff87b619 100644 --- a/src/platform/assets/composables/useMediaAssetActions.ts +++ b/src/platform/assets/composables/useMediaAssetActions.ts @@ -5,6 +5,7 @@ import { useI18n } from 'vue-i18n' import ConfirmationDialogContent from '@/components/dialog/content/ConfirmationDialogContent.vue' import { downloadFile } from '@/base/common/downloadUtil' import { useCopyToClipboard } from '@/composables/useCopyToClipboard' +import { useFeatureFlags } from '@/composables/useFeatureFlags' import { isCloud } from '@/platform/distribution/types' import { useWorkflowActionsService } from '@/platform/workflow/core/services/workflowActionsService' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' @@ -71,6 +72,7 @@ export function useMediaAssetActions() { const dialogStore = useDialogStore() const mediaContext = inject(MediaAssetKey, null) const { copyToClipboard } = useCopyToClipboard() + const { flags } = useFeatureFlags() const workflowActions = useWorkflowActionsService() const litegraphService = useLitegraphService() const nodeDefStore = useNodeDefStore() @@ -102,10 +104,11 @@ export function useMediaAssetActions() { /** * Download one or more assets. - * In cloud mode, creates a ZIP export via the backend when called with - * 2+ assets or with any asset whose job has `outputCount > 1`. - * Falls back to direct downloads in OSS mode and for single single-output - * assets. With no argument, uses the asset from `MediaAssetKey` context. + * When the backend advertises bulk export, creates a ZIP export via the + * backend when called with 2+ assets or with any asset whose job has + * `outputCount > 1`. Falls back to per-file direct downloads otherwise and + * for single single-output assets. With no argument, uses the asset from + * `MediaAssetKey` context. */ const downloadAssets = (assets?: AssetItem[]) => { const targetAssets = @@ -117,7 +120,10 @@ export function useMediaAssetActions() { return typeof count === 'number' && count > 1 }) - if (isCloud && (targetAssets.length > 1 || hasMultiOutputJobs)) { + if ( + flags.assetBulkExportEnabled && + (targetAssets.length > 1 || hasMultiOutputJobs) + ) { void downloadAssetsAsZip(targetAssets) return } diff --git a/src/platform/remoteConfig/types.ts b/src/platform/remoteConfig/types.ts index f2134aa513b..c79a8f0280c 100644 --- a/src/platform/remoteConfig/types.ts +++ b/src/platform/remoteConfig/types.ts @@ -103,5 +103,6 @@ export type RemoteConfig = { workflow_sharing_enabled?: boolean comfyhub_upload_enabled?: boolean comfyhub_profile_gate_enabled?: boolean + asset_bulk_export_enabled?: boolean sentry_dsn?: string }