aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/videos/video-playlists.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils/videos/video-playlists.ts')
-rw-r--r--shared/utils/videos/video-playlists.ts117
1 files changed, 110 insertions, 7 deletions
diff --git a/shared/utils/videos/video-playlists.ts b/shared/utils/videos/video-playlists.ts
index 21285688a..4af52ec0f 100644
--- a/shared/utils/videos/video-playlists.ts
+++ b/shared/utils/videos/video-playlists.ts
@@ -4,6 +4,12 @@ import { omit } from 'lodash'
4import { VideoPlaylistUpdate } from '../../models/videos/playlist/video-playlist-update.model' 4import { VideoPlaylistUpdate } from '../../models/videos/playlist/video-playlist-update.model'
5import { VideoPlaylistElementCreate } from '../../models/videos/playlist/video-playlist-element-create.model' 5import { VideoPlaylistElementCreate } from '../../models/videos/playlist/video-playlist-element-create.model'
6import { VideoPlaylistElementUpdate } from '../../models/videos/playlist/video-playlist-element-update.model' 6import { VideoPlaylistElementUpdate } from '../../models/videos/playlist/video-playlist-element-update.model'
7import { videoUUIDToId } from './videos'
8import { join } from 'path'
9import { root } from '..'
10import { readdir } from 'fs-extra'
11import { expect } from 'chai'
12import { VideoPlaylistType } from '../../models/videos/playlist/video-playlist-type.model'
7 13
8function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) { 14function getVideoPlaylistsList (url: string, start: number, count: number, sort?: string) {
9 const path = '/api/v1/video-playlists' 15 const path = '/api/v1/video-playlists'
@@ -17,7 +23,67 @@ function getVideoPlaylistsList (url: string, start: number, count: number, sort?
17 return makeGetRequest({ 23 return makeGetRequest({
18 url, 24 url,
19 path, 25 path,
20 query 26 query,
27 statusCodeExpected: 200
28 })
29}
30
31function getVideoChannelPlaylistsList (url: string, videoChannelName: string, start: number, count: number, sort?: string) {
32 const path = '/api/v1/video-channels/' + videoChannelName + '/video-playlists'
33
34 const query = {
35 start,
36 count,
37 sort
38 }
39
40 return makeGetRequest({
41 url,
42 path,
43 query,
44 statusCodeExpected: 200
45 })
46}
47
48function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string) {
49 const path = '/api/v1/accounts/' + accountName + '/video-playlists'
50
51 const query = {
52 start,
53 count,
54 sort
55 }
56
57 return makeGetRequest({
58 url,
59 path,
60 query,
61 statusCodeExpected: 200
62 })
63}
64
65function getAccountPlaylistsListWithToken (
66 url: string,
67 token: string,
68 accountName: string,
69 start: number,
70 count: number,
71 playlistType?: VideoPlaylistType
72) {
73 const path = '/api/v1/accounts/' + accountName + '/video-playlists'
74
75 const query = {
76 start,
77 count,
78 playlistType
79 }
80
81 return makeGetRequest({
82 url,
83 token,
84 path,
85 query,
86 statusCodeExpected: 200
21 }) 87 })
22} 88}
23 89
@@ -31,6 +97,17 @@ function getVideoPlaylist (url: string, playlistId: number | string, statusCodeE
31 }) 97 })
32} 98}
33 99
100function getVideoPlaylistWithToken (url: string, token: string, playlistId: number | string, statusCodeExpected = 200) {
101 const path = '/api/v1/video-playlists/' + playlistId
102
103 return makeGetRequest({
104 url,
105 token,
106 path,
107 statusCodeExpected
108 })
109}
110
34function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = 204) { 111function deleteVideoPlaylist (url: string, token: string, playlistId: number | string, statusCodeExpected = 204) {
35 const path = '/api/v1/video-playlists/' + playlistId 112 const path = '/api/v1/video-playlists/' + playlistId
36 113
@@ -93,13 +170,15 @@ function updateVideoPlaylist (options: {
93 }) 170 })
94} 171}
95 172
96function addVideoInPlaylist (options: { 173async function addVideoInPlaylist (options: {
97 url: string, 174 url: string,
98 token: string, 175 token: string,
99 playlistId: number | string, 176 playlistId: number | string,
100 elementAttrs: VideoPlaylistElementCreate 177 elementAttrs: VideoPlaylistElementCreate | { videoId: string }
101 expectedStatus?: number 178 expectedStatus?: number
102}) { 179}) {
180 options.elementAttrs.videoId = await videoUUIDToId(options.url, options.elementAttrs.videoId)
181
103 const path = '/api/v1/video-playlists/' + options.playlistId + '/videos' 182 const path = '/api/v1/video-playlists/' + options.playlistId + '/videos'
104 183
105 return makePostBodyRequest({ 184 return makePostBodyRequest({
@@ -135,7 +214,7 @@ function removeVideoFromPlaylist (options: {
135 token: string, 214 token: string,
136 playlistId: number | string, 215 playlistId: number | string,
137 videoId: number | string, 216 videoId: number | string,
138 expectedStatus: number 217 expectedStatus?: number
139}) { 218}) {
140 const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/' + options.videoId 219 const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/' + options.videoId
141 220
@@ -156,7 +235,7 @@ function reorderVideosPlaylist (options: {
156 insertAfterPosition: number, 235 insertAfterPosition: number,
157 reorderLength?: number 236 reorderLength?: number
158 }, 237 },
159 expectedStatus: number 238 expectedStatus?: number
160}) { 239}) {
161 const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/reorder' 240 const path = '/api/v1/video-playlists/' + options.playlistId + '/videos/reorder'
162 241
@@ -165,15 +244,37 @@ function reorderVideosPlaylist (options: {
165 path, 244 path,
166 token: options.token, 245 token: options.token,
167 fields: options.elementAttrs, 246 fields: options.elementAttrs,
168 statusCodeExpected: options.expectedStatus 247 statusCodeExpected: options.expectedStatus || 204
169 }) 248 })
170} 249}
171 250
251async function checkPlaylistFilesWereRemoved (
252 playlistUUID: string,
253 serverNumber: number,
254 directories = [ 'thumbnails' ]
255) {
256 const testDirectory = 'test' + serverNumber
257
258 for (const directory of directories) {
259 const directoryPath = join(root(), testDirectory, directory)
260
261 const files = await readdir(directoryPath)
262 for (const file of files) {
263 expect(file).to.not.contain(playlistUUID)
264 }
265 }
266}
267
172// --------------------------------------------------------------------------- 268// ---------------------------------------------------------------------------
173 269
174export { 270export {
175 getVideoPlaylistsList, 271 getVideoPlaylistsList,
272 getVideoChannelPlaylistsList,
273 getAccountPlaylistsList,
274 getAccountPlaylistsListWithToken,
275
176 getVideoPlaylist, 276 getVideoPlaylist,
277 getVideoPlaylistWithToken,
177 278
178 createVideoPlaylist, 279 createVideoPlaylist,
179 updateVideoPlaylist, 280 updateVideoPlaylist,
@@ -183,5 +284,7 @@ export {
183 updateVideoPlaylistElement, 284 updateVideoPlaylistElement,
184 removeVideoFromPlaylist, 285 removeVideoFromPlaylist,
185 286
186 reorderVideosPlaylist 287 reorderVideosPlaylist,
288
289 checkPlaylistFilesWereRemoved
187} 290}