Skip to content

Commit

Permalink
store image widget multiple asset authors
Browse files Browse the repository at this point in the history
  • Loading branch information
volar committed Dec 12, 2024
1 parent 4923aae commit 7155754
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/components/damImage/uploadQueue/api/damAssetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,52 @@ export const fetchAssetListByIdsMultipleLicences = async (

return results
}

export type AssetAuthorsItems = AssetAuthorsItem[]
export interface AssetAuthorsItem {
id: DocId
authors: DocId[]
}

async function updateAuthorsSequence(client: () => AxiosInstance, items: AssetAuthorsItems) {
const totalCalls = Math.ceil(items.length / BULK_METADATA_LIMIT)
const responses: AxiosResponse[] = []
if (items.length === 0) return Promise.resolve([])

for (let i = 0; i < totalCalls; i++) {
const offset = i * BULK_METADATA_LIMIT
const reduced = items.slice(offset, offset + BULK_METADATA_LIMIT)
const res = await client().patch(END_POINT + '/metadata-bulk-update', JSON.stringify(reduced))
responses.push(res)
}
return responses
}

export const bulkUpdateAssetsAuthors = (
client: () => AxiosInstance,
items: AssetAuthorsItems,
) => {
return new Promise<AssetMetadataBulkItem[]>((resolve, reject) => {
updateAuthorsSequence(client, items)
.then((responses) => {
if (items.length === 0) {
return resolve([])
} else if (responses.length === 0) {
return reject(responses)
} else if (
responses.every((res) => {
return res.status === HTTP_STATUS_OK
})
) {
const bulkItemsRes: AssetMetadataBulkItem[] = responses.flatMap((response) => response.data)
return resolve(bulkItemsRes)
} else {
return reject(responses)
}
})
.catch((err) => {
//
return reject(err)
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import UploadQueueDialog from '@/components/damImage/uploadQueue/components/Uplo
import { useUploadQueueDialog } from '@/components/damImage/uploadQueue/composables/uploadQueueDialog'
import AssetDetailDialog from '@/components/damImage/uploadQueue/components/AssetDetailDialog.vue'
import {
type AssetAuthorsItems,
bulkUpdateAssetsAuthors,
fetchAssetByFileId,
fetchAssetListByIds,
fetchAssetListByIdsMultipleLicences,
Expand Down Expand Up @@ -298,6 +300,15 @@ const saveImages = async () => {
return false
}
try {
const assetUpdateItems: AssetAuthorsItems = []
toRaw(images.value).forEach((image) => {
if (image.showDamAuthors) {
assetUpdateItems.push({ id: image.dam.damId, authors: image.damAuthors })
}
})
if (assetUpdateItems.length) {
await bulkUpdateAssetsAuthors(damClient, assetUpdateItems)
}
const resItems = await bulkUpdateImages(imageClient, toRaw(images.value))
const ids: IntegerId[] = []
const items = resItems.map((resItem) => {
Expand Down

0 comments on commit 7155754

Please sign in to comment.