Plugin Directory

source: jetpack/trunk/jetpack_vendor/automattic/jetpack-videopress/src/client/state/utils/map-videos.ts @ 2832426

Last change on this file since 2832426 was 2832426, checked in by wpkaren, 20 months ago

Updating trunk to version 11.7-a.3

File size: 2.2 KB
Line 
1/**
2 * Internal dependencies
3 */
4import { OriginalVideoPressVideo, VideoPressVideo } from '../../admin/types';
5
6export const mapVideoFromWPV2MediaEndpoint = (
7        video: OriginalVideoPressVideo
8): VideoPressVideo => {
9        const {
10                media_details: mediaDetails,
11                id,
12                jetpack_videopress: jetpackVideoPress,
13                jetpack_videopress_guid: guid,
14                slug: filename,
15        } = video;
16
17        const { videopress: videoPressMediaDetails, width, height } = mediaDetails;
18
19        const {
20                title,
21                description,
22                caption,
23                rating,
24                allow_download: allowDownload,
25                display_embed: displayEmbed,
26                privacy_setting: privacySetting,
27                needs_playback_token: needsPlaybackToken,
28        } = jetpackVideoPress;
29
30        const {
31                original: url,
32                poster,
33                upload_date: uploadDate,
34                duration,
35                is_private: isPrivate,
36                file_url_base: fileURLBase,
37                finished,
38                files = {
39                        dvd: {
40                                original_img: '',
41                        },
42                },
43        } = videoPressMediaDetails || {};
44
45        const { dvd } = files;
46
47        /*
48         * Define thumbnail picking the image from DVD file type
49         * Issue: https://github.com/Automattic/jetpack/issues/26319
50         */
51        const thumbnail = dvd?.original_img ? `${ fileURLBase.https }${ dvd.original_img }` : undefined;
52
53        return {
54                id,
55                guid,
56                title,
57                description,
58                caption,
59                url,
60                uploadDate,
61                duration,
62                isPrivate,
63                posterImage: poster,
64                allowDownload,
65                displayEmbed,
66                rating,
67                privacySetting,
68                needsPlaybackToken,
69                poster: {
70                        src: poster,
71                        width,
72                        height,
73                },
74                thumbnail,
75                finished,
76                filename,
77        };
78};
79
80export const mapVideosFromWPV2MediaEndpoint = (
81        videos: OriginalVideoPressVideo[]
82): VideoPressVideo[] => {
83        return videos?.map?.( mapVideoFromWPV2MediaEndpoint );
84};
85
86export const mapLocalVideoFromWPV2MediaEndpoint = (
87        video: OriginalVideoPressVideo
88): VideoPressVideo => {
89        const {
90                media_details: mediaDetails,
91                id,
92                jetpack_videopress: jetpackVideoPress,
93                source_url: url,
94                date: uploadDate,
95        } = video;
96
97        const { width, height, length: duration } = mediaDetails;
98
99        const { title, description, caption } = jetpackVideoPress;
100
101        return {
102                id,
103                title,
104                description,
105                caption,
106                width,
107                height,
108                url,
109                uploadDate,
110                duration,
111        };
112};
113
114export const mapLocalVideosFromWPV2MediaEndpoint = (
115        videos: OriginalVideoPressVideo[]
116): VideoPressVideo[] => {
117    ��   return videos.map( mapLocalVideoFromWPV2MediaEndpoint );
118};
Note: See TracBrowser for help on using the repository browser.