]>
Commit | Line | Data |
---|---|---|
418d092a C |
1 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest, makeUploadRequest } from '../requests/requests' |
2 | import { VideoPlaylistCreate } from '../../models/videos/playlist/video-playlist-create.model' | |
3 | import { omit } from 'lodash' | |
4 | import { VideoPlaylistUpdate } from '../../models/videos/playlist/video-playlist-update.model' | |
5 | import { VideoPlaylistElementCreate } from '../../models/videos/playlist/video-playlist-element-create.model' | |
6 | import { VideoPlaylistElementUpdate } from '../../models/videos/playlist/video-playlist-element-update.model' | |
09209296 | 7 | |
418d092a C |
8 | function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) { |
9 | const path = '/api/v1/video-playlists' | |
10 | ||
11 | const query = { | |
12 | start, | |
13 | count, | |
14 | sort | |
15 | } | |
16 | ||
17 | return makeGetRequest({ | |
18 | url, | |
19 | path, | |
20 | query | |
21 | }) | |
09209296 C |
22 | } |
23 | ||
418d092a C |
24 | function getVideoPlaylist (url: string, playlistId: number | string, statusCodeExpected = 200) { |
25 | const path = '/api/v1/video-playlists/' + playlistId | |
26 | ||
27 | return makeGetRequest({ | |
28 | url, | |
29 | path, | |
30 | statusCodeExpected | |
31 | }) | |
09209296 C |
32 | } |
33 | ||
418d092a C |
34 | function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = 200) { |
35 | const path = '/api/v1/video-playlists/' + playlistId | |
36 | ||
37 | return makeDeleteRequest({ | |
38 | url, | |
39 | path, | |
40 | token, | |
41 | statusCodeExpected | |
42 | }) | |
09209296 C |
43 | } |
44 | ||
418d092a C |
45 | function createVideoPlaylist (options: { |
46 | url: string, | |
47 | token: string, | |
48 | playlistAttrs: VideoPlaylistCreate, | |
49 | expectedStatus: number | |
50 | }) { | |
51 | const path = '/api/v1/video-playlists/' | |
52 | ||
53 | const fields = omit(options.playlistAttrs, 'thumbnailfile') | |
4c280004 | 54 | |
418d092a C |
55 | const attaches = options.playlistAttrs.thumbnailfile |
56 | ? { thumbnailfile: options.playlistAttrs.thumbnailfile } | |
57 | : {} | |
4c280004 | 58 | |
418d092a C |
59 | return makeUploadRequest({ |
60 | method: 'POST', | |
61 | url: options.url, | |
62 | path, | |
63 | token: options.token, | |
64 | fields, | |
65 | attaches, | |
66 | statusCodeExpected: options.expectedStatus | |
67 | }) | |
68 | } | |
4c280004 | 69 | |
418d092a C |
70 | function updateVideoPlaylist (options: { |
71 | url: string, | |
72 | token: string, | |
73 | playlistAttrs: VideoPlaylistUpdate, | |
74 | expectedStatus: number | |
75 | }) { | |
76 | const path = '/api/v1/video-playlists/' | |
4c280004 | 77 | |
418d092a | 78 | const fields = omit(options.playlistAttrs, 'thumbnailfile') |
4c280004 | 79 | |
418d092a C |
80 | const attaches = options.playlistAttrs.thumbnailfile |
81 | ? { thumbnailfile: options.playlistAttrs.thumbnailfile } | |
82 | : {} | |
4c280004 | 83 | |
418d092a C |
84 | return makeUploadRequest({ |
85 | method: 'PUT', | |
86 | url: options.url, | |
87 | path, | |
88 | token: options.token, | |
89 | fields, | |
90 | attaches, | |
91 | statusCodeExpected: options.expectedStatus | |
92 | }) | |
93 | } | |
94 | ||
95 | function addVideoInPlaylist (options: { | |
96 | url: string, | |
97 | token: string, | |
98 | playlistId: number | string, | |
99 | elementAttrs: VideoPlaylistElementCreate | |
100 | expectedStatus: number | |
101 | }) { | |
102 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos' | |
103 | ||
104 | return makePostBodyRequest({ | |
105 | url: options.url, | |
106 | path, | |
107 | token: options.token, | |
108 | fields: options.elementAttrs, | |
109 | statusCodeExpected: options.expectedStatus | |
110 | }) | |
111 | } | |
112 | ||
113 | function updateVideoPlaylistElement (options: { | |
114 | url: string, | |
115 | token: string, | |
116 | playlistId: number | string, | |
117 | videoId: number | string, | |
118 | elementAttrs: VideoPlaylistElementUpdate, | |
119 | expectedStatus: number | |
120 | }) { | |
121 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/' + options.videoId | |
122 | ||
123 | return makePutBodyRequest({ | |
124 | url: options.url, | |
125 | path, | |
126 | token: options.token, | |
127 | fields: options.elementAttrs, | |
128 | statusCodeExpected: options.expectedStatus | |
129 | }) | |
130 | } | |
131 | ||
132 | function removeVideoFromPlaylist (options: { | |
133 | url: string, | |
134 | token: string, | |
135 | playlistId: number | string, | |
136 | videoId: number | string, | |
137 | expectedStatus: number | |
138 | }) { | |
139 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/' + options.videoId | |
140 | ||
141 | return makeDeleteRequest({ | |
142 | url: options.url, | |
143 | path, | |
144 | token: options.token, | |
145 | statusCodeExpected: options.expectedStatus | |
146 | }) | |
147 | } | |
148 | ||
149 | function reorderVideosPlaylist (options: { | |
150 | url: string, | |
151 | token: string, | |
152 | playlistId: number | string, | |
153 | elementAttrs: { | |
154 | startPosition: number, | |
155 | insertAfter: number, | |
156 | reorderLength?: number | |
157 | }, | |
158 | expectedStatus: number | |
159 | }) { | |
160 | const path = '/api/v1/video-playlists/' + options.playlistId + '/videos' | |
161 | ||
162 | return makePutBodyRequest({ | |
163 | url: options.url, | |
164 | path, | |
165 | token: options.token, | |
166 | fields: options.elementAttrs, | |
167 | statusCodeExpected: options.expectedStatus | |
168 | }) | |
4c280004 C |
169 | } |
170 | ||
09209296 C |
171 | // --------------------------------------------------------------------------- |
172 | ||
173 | export { | |
418d092a C |
174 | getVideoPlaylistsList, |
175 | getVideoPlaylist, | |
176 | ||
177 | createVideoPlaylist, | |
178 | updateVideoPlaylist, | |
179 | deleteVideoPlaylist, | |
180 | ||
181 | addVideoInPlaylist, | |
182 | removeVideoFromPlaylist, | |
183 | ||
184 | reorderVideosPlaylist | |
09209296 | 185 | } |