@@ -22,6 +22,16 @@ export default function PostMedia({
2222 videoProgress ?: number ;
2323 setVideoProgress ?: ( value : SetStateAction < number > ) => void ;
2424} ) : JSX . Element {
25+ const isCloudinary = ( ) : boolean => {
26+ if ( post && post ?. coverVideo && post ?. coverVideo ?. url ) {
27+ return post . coverVideo ?. url . includes ( 'media.codingcat.dev/video' ) ||
28+ post . coverVideo ?. url . includes ( 'res.cloudinary.com/video' )
29+ ? true
30+ : false ;
31+ } else {
32+ return false ;
33+ }
34+ } ;
2535 const isYouTube = ( ) : boolean => {
2636 if ( post && post . coverVideo && post . coverVideo . url ) {
2737 return post . coverVideo ?. url . includes ( 'youtu.be' ) ||
@@ -43,21 +53,28 @@ export default function PostMedia({
4353 const onProgress = ( progress ?: { played : number } ) => {
4454 progress && setVideoProgress && setVideoProgress ( progress . played ) ;
4555 } ;
46-
56+ const cloudinaryPublicId = isCloudinary ( )
57+ ? post ?. coverVideo ?. url ?. split ( '/' )
58+ : null ;
4759 return (
4860 < >
4961 { post ?. coverVideo && Object . keys ( post . coverVideo ) . length ? (
5062 < div >
51- { post . coverVideo ?. source === MediaSource . cloudinary ? (
63+ { isCloudinary ( ) ? (
5264 < >
5365 < Video
5466 cloudName = { config . name }
55- publicId = { post . coverVideo ?. public_id }
67+ publicId = {
68+ cloudinaryPublicId
69+ ? `${ cloudinaryPublicId . at ( - 2 ) } /${ cloudinaryPublicId
70+ . at ( - 1 )
71+ ?. replace ( '.mp4' , '' ) } `
72+ : undefined
73+ }
5674 privateCdn = { config . cname ? true : false }
5775 secure = { config . cname ? true : false }
5876 secureDistribution = { config . cname ? config . cname : '' }
5977 sourceTypes = { [ 'hls' , 'webm' , 'ogv' , 'mp4' ] }
60- poster = { `https://${ config . cname } /image/upload/${ post . coverPhoto ?. public_id } ` }
6178 controls = { true }
6279 fluid = "true"
6380 style = { { height : '100%' , width : '100%' } }
0 commit comments