diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/activitypub/client.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/users/my-video-playlists.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-playlists.ts | 5 | ||||
-rw-r--r-- | server/models/video/video-playlist.ts | 5 | ||||
-rw-r--r-- | server/tests/api/check-params/video-playlists.ts | 46 | ||||
-rw-r--r-- | server/tests/api/redundancy/redundancy.ts | 4 | ||||
-rw-r--r-- | server/tests/api/videos/video-hls.ts | 6 | ||||
-rw-r--r-- | server/tests/api/videos/video-playlists.ts | 42 |
8 files changed, 99 insertions, 13 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 0d1dff96f..f1217f6db 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -357,7 +357,7 @@ async function actorFollowers (req: express.Request, actor: ActorModel) { | |||
357 | 357 | ||
358 | async function actorPlaylists (req: express.Request, account: AccountModel) { | 358 | async function actorPlaylists (req: express.Request, account: AccountModel) { |
359 | const handler = (start: number, count: number) => { | 359 | const handler = (start: number, count: number) => { |
360 | return VideoPlaylistModel.listUrlsOfForAP(account.id, start, count) | 360 | return VideoPlaylistModel.listPublicUrlsOfForAP(account.id, start, count) |
361 | } | 361 | } |
362 | 362 | ||
363 | return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) | 363 | return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) |
diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.ts index 1ec175f64..42da02bff 100644 --- a/server/controllers/api/users/my-video-playlists.ts +++ b/server/controllers/api/users/my-video-playlists.ts | |||
@@ -22,7 +22,7 @@ export { | |||
22 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
23 | 23 | ||
24 | async function doVideosInPlaylistExist (req: express.Request, res: express.Response) { | 24 | async function doVideosInPlaylistExist (req: express.Request, res: express.Response) { |
25 | const videoIds = req.query.videoIds as number[] | 25 | const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) |
26 | const user = res.locals.oauth.token.User as UserModel | 26 | const user = res.locals.oauth.token.User as UserModel |
27 | 27 | ||
28 | const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds) | 28 | const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds) |
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts index 87d2c7b51..3bbf796e4 100644 --- a/server/middlewares/validators/videos/video-playlists.ts +++ b/server/middlewares/validators/videos/video-playlists.ts | |||
@@ -4,9 +4,9 @@ import { UserRight } from '../../../../shared' | |||
4 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { UserModel } from '../../../models/account/user' | 5 | import { UserModel } from '../../../models/account/user' |
6 | import { areValidationErrors } from '../utils' | 6 | import { areValidationErrors } from '../utils' |
7 | import { isVideoExist, isVideoFileInfoHashValid, isVideoImage } from '../../../helpers/custom-validators/videos' | 7 | import { isVideoExist, isVideoImage } from '../../../helpers/custom-validators/videos' |
8 | import { CONSTRAINTS_FIELDS } from '../../../initializers' | 8 | import { CONSTRAINTS_FIELDS } from '../../../initializers' |
9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toArray, toValueOrNull, toIntArray } from '../../../helpers/custom-validators/misc' | 9 | import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' |
10 | import { | 10 | import { |
11 | isVideoPlaylistDescriptionValid, | 11 | isVideoPlaylistDescriptionValid, |
12 | isVideoPlaylistExist, | 12 | isVideoPlaylistExist, |
@@ -23,7 +23,6 @@ import { VideoModel } from '../../../models/video/video' | |||
23 | import { authenticatePromiseIfNeeded } from '../../oauth' | 23 | import { authenticatePromiseIfNeeded } from '../../oauth' |
24 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' | 24 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' |
25 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' | 25 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' |
26 | import { areValidActorHandles } from '../../../helpers/custom-validators/activitypub/actor' | ||
27 | 26 | ||
28 | const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ | 27 | const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ |
29 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 28 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index aa42687cd..7dbe4ce8d 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -301,13 +301,14 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
301 | }) | 301 | }) |
302 | } | 302 | } |
303 | 303 | ||
304 | static listUrlsOfForAP (accountId: number, start: number, count: number) { | 304 | static listPublicUrlsOfForAP (accountId: number, start: number, count: number) { |
305 | const query = { | 305 | const query = { |
306 | attributes: [ 'url' ], | 306 | attributes: [ 'url' ], |
307 | offset: start, | 307 | offset: start, |
308 | limit: count, | 308 | limit: count, |
309 | where: { | 309 | where: { |
310 | ownerAccountId: accountId | 310 | ownerAccountId: accountId, |
311 | privacy: VideoPlaylistPrivacy.PUBLIC | ||
311 | } | 312 | } |
312 | } | 313 | } |
313 | 314 | ||
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 803e7afb9..4d8000dbf 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts | |||
@@ -522,6 +522,52 @@ describe('Test video playlists API validator', function () { | |||
522 | }) | 522 | }) |
523 | }) | 523 | }) |
524 | 524 | ||
525 | describe('When checking exists in playlist endpoint', function () { | ||
526 | const path = '/api/v1/users/me/video-playlists/videos-exist' | ||
527 | |||
528 | it('Should fail with an unauthenticated user', async function () { | ||
529 | await makeGetRequest({ | ||
530 | url: server.url, | ||
531 | path, | ||
532 | query: { videoIds: [ 1, 2 ] }, | ||
533 | statusCodeExpected: 401 | ||
534 | }) | ||
535 | }) | ||
536 | |||
537 | it('Should fail with invalid video ids', async function () { | ||
538 | await makeGetRequest({ | ||
539 | url: server.url, | ||
540 | token: server.accessToken, | ||
541 | path, | ||
542 | query: { videoIds: 'toto' } | ||
543 | }) | ||
544 | |||
545 | await makeGetRequest({ | ||
546 | url: server.url, | ||
547 | token: server.accessToken, | ||
548 | path, | ||
549 | query: { videoIds: [ 'toto' ] } | ||
550 | }) | ||
551 | |||
552 | await makeGetRequest({ | ||
553 | url: server.url, | ||
554 | token: server.accessToken, | ||
555 | path, | ||
556 | query: { videoIds: [ 1, 'toto' ] } | ||
557 | }) | ||
558 | }) | ||
559 | |||
560 | it('Should succeed with the correct params', async function () { | ||
561 | await makeGetRequest({ | ||
562 | url: server.url, | ||
563 | token: server.accessToken, | ||
564 | path, | ||
565 | query: { videoIds: [ 1, 2 ] }, | ||
566 | statusCodeExpected: 200 | ||
567 | }) | ||
568 | }) | ||
569 | }) | ||
570 | |||
525 | describe('When deleting an element in a playlist', function () { | 571 | describe('When deleting an element in a playlist', function () { |
526 | const getBase = (wrapper: any = {}) => { | 572 | const getBase = (wrapper: any = {}) => { |
527 | return Object.assign({ | 573 | return Object.assign({ |
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index fc5ffbad7..33921763d 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -184,7 +184,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { | |||
184 | expect(redundancy.baseUrl).to.equal(servers[0].url + '/static/redundancy/hls/' + videoUUID) | 184 | expect(redundancy.baseUrl).to.equal(servers[0].url + '/static/redundancy/hls/' + videoUUID) |
185 | } | 185 | } |
186 | 186 | ||
187 | const baseUrlPlaylist = servers[1].url + '/static/playlists/hls' | 187 | const baseUrlPlaylist = servers[1].url + '/static/streaming-playlists/hls' |
188 | const baseUrlSegment = servers[0].url + '/static/redundancy/hls' | 188 | const baseUrlSegment = servers[0].url + '/static/redundancy/hls' |
189 | 189 | ||
190 | const res = await getVideo(servers[0].url, videoUUID) | 190 | const res = await getVideo(servers[0].url, videoUUID) |
@@ -194,7 +194,7 @@ async function check1PlaylistRedundancies (videoUUID?: string) { | |||
194 | await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) | 194 | await checkSegmentHash(baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist) |
195 | } | 195 | } |
196 | 196 | ||
197 | for (const directory of [ 'test1/redundancy/hls', 'test2/playlists/hls' ]) { | 197 | for (const directory of [ 'test1/redundancy/hls', 'test2/streaming-playlists/hls' ]) { |
198 | const files = await readdir(join(root(), directory, videoUUID)) | 198 | const files = await readdir(join(root(), directory, videoUUID)) |
199 | expect(files).to.have.length.at.least(4) | 199 | expect(files).to.have.length.at.least(4) |
200 | 200 | ||
diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index a1214bad1..3d04758b1 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts | |||
@@ -51,7 +51,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) { | |||
51 | 51 | ||
52 | { | 52 | { |
53 | for (const resolution of resolutions) { | 53 | for (const resolution of resolutions) { |
54 | const res2 = await getPlaylist(`http://localhost:9001/static/playlists/hls/${videoUUID}/${resolution}.m3u8`) | 54 | const res2 = await getPlaylist(`http://localhost:9001/static/streaming-playlists/hls/${videoUUID}/${resolution}.m3u8`) |
55 | 55 | ||
56 | const subPlaylist = res2.text | 56 | const subPlaylist = res2.text |
57 | expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) | 57 | expect(subPlaylist).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) |
@@ -59,7 +59,7 @@ async function checkHlsPlaylist (servers: ServerInfo[], videoUUID: string) { | |||
59 | } | 59 | } |
60 | 60 | ||
61 | { | 61 | { |
62 | const baseUrl = 'http://localhost:9001/static/playlists/hls' | 62 | const baseUrl = 'http://localhost:9001/static/streaming-playlists/hls' |
63 | 63 | ||
64 | for (const resolution of resolutions) { | 64 | for (const resolution of resolutions) { |
65 | await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist) | 65 | await checkSegmentHash(baseUrl, baseUrl, videoUUID, resolution, hlsPlaylist) |
@@ -118,7 +118,7 @@ describe('Test HLS videos', function () { | |||
118 | it('Should have the playlists/segment deleted from the disk', async function () { | 118 | it('Should have the playlists/segment deleted from the disk', async function () { |
119 | for (const server of servers) { | 119 | for (const server of servers) { |
120 | await checkDirectoryIsEmpty(server, 'videos') | 120 | await checkDirectoryIsEmpty(server, 'videos') |
121 | await checkDirectoryIsEmpty(server, join('playlists', 'hls')) | 121 | await checkDirectoryIsEmpty(server, join('streaming-playlists', 'hls')) |
122 | } | 122 | } |
123 | }) | 123 | }) |
124 | 124 | ||
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index baa2b3b8c..931491406 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts | |||
@@ -10,7 +10,7 @@ import { | |||
10 | createVideoPlaylist, | 10 | createVideoPlaylist, |
11 | deleteVideoChannel, | 11 | deleteVideoChannel, |
12 | deleteVideoPlaylist, | 12 | deleteVideoPlaylist, |
13 | doubleFollow, | 13 | doubleFollow, doVideosExistInMyPlaylist, |
14 | flushAndRunMultipleServers, | 14 | flushAndRunMultipleServers, |
15 | flushTests, | 15 | flushTests, |
16 | getAccountPlaylistsList, | 16 | getAccountPlaylistsList, |
@@ -41,6 +41,7 @@ import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/ | |||
41 | import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model' | 41 | import { VideoPlaylist } from '../../../../shared/models/videos/playlist/video-playlist.model' |
42 | import { Video } from '../../../../shared/models/videos' | 42 | import { Video } from '../../../../shared/models/videos' |
43 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' | 43 | import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' |
44 | import { VideoExistInPlaylist } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | ||
44 | 45 | ||
45 | const expect = chai.expect | 46 | const expect = chai.expect |
46 | 47 | ||
@@ -624,6 +625,45 @@ describe('Test video playlists', function () { | |||
624 | } | 625 | } |
625 | }) | 626 | }) |
626 | 627 | ||
628 | it('Should check videos existence in my playlist', async function () { | ||
629 | const videoIds = [ | ||
630 | servers[0].videos[0].id, | ||
631 | 42000, | ||
632 | servers[0].videos[3].id, | ||
633 | 43000, | ||
634 | servers[0].videos[4].id | ||
635 | ] | ||
636 | const res = await doVideosExistInMyPlaylist(servers[ 0 ].url, servers[ 0 ].accessToken, videoIds) | ||
637 | const obj = res.body as VideoExistInPlaylist | ||
638 | |||
639 | { | ||
640 | const elem = obj[servers[0].videos[0].id] | ||
641 | expect(elem).to.have.lengthOf(1) | ||
642 | expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id) | ||
643 | expect(elem[ 0 ].startTimestamp).to.equal(15) | ||
644 | expect(elem[ 0 ].stopTimestamp).to.equal(28) | ||
645 | } | ||
646 | |||
647 | { | ||
648 | const elem = obj[servers[0].videos[3].id] | ||
649 | expect(elem).to.have.lengthOf(1) | ||
650 | expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id) | ||
651 | expect(elem[ 0 ].startTimestamp).to.equal(1) | ||
652 | expect(elem[ 0 ].stopTimestamp).to.equal(35) | ||
653 | } | ||
654 | |||
655 | { | ||
656 | const elem = obj[servers[0].videos[4].id] | ||
657 | expect(elem).to.have.lengthOf(1) | ||
658 | expect(elem[ 0 ].playlistId).to.equal(playlistServer1Id) | ||
659 | expect(elem[ 0 ].startTimestamp).to.equal(45) | ||
660 | expect(elem[ 0 ].stopTimestamp).to.equal(null) | ||
661 | } | ||
662 | |||
663 | expect(obj[42000]).to.have.lengthOf(0) | ||
664 | expect(obj[43000]).to.have.lengthOf(0) | ||
665 | }) | ||
666 | |||
627 | it('Should delete some elements', async function () { | 667 | it('Should delete some elements', async function () { |
628 | this.timeout(30000) | 668 | this.timeout(30000) |
629 | 669 | ||