diff --git a/projects/packages/videopress/changelog/update-videopress-skip-rating-checking-in-editor-context b/projects/packages/videopress/changelog/update-videopress-skip-rating-checking-in-editor-context new file mode 100644 index 000000000000..0b12528c5dae --- /dev/null +++ b/projects/packages/videopress/changelog/update-videopress-skip-rating-checking-in-editor-context @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +VideoPress: skip rating checking when pulling video data for the block diff --git a/projects/packages/videopress/src/client/block-editor/hooks/use-video-data-update/index.ts b/projects/packages/videopress/src/client/block-editor/hooks/use-video-data-update/index.ts index 9aba18f76964..0f8aa5f72dc1 100644 --- a/projects/packages/videopress/src/client/block-editor/hooks/use-video-data-update/index.ts +++ b/projects/packages/videopress/src/client/block-editor/hooks/use-video-data-update/index.ts @@ -162,7 +162,11 @@ export function useSyncMedia( options: UseSyncMediaOptionsProps ): UseSyncMediaProps { const { id, guid } = attributes; - const { videoData, isRequestingVideoData } = useVideoData( { id, guid } ); + const { videoData, isRequestingVideoData } = useVideoData( { + id, + guid, + skipRatingControl: true, + } ); const isSaving = useSelect( select => select( editorStore ).isSavingPost(), [] ); const wasSaving = usePrevious( isSaving ); diff --git a/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/index.ts b/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/index.ts index 1e5d159c68ae..eef2fe491323 100644 --- a/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/index.ts +++ b/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/index.ts @@ -11,7 +11,10 @@ import { decodeEntities } from '../../../lib/url'; /** * Types */ -import { WPCOMRestAPIVideosGetEndpointResponseProps } from '../../../types'; +import { + WPCOMRestAPIVideosGetEndpointRequestArguments, + WPCOMRestAPIVideosGetEndpointResponseProps, +} from '../../../types'; import { UseVideoDataProps, UseVideoDataArgumentsProps, VideoDataProps } from './types'; /** @@ -23,6 +26,7 @@ import { UseVideoDataProps, UseVideoDataArgumentsProps, VideoDataProps } from '. export default function useVideoData( { id, guid, + skipRatingControl = false, }: UseVideoDataArgumentsProps ): UseVideoDataProps { const [ videoData, setVideoData ] = useState< VideoDataProps >( {} ); const [ isRequestingVideoData, setIsRequestingVideoData ] = useState( false ); @@ -34,12 +38,26 @@ export default function useVideoData( { async function fetchVideoItem() { try { const tokenData = await getMediaToken( 'playback', { id, guid } ); - const params = tokenData?.token - ? `?${ new URLSearchParams( { metadata_token: tokenData.token } ).toString() }` + const params: WPCOMRestAPIVideosGetEndpointRequestArguments = {}; + + // Add the token to the request if it exists. + if ( tokenData?.token ) { + params.metadata_token = tokenData.token; + } + + // Add the birthdate to skip the rating check if it's required. + if ( skipRatingControl ) { + params.birth_day = '1'; + params.birth_month = '1'; + params.birth_year = '2000'; + } + + const requestArgs = Object.keys( params ).length + ? `?${ new URLSearchParams( params ).toString() }` : ''; const response: WPCOMRestAPIVideosGetEndpointResponseProps = await apiFetch( { - url: `https://public-api.wordpress.com/rest/v1.1/videos/${ guid }${ params }`, + url: `https://public-api.wordpress.com/rest/v1.1/videos/${ guid }${ requestArgs }`, credentials: 'omit', global: true, } ); diff --git a/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/types.ts b/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/types.ts index 519504acc391..8ba5781966e5 100644 --- a/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/types.ts +++ b/projects/packages/videopress/src/client/block-editor/hooks/use-video-data/types.ts @@ -7,7 +7,7 @@ import { VideoGUID, VideoId } from '../../blocks/video/types'; export type UseVideoDataArgumentsProps = { id?: VideoId; guid?: VideoGUID; - isPrivate?: boolean; + skipRatingControl: boolean; }; export type VideoDataProps = { diff --git a/projects/packages/videopress/src/client/types.ts b/projects/packages/videopress/src/client/types.ts index 43f4699d9bf8..ab303a208fe9 100644 --- a/projects/packages/videopress/src/client/types.ts +++ b/projects/packages/videopress/src/client/types.ts @@ -93,6 +93,13 @@ export type WPV2mediaGetEndpointResponseProps = { /* * https://public-api.wordpress.com/rest/v1.1/videos/${ guid } */ +export type WPCOMRestAPIVideosGetEndpointRequestArguments = { + metadata_token?: string; + birth_day?: string; + birth_month?: string; + birth_year?: string; +}; + export type WPCOMRestAPIVideosGetEndpointResponseProps = { // source_url: string;