sign for multiple media attributes

This commit is contained in:
Marc-Roig 2023-02-22 16:12:39 +01:00
parent 5b92402129
commit 813eed2d9c

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const { traverseEntity } = require('@strapi/utils'); const { mapAsync, traverseEntity } = require('@strapi/utils');
const { getService } = require('../../../utils'); const { getService } = require('../../../utils');
/** /**
@ -15,10 +15,20 @@ const { getService } = require('../../../utils');
const signEntityMediaVisitor = async ({ key, value, attribute }, { set }) => { const signEntityMediaVisitor = async ({ key, value, attribute }, { set }) => {
const { signFileUrls } = getService('file'); const { signFileUrls } = getService('file');
if (value && attribute.type === 'media') { if (!value || attribute.type !== 'media') {
return;
}
// If the attribute is repeatable sign each file
if (attribute.multiple) {
const signedFiles = await mapAsync(value, signFileUrls);
set(key, signedFiles);
return;
}
// If the attribute is not repeatable only sign a single file
const signedFile = await signFileUrls(value); const signedFile = await signFileUrls(value);
set(key, signedFile); set(key, signedFile);
}
}; };
/** /**