fix: prefer job-level exports over asset filters

Amp-Thread-ID: https://ampcode.com/threads/T-019d6a6f-e97a-7659-b41f-41763db3920a
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Simon Pinfold
2026-04-08 17:37:49 +12:00
parent 16eacfe87c
commit 2ca98c8ae4
2 changed files with 32 additions and 6 deletions

View File

@@ -379,6 +379,22 @@ describe('useMediaAssetActions', () => {
job2: ['img2.png']
})
})
it('should omit name filters when job-level and asset-level selections share a jobId', async () => {
const jobLevelAsset = createOutputAsset('a1', 'img1.png', 'job1', 3)
const assetLevelSelection = createOutputAsset('a2', 'img2.png', 'job1')
const actions = useMediaAssetActions()
actions.downloadMultipleAssets([jobLevelAsset, assetLevelSelection])
await vi.waitFor(() => {
expect(mockCreateAssetExport).toHaveBeenCalledTimes(1)
})
const payload = mockCreateAssetExport.mock.calls[0][0]
expect(payload.job_ids).toEqual(['job1'])
expect(payload.job_asset_name_filters).toBeUndefined()
})
})
describe('downloadMultipleAssets - export toast file count', () => {

View File

@@ -154,13 +154,22 @@ export function useMediaAssetActions() {
if (getAssetType(asset) === 'output') {
const metadata = getOutputAssetMetadata(asset.user_metadata)
const jobId = metadata?.jobId || asset.id
const outputCount = metadata?.outputCount
if (!jobIds.includes(jobId)) {
jobIds.push(jobId)
}
// Only add name filters when outputCount is unknown.
// When outputCount is set, the asset is a job-level selection
// from the gallery and the user wants all outputs for that job.
if (metadata?.jobId && asset.name && metadata.outputCount == null) {
if (typeof outputCount === 'number') {
delete jobAssetNameFilters[jobId]
} else if (
metadata?.jobId &&
asset.name &&
!countedJobLevelIds.has(jobId)
) {
if (!jobAssetNameFilters[metadata.jobId]) {
jobAssetNameFilters[metadata.jobId] = []
}
@@ -173,12 +182,13 @@ export function useMediaAssetActions() {
// represents a single job-wide export of outputCount files. Once a
// job has been counted at the job level, skip any further assets
// from the same jobId so mixed selections don't double-count.
const outputCount = metadata?.outputCount
if (countedJobLevelIds.has(jobId)) {
if (typeof outputCount === 'number') {
if (!countedJobLevelIds.has(jobId)) {
countedJobLevelIds.add(jobId)
fileCount += outputCount
}
} else if (countedJobLevelIds.has(jobId)) {
// already counted at the job level, ignore this asset
} else if (typeof outputCount === 'number') {
fileCount += outputCount
countedJobLevelIds.add(jobId)
} else {
fileCount += 1
}