aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2022-02-15 08:24:22 +0100
committerChocobozzz <chocobozzz@cpy.re>2022-02-28 10:56:37 +0100
commitc5ca7e1e0c735d1e658f9ef524a61d19f6a50fea (patch)
tree84c83e4ca9d7950ee2b5edad8b76dc7d5ab31031
parentc729caf6cc34630877a0e5a1bda1719384cd0c8a (diff)
downloadPeerTube-c5ca7e1e0c735d1e658f9ef524a61d19f6a50fea.tar.gz
PeerTube-c5ca7e1e0c735d1e658f9ef524a61d19f6a50fea.tar.zst
PeerTube-c5ca7e1e0c735d1e658f9ef524a61d19f6a50fea.zip
add filter:api.video-playlist.videos.list.* hooks
closes #4775
-rw-r--r--server/controllers/api/video-playlist.ts10
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js10
-rw-r--r--server/tests/plugins/filter-hooks.ts34
-rw-r--r--shared/models/plugins/server/server-hook.model.ts5
4 files changed, 56 insertions, 3 deletions
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index 795e14e73..ee6c73855 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -453,13 +453,19 @@ async function getVideoPlaylistVideos (req: express.Request, res: express.Respon
453 const user = res.locals.oauth ? res.locals.oauth.token.User : undefined 453 const user = res.locals.oauth ? res.locals.oauth.token.User : undefined
454 const server = await getServerActor() 454 const server = await getServerActor()
455 455
456 const resultList = await VideoPlaylistElementModel.listForApi({ 456 const apiOptions = await Hooks.wrapObject({
457 start: req.query.start, 457 start: req.query.start,
458 count: req.query.count, 458 count: req.query.count,
459 videoPlaylistId: videoPlaylistInstance.id, 459 videoPlaylistId: videoPlaylistInstance.id,
460 serverAccount: server.Account, 460 serverAccount: server.Account,
461 user 461 user
462 }) 462 }, 'filter:api.video-playlist.videos.list.params')
463
464 const resultList = await Hooks.wrapPromiseFun(
465 VideoPlaylistElementModel.listForApi,
466 apiOptions,
467 'filter:api.video-playlist.videos.list.result'
468 )
463 469
464 const options = { 470 const options = {
465 displayNSFW: buildNSFWFilter(res, req.query.nsfw), 471 displayNSFW: buildNSFWFilter(res, req.query.nsfw),
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 90951d611..7715ab6e8 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -45,6 +45,16 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
45 }) 45 })
46 46
47 registerHook({ 47 registerHook({
48 target: 'filter:api.video-playlist.videos.list.params',
49 handler: obj => addToCount(obj)
50 })
51
52 registerHook({
53 target: 'filter:api.video-playlist.videos.list.result',
54 handler: obj => addToTotal(obj)
55 })
56
57 registerHook({
48 target: 'filter:api.accounts.videos.list.params', 58 target: 'filter:api.accounts.videos.list.params',
49 handler: obj => addToCount(obj) 59 handler: obj => addToCount(obj)
50 }) 60 })
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 7adfc1277..e0f25ca26 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -22,6 +22,7 @@ describe('Test plugin filter hooks', function () {
22 let servers: PeerTubeServer[] 22 let servers: PeerTubeServer[]
23 let videoUUID: string 23 let videoUUID: string
24 let threadId: number 24 let threadId: number
25 let videoPlaylistUUID: string
25 26
26 before(async function () { 27 before(async function () {
27 this.timeout(60000) 28 this.timeout(60000)
@@ -33,9 +34,20 @@ describe('Test plugin filter hooks', function () {
33 34
34 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) 35 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
35 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) 36 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
37 {
38 ({ uuid: videoPlaylistUUID } = await servers[0].playlists.create({
39 attributes: {
40 displayName: 'my super playlist',
41 privacy: VideoPlaylistPrivacy.PUBLIC,
42 description: 'my super description',
43 videoChannelId: servers[0].store.channel.id
44 }
45 }))
46 }
36 47
37 for (let i = 0; i < 10; i++) { 48 for (let i = 0; i < 10; i++) {
38 await servers[0].videos.upload({ attributes: { name: 'default video ' + i } }) 49 const video = await servers[0].videos.upload({ attributes: { name: 'default video ' + i } })
50 await servers[0].playlists.addElement({ playlistId: videoPlaylistUUID, attributes: { videoId: video.id } })
39 } 51 }
40 52
41 const { data } = await servers[0].videos.list() 53 const { data } = await servers[0].videos.list()
@@ -69,6 +81,26 @@ describe('Test plugin filter hooks', function () {
69 expect(total).to.equal(11) 81 expect(total).to.equal(11)
70 }) 82 })
71 83
84 it('Should run filter:api.video-playlist.videos.list.params', async function () {
85 const { data } = await servers[0].playlists.listVideos({
86 count: 2,
87 playlistId: videoPlaylistUUID
88 })
89
90 // 1 plugin do +1 to the count parameter
91 expect(data).to.have.lengthOf(3)
92 })
93
94 it('Should run filter:api.video-playlist.videos.list.result', async function () {
95 const { total } = await servers[0].playlists.listVideos({
96 count: 0,
97 playlistId: videoPlaylistUUID
98 })
99
100 // Plugin do +1 to the total result
101 expect(total).to.equal(11)
102 })
103
72 it('Should run filter:api.accounts.videos.list.params', async function () { 104 it('Should run filter:api.accounts.videos.list.params', async function () {
73 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) 105 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
74 106
diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts
index bd2b27da5..e64c3bbbc 100644
--- a/shared/models/plugins/server/server-hook.model.ts
+++ b/shared/models/plugins/server/server-hook.model.ts
@@ -6,6 +6,11 @@ export const serverFilterHookObject = {
6 'filter:api.videos.list.params': true, 6 'filter:api.videos.list.params': true,
7 'filter:api.videos.list.result': true, 7 'filter:api.videos.list.result': true,
8 8
9 // Filter params/result used to list a video playlists videos
10 // for the REST API
11 'filter:api.video-playlist.videos.list.params': true,
12 'filter:api.video-playlist.videos.list.result': true,
13
9 // Filter params/result used to list account videos for the REST API 14 // Filter params/result used to list account videos for the REST API
10 'filter:api.accounts.videos.list.params': true, 15 'filter:api.accounts.videos.list.params': true,
11 'filter:api.accounts.videos.list.result': true, 16 'filter:api.accounts.videos.list.result': true,