diff options
author | kontrollanten <6680299+kontrollanten@users.noreply.github.com> | 2022-10-24 14:48:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-24 14:48:03 +0200 |
commit | 38a3ccc7f8ad0ea94362b58c732af7c387ab46be (patch) | |
tree | ccbd200c4b95d0fcfa56b7d5fc3c9490887187b1 /server | |
parent | 01a3c07a7913891d4830797403b3865d53f0af61 (diff) | |
download | PeerTube-38a3ccc7f8ad0ea94362b58c732af7c387ab46be.tar.gz PeerTube-38a3ccc7f8ad0ea94362b58c732af7c387ab46be.tar.zst PeerTube-38a3ccc7f8ad0ea94362b58c732af7c387ab46be.zip |
feat: show contained playlists under My videos (#5125)
* feat: show contained playlists under My videos
closes #4769
* refactor(server): remove unused types
* fixes after code review
* fix(client/video-miniature): add to playlist
* fix(server/user/me): shortUUID response
* Revert "fix(client/video-miniature): add to playlist"
This reverts commit f1a0412391c7e2370b87df2594c9fe3f39a40ddc.
* fix(client/PlaylistService): caching
* Revert "fix(server/user/me): shortUUID response"
This reverts commit e3f1ee4e335739b895bced938540c003df24af73.
* Fix fetching playlists
Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/users/my-video-playlists.ts | 5 | ||||
-rw-r--r-- | server/models/video/video-playlist.ts | 6 | ||||
-rw-r--r-- | server/tests/api/videos/video-playlists.ts | 12 | ||||
-rw-r--r-- | server/types/models/video/video-playlist.ts | 12 |
4 files changed, 24 insertions, 11 deletions
diff --git a/server/controllers/api/users/my-video-playlists.ts b/server/controllers/api/users/my-video-playlists.ts index f55ea2ec4..715717610 100644 --- a/server/controllers/api/users/my-video-playlists.ts +++ b/server/controllers/api/users/my-video-playlists.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import { uuidToShort } from '@shared/extra-utils' | ||
1 | import express from 'express' | 2 | import express from 'express' |
2 | import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' | 3 | import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model' |
3 | import { asyncMiddleware, authenticate } from '../../../middlewares' | 4 | import { asyncMiddleware, authenticate } from '../../../middlewares' |
@@ -24,7 +25,7 @@ async function doVideosInPlaylistExist (req: express.Request, res: express.Respo | |||
24 | const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) | 25 | const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10)) |
25 | const user = res.locals.oauth.token.User | 26 | const user = res.locals.oauth.token.User |
26 | 27 | ||
27 | const results = await VideoPlaylistModel.listPlaylistIdsOf(user.Account.id, videoIds) | 28 | const results = await VideoPlaylistModel.listPlaylistSummariesOf(user.Account.id, videoIds) |
28 | 29 | ||
29 | const existObject: VideosExistInPlaylists = {} | 30 | const existObject: VideosExistInPlaylists = {} |
30 | 31 | ||
@@ -37,6 +38,8 @@ async function doVideosInPlaylistExist (req: express.Request, res: express.Respo | |||
37 | existObject[element.videoId].push({ | 38 | existObject[element.videoId].push({ |
38 | playlistElementId: element.id, | 39 | playlistElementId: element.id, |
39 | playlistId: result.id, | 40 | playlistId: result.id, |
41 | playlistDisplayName: result.name, | ||
42 | playlistShortUUID: uuidToShort(result.uuid), | ||
40 | startTimestamp: element.startTimestamp, | 43 | startTimestamp: element.startTimestamp, |
41 | stopTimestamp: element.stopTimestamp | 44 | stopTimestamp: element.stopTimestamp |
42 | }) | 45 | }) |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 81ce3dc9e..8bbe54c49 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -49,7 +49,7 @@ import { | |||
49 | MVideoPlaylistFormattable, | 49 | MVideoPlaylistFormattable, |
50 | MVideoPlaylistFull, | 50 | MVideoPlaylistFull, |
51 | MVideoPlaylistFullSummary, | 51 | MVideoPlaylistFullSummary, |
52 | MVideoPlaylistIdWithElements | 52 | MVideoPlaylistSummaryWithElements |
53 | } from '../../types/models/video/video-playlist' | 53 | } from '../../types/models/video/video-playlist' |
54 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account' | 54 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions } from '../account/account' |
55 | import { ActorModel } from '../actor/actor' | 55 | import { ActorModel } from '../actor/actor' |
@@ -470,9 +470,9 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
470 | })) | 470 | })) |
471 | } | 471 | } |
472 | 472 | ||
473 | static listPlaylistIdsOf (accountId: number, videoIds: number[]): Promise<MVideoPlaylistIdWithElements[]> { | 473 | static listPlaylistSummariesOf (accountId: number, videoIds: number[]): Promise<MVideoPlaylistSummaryWithElements[]> { |
474 | const query = { | 474 | const query = { |
475 | attributes: [ 'id' ], | 475 | attributes: [ 'id', 'name', 'uuid' ], |
476 | where: { | 476 | where: { |
477 | ownerAccountId: accountId | 477 | ownerAccountId: accountId |
478 | }, | 478 | }, |
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 9d223de48..a3de73ba5 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts | |||
@@ -23,6 +23,7 @@ import { | |||
23 | setDefaultVideoChannel, | 23 | setDefaultVideoChannel, |
24 | waitJobs | 24 | waitJobs |
25 | } from '@shared/server-commands' | 25 | } from '@shared/server-commands' |
26 | import { uuidToShort } from '@shared/extra-utils' | ||
26 | 27 | ||
27 | async function checkPlaylistElementType ( | 28 | async function checkPlaylistElementType ( |
28 | servers: PeerTubeServer[], | 29 | servers: PeerTubeServer[], |
@@ -56,6 +57,7 @@ describe('Test video playlists', function () { | |||
56 | let playlistServer2UUID2: string | 57 | let playlistServer2UUID2: string |
57 | 58 | ||
58 | let playlistServer1Id: number | 59 | let playlistServer1Id: number |
60 | let playlistServer1DisplayName: string | ||
59 | let playlistServer1UUID: string | 61 | let playlistServer1UUID: string |
60 | let playlistServer1UUID2: string | 62 | let playlistServer1UUID2: string |
61 | 63 | ||
@@ -489,15 +491,17 @@ describe('Test video playlists', function () { | |||
489 | return commands[0].addElement({ playlistId: playlistServer1Id, attributes }) | 491 | return commands[0].addElement({ playlistId: playlistServer1Id, attributes }) |
490 | } | 492 | } |
491 | 493 | ||
494 | const playlistDisplayName = 'playlist 4' | ||
492 | const playlist = await commands[0].create({ | 495 | const playlist = await commands[0].create({ |
493 | attributes: { | 496 | attributes: { |
494 | displayName: 'playlist 4', | 497 | displayName: playlistDisplayName, |
495 | privacy: VideoPlaylistPrivacy.PUBLIC, | 498 | privacy: VideoPlaylistPrivacy.PUBLIC, |
496 | videoChannelId: servers[0].store.channel.id | 499 | videoChannelId: servers[0].store.channel.id |
497 | } | 500 | } |
498 | }) | 501 | }) |
499 | 502 | ||
500 | playlistServer1Id = playlist.id | 503 | playlistServer1Id = playlist.id |
504 | playlistServer1DisplayName = playlistDisplayName | ||
501 | playlistServer1UUID = playlist.uuid | 505 | playlistServer1UUID = playlist.uuid |
502 | 506 | ||
503 | await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) | 507 | await addVideo({ videoId: servers[0].store.videos[0].uuid, startTimestamp: 15, stopTimestamp: 28 }) |
@@ -908,6 +912,8 @@ describe('Test video playlists', function () { | |||
908 | const elem = obj[servers[0].store.videos[0].id] | 912 | const elem = obj[servers[0].store.videos[0].id] |
909 | expect(elem).to.have.lengthOf(1) | 913 | expect(elem).to.have.lengthOf(1) |
910 | expect(elem[0].playlistElementId).to.exist | 914 | expect(elem[0].playlistElementId).to.exist |
915 | expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName) | ||
916 | expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID)) | ||
911 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | 917 | expect(elem[0].playlistId).to.equal(playlistServer1Id) |
912 | expect(elem[0].startTimestamp).to.equal(15) | 918 | expect(elem[0].startTimestamp).to.equal(15) |
913 | expect(elem[0].stopTimestamp).to.equal(28) | 919 | expect(elem[0].stopTimestamp).to.equal(28) |
@@ -917,6 +923,8 @@ describe('Test video playlists', function () { | |||
917 | const elem = obj[servers[0].store.videos[3].id] | 923 | const elem = obj[servers[0].store.videos[3].id] |
918 | expect(elem).to.have.lengthOf(1) | 924 | expect(elem).to.have.lengthOf(1) |
919 | expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) | 925 | expect(elem[0].playlistElementId).to.equal(playlistElementServer1Video4) |
926 | expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName) | ||
927 | expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID)) | ||
920 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | 928 | expect(elem[0].playlistId).to.equal(playlistServer1Id) |
921 | expect(elem[0].startTimestamp).to.equal(1) | 929 | expect(elem[0].startTimestamp).to.equal(1) |
922 | expect(elem[0].stopTimestamp).to.equal(35) | 930 | expect(elem[0].stopTimestamp).to.equal(35) |
@@ -926,6 +934,8 @@ describe('Test video playlists', function () { | |||
926 | const elem = obj[servers[0].store.videos[4].id] | 934 | const elem = obj[servers[0].store.videos[4].id] |
927 | expect(elem).to.have.lengthOf(1) | 935 | expect(elem).to.have.lengthOf(1) |
928 | expect(elem[0].playlistId).to.equal(playlistServer1Id) | 936 | expect(elem[0].playlistId).to.equal(playlistServer1Id) |
937 | expect(elem[0].playlistDisplayName).to.equal(playlistServer1DisplayName) | ||
938 | expect(elem[0].playlistShortUUID).to.equal(uuidToShort(playlistServer1UUID)) | ||
929 | expect(elem[0].startTimestamp).to.equal(45) | 939 | expect(elem[0].startTimestamp).to.equal(45) |
930 | expect(elem[0].stopTimestamp).to.equal(null) | 940 | expect(elem[0].stopTimestamp).to.equal(null) |
931 | } | 941 | } |
diff --git a/server/types/models/video/video-playlist.ts b/server/types/models/video/video-playlist.ts index 33fe5416a..40f0dfc14 100644 --- a/server/types/models/video/video-playlist.ts +++ b/server/types/models/video/video-playlist.ts | |||
@@ -14,6 +14,10 @@ export type MVideoPlaylist = Omit<VideoPlaylistModel, 'OwnerAccount' | 'VideoCha | |||
14 | // ############################################################################ | 14 | // ############################################################################ |
15 | 15 | ||
16 | export type MVideoPlaylistId = Pick<MVideoPlaylist, 'id'> | 16 | export type MVideoPlaylistId = Pick<MVideoPlaylist, 'id'> |
17 | export type MVideoPlaylistSummary = | ||
18 | Pick<MVideoPlaylist, 'id'> & | ||
19 | Pick<MVideoPlaylist, 'name'> & | ||
20 | Pick<MVideoPlaylist, 'uuid'> | ||
17 | export type MVideoPlaylistPrivacy = Pick<MVideoPlaylist, 'privacy'> | 21 | export type MVideoPlaylistPrivacy = Pick<MVideoPlaylist, 'privacy'> |
18 | export type MVideoPlaylistUUID = Pick<MVideoPlaylist, 'uuid'> | 22 | export type MVideoPlaylistUUID = Pick<MVideoPlaylist, 'uuid'> |
19 | export type MVideoPlaylistVideosLength = MVideoPlaylist & { videosLength?: number } | 23 | export type MVideoPlaylistVideosLength = MVideoPlaylist & { videosLength?: number } |
@@ -22,12 +26,8 @@ export type MVideoPlaylistVideosLength = MVideoPlaylist & { videosLength?: numbe | |||
22 | 26 | ||
23 | // With elements | 27 | // With elements |
24 | 28 | ||
25 | export type MVideoPlaylistWithElements = | 29 | export type MVideoPlaylistSummaryWithElements = |
26 | MVideoPlaylist & | 30 | MVideoPlaylistSummary & |
27 | Use<'VideoPlaylistElements', MVideoPlaylistElementLight[]> | ||
28 | |||
29 | export type MVideoPlaylistIdWithElements = | ||
30 | MVideoPlaylistId & | ||
31 | Use<'VideoPlaylistElements', MVideoPlaylistElementLight[]> | 31 | Use<'VideoPlaylistElements', MVideoPlaylistElementLight[]> |
32 | 32 | ||
33 | // ############################################################################ | 33 | // ############################################################################ |