Repository URL to install this package:
|
Version:
3.12.2 ▾
|
import isImage from '@filerobot/utils/lib/isImage';
import isFileSupportedByCloudimage from '@filerobot/utils/lib/isFileSupportedByCloudimage';
import isPdf from './isPdf';
import { BYTES_TO_MEGA_BYTES, UNSUPPORTED_FILES_TO_EXPORT_REASONS } from './constants';
var areAllSelectionsImages = function areAllSelectionsImages(items) {
return items.every(isImage);
};
var maximumItemSize = 100 * BYTES_TO_MEGA_BYTES;
var photoshopItemType = 'image/vnd.adobe.photoshop';
var areSelectionsMixedWithPdf = function areSelectionsMixedWithPdf(items) {
return items.length && items.some(isPdf) && items.some(function (item) {
return !isPdf(item);
});
};
/**
* Check if the items provided are supportted to be exported.
* @param {items}
* @returns {i18nStr} If not supported.
* @returns {undefined} If supported.
*/
export default function checkItemsSupportExportWithReason(items) {
var i18nStr;
var areAllItemsImages = areAllSelectionsImages(items);
items.forEach(function (i) {
if (!isFileSupportedByCloudimage(i)) {
i18nStr = areAllItemsImages ? UNSUPPORTED_FILES_TO_EXPORT_REASONS.NOT_SUPPORTED_IMAGES : UNSUPPORTED_FILES_TO_EXPORT_REASONS.NOT_SUPPORTED_FILES;
return i18nStr;
}
if (i.size.bytes > maximumItemSize && i.type === photoshopItemType) {
i18nStr = UNSUPPORTED_FILES_TO_EXPORT_REASONS.NOT_SUPPORTED_PDS_SIZE;
return i18nStr;
}
});
var areItemsMixedWithPdf = areSelectionsMixedWithPdf(items);
if (areItemsMixedWithPdf) {
i18nStr = UNSUPPORTED_FILES_TO_EXPORT_REASONS.MIXED_WITH_PDF;
}
return i18nStr;
}