Skip to content

Commit eae1f5c

Browse files
authored
release: fixes
- Fixes invalid Optimole URLs being picked up for embed in the block editor - Fixes issue where getting the unoptimized image URL didn't account for directly uploaded images to the Optimole Dashboard
2 parents 9bbb63a + cac9570 commit eae1f5c

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

assets/src/video-player/common/utils.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1+
const VIDEO_EXTENSIONS = [ 'mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv', 'm4v' ];
2+
3+
const hasVideoExtension = ( url ) => {
4+
try {
5+
const { pathname } = new URL( url );
6+
const extension = pathname.split( '.' ).pop()?.toLowerCase();
7+
return VIDEO_EXTENSIONS.includes( extension );
8+
} catch {
9+
return false;
10+
}
11+
};
12+
113
export const isOptimoleURL = async( url ) => {
214
const customEmbedRegexPattern = new RegExp( `^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*$` );
315

4-
if ( ! customEmbedRegexPattern.test( url ) ) {
16+
if ( ! customEmbedRegexPattern.test( url ) ) {
17+
return false;
18+
}
19+
20+
if ( ! hasVideoExtension( url ) ) {
521
return false;
622
}
723

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

1329
return contentType.includes( 'video' );
1430
}
31+
return false;
1532
} catch ( error ) {
1633
return false;
1734
}

assets/src/video-player/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ registerBlockVariation( 'core/embed', {
2929
return 'optimole' === blockAttributes.providerNameSlug;
3030
},
3131
patterns: [
32-
`^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*$`
32+
`^https?:\\/\\/(?:www\\.)?${OMVideoPlayerBlock.domain}\\/.*\\.(mp4|webm|ogg|mov|avi|mkv|m4v)$`
3333
]
3434
});
3535

inc/traits/normalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function get_unoptimized_url( $url ) {
5353
}
5454
// If the url is an uploaded image, return the url
5555
if ( Optml_Media_Offload::is_uploaded_image( $url ) ) {
56-
$pattern = '#/id:([^/]+)/((?:https?|http)://\S+)#';
56+
$pattern = '#/id:([^/]+)/((?:https?://|http://|directUpload/)\S+)#';
5757
if ( preg_match( $pattern, $url, $matches ) ) {
5858
$url = $matches[0];
5959
}

0 commit comments

Comments
 (0)