Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/composables/useFeatureFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions src/composables/useFeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down Expand Up @@ -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,
Expand Down
84 changes: 77 additions & 7 deletions src/platform/assets/composables/useMediaAssetActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -280,6 +286,7 @@ describe('useMediaAssetActions', () => {
vi.clearAllMocks()
capturedFilenames.values = []
mockIsCloud.value = false
mockFeatureFlags.assetBulkExportEnabled = false
mockGetOutputAssetMetadata.mockReset()
mockGetOutputAssetMetadata.mockReturnValue(null)
mockGetAssetType.mockReset()
Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -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<string, unknown> | 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')
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 11 additions & 5 deletions src/platform/assets/composables/useMediaAssetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 =
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/platform/remoteConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading