diff --git a/src/composables/useFeatureFlags.test.ts b/src/composables/useFeatureFlags.test.ts index 4ce22464b89..1b24c3afc36 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 64f2919ebc4..a67d527a031 100644 --- a/src/composables/useFeatureFlags.ts +++ b/src/composables/useFeatureFlags.ts @@ -29,6 +29,7 @@ export enum ServerFeatureFlag { COMFYHUB_UPLOAD_ENABLED = 'comfyhub_upload_enabled', COMFYHUB_PROFILE_GATE_ENABLED = 'comfyhub_profile_gate_enabled', SHOW_SIGNIN_BUTTON = 'show_signin_button', + ASSET_BULK_EXPORT_ENABLED = 'asset_bulk_export_enabled', UNIFIED_CLOUD_AUTH = 'unified_cloud_auth' } @@ -167,6 +168,20 @@ export function useFeatureFlags() { 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 + ) + }, get unifiedCloudAuthEnabled() { return resolveFlag( ServerFeatureFlag.UNIFIED_CLOUD_AUTH, diff --git a/src/platform/assets/composables/useMediaAssetActions.test.ts b/src/platform/assets/composables/useMediaAssetActions.test.ts index e4fa6c50d11..c9c8f110ae4 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', @@ -582,9 +589,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') @@ -703,7 +773,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 8ba12f12496..d5d63d60934 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 { withNodeAddSource } from '@/platform/telemetry/nodeAdded/nodeAddSource' import { useWorkflowActionsService } from '@/platform/workflow/core/services/workflowActionsService' @@ -76,6 +77,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() @@ -107,10 +109,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 = @@ -122,7 +125,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 6d9188d4fc9..a39a858f45d 100644 --- a/src/platform/remoteConfig/types.ts +++ b/src/platform/remoteConfig/types.ts @@ -108,6 +108,7 @@ export type RemoteConfig = { workflow_sharing_enabled?: boolean comfyhub_upload_enabled?: boolean comfyhub_profile_gate_enabled?: boolean + asset_bulk_export_enabled?: boolean unified_cloud_auth?: boolean sentry_dsn?: string }