Skip to content

Commit

Permalink
Make sure Audio files don't make it in
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Nov 17, 2024
1 parent 40b84f9 commit 660e726
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
58 changes: 31 additions & 27 deletions packages/block-editor/src/components/media-placeholder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,33 +252,37 @@ export function MediaPlaceholder( {
}

const uploadedMediaList = await Promise.all(
mediaBlocks.map( ( block ) =>
block.attributes.id
? block.attributes
: new Promise( ( resolve, reject ) => {
window
.fetch( block.attributes.url )
.then( ( response ) => response.blob() )
.then( ( blob ) =>
mediaUpload( {
filesList: [ blob ],
additionalData: {
title: block.attributes.title,
alt_text: block.attributes.alt,
caption: block.attributes.caption,
},
onFileChange: ( [ media ] ) => {
if ( media.id ) {
resolve( media );
}
},
allowedTypes,
onError: reject,
} )
)
.catch( () => resolve( block.attributes.url ) );
} )
)
mediaBlocks.map( ( block ) => {
const blockType = block.name.split( '/' )[ 1 ];
if ( block.attributes.id ) {
block.attributes.type = blockType;
return block.attributes;
}
return new Promise( ( resolve, reject ) => {
window
.fetch( block.attributes.url )
.then( ( response ) => response.blob() )
.then( ( blob ) =>
mediaUpload( {
filesList: [ blob ],
additionalData: {
title: block.attributes.title,
alt_text: block.attributes.alt,
caption: block.attributes.caption,
type: blockType,
},
onFileChange: ( [ media ] ) => {
if ( media.id ) {
resolve( media );
}
},
allowedTypes,
onError: reject,
} )
)
.catch( () => resolve( block.attributes.url ) );
} );
} )
).catch( ( err ) => onError( err ) );

if ( multiple ) {
Expand Down
6 changes: 0 additions & 6 deletions packages/block-library/src/cover/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ export function attributesFromMedia( media ) {
media.type === VIDEO_BACKGROUND_TYPE )
) {
mediaType = media.type;
// If there's a url or src but no type, it's probably coming from the inserter so
// we still want to return what data we have.
} else if ( media.url ) {
mediaType = IMAGE_BACKGROUND_TYPE;
} else if ( media.src ) {
mediaType = VIDEO_BACKGROUND_TYPE;
} else {
return;
}
Expand Down

0 comments on commit 660e726

Please sign in to comment.