mirror of
https://github.com/strapi/strapi.git
synced 2025-12-01 01:22:01 +00:00
27 lines
1.0 KiB
JavaScript
27 lines
1.0 KiB
JavaScript
function findLinkEntities(contentBlock, callback, contentState) {
|
|
contentBlock.findEntityRanges(character => {
|
|
const entityKey = character.getEntity();
|
|
return entityKey !== null && contentState.getEntity(entityKey).getType() === 'LINK';
|
|
}, callback);
|
|
}
|
|
|
|
function findImageEntities(contentBlock, callback, contentState) {
|
|
contentBlock.findEntityRanges(character => {
|
|
const entityKey = character.getEntity();
|
|
|
|
return entityKey !== null && contentState.getEntity(entityKey).getType() === 'IMAGE' && !isVideoType(contentState.getEntity(entityKey).getData().src);
|
|
}, callback);
|
|
}
|
|
|
|
function findVideoEntities(contentBlock, cb, contentState) {
|
|
contentBlock.findEntityRanges(character => {
|
|
const entityKey = character.getEntity();
|
|
|
|
return entityKey !== null && contentState.getEntity(entityKey).getType() === 'IMAGE' && isVideoType(contentState.getEntity(entityKey).getData().src);
|
|
}, cb);
|
|
}
|
|
|
|
const isVideoType = (fileName) => /\.(mp4|mpg|mpeg|mov|avi)$/i.test(fileName);
|
|
|
|
export { findLinkEntities, findImageEntities, findVideoEntities };
|