Skip to content
Merged

Release #1017

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion assets/src/video-player/common/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
const VIDEO_EXTENSIONS = [ 'mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv', 'm4v' ];

const hasVideoExtension = ( url ) => {
try {
const { pathname } = new URL( url );
const extension = pathname.split( '.' ).pop()?.toLowerCase();
return VIDEO_EXTENSIONS.includes( extension );
} catch {
return false;
}
};

export const isOptimoleURL = async( url ) => {
const customEmbedRegexPattern = new RegExp( `^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*$` );

if ( ! customEmbedRegexPattern.test( url ) ) {
if ( ! customEmbedRegexPattern.test( url ) ) {
return false;
}

if ( ! hasVideoExtension( url ) ) {
return false;
}

Expand All @@ -12,6 +28,7 @@ export const isOptimoleURL = async( url ) => {

return contentType.includes( 'video' );
}
return false;
} catch ( error ) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion assets/src/video-player/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ registerBlockVariation( 'core/embed', {
return 'optimole' === blockAttributes.providerNameSlug;
},
patterns: [
`^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*$`
`^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*\\.(mp4|webm|ogg|mov|avi|mkv|m4v)$`
]
});

Expand Down
2 changes: 1 addition & 1 deletion inc/traits/normalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function get_unoptimized_url( $url ) {
}
// If the url is an uploaded image, return the url
if ( Optml_Media_Offload::is_uploaded_image( $url ) ) {
$pattern = '#/id:([^/]+)/((?:https?|http)://\S+)#';
$pattern = '#/id:([^/]+)/((?:https?://|http://|directUpload/)\S+)#';
if ( preg_match( $pattern, $url, $matches ) ) {
$url = $matches[0];
}
Expand Down
Loading