diff --git a/src/components/damImage/uploadQueue/api/damAssetApi.ts b/src/components/damImage/uploadQueue/api/damAssetApi.ts index 88e3b420..19db3261 100644 --- a/src/components/damImage/uploadQueue/api/damAssetApi.ts +++ b/src/components/damImage/uploadQueue/api/damAssetApi.ts @@ -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((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) + }) + }) +} diff --git a/src/components/damImage/uploadQueue/components/ImageWidgetMultipleInner.vue b/src/components/damImage/uploadQueue/components/ImageWidgetMultipleInner.vue index 5a9beaa8..05e8d706 100644 --- a/src/components/damImage/uploadQueue/components/ImageWidgetMultipleInner.vue +++ b/src/components/damImage/uploadQueue/components/ImageWidgetMultipleInner.vue @@ -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, @@ -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) => {