aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2021-06-28 09:22:15 +0200
committerGitHub <noreply@github.com>2021-06-28 09:22:15 +0200
commite2e0b645cdac3c705b1988fbb0eff723ad5e885d (patch)
tree0e8d7d5d7bfbd5815f89e1444b693d5a7662a6a7 /server
parent3e84ae325088320c49dd07de2d3a0d020151002e (diff)
downloadPeerTube-e2e0b645cdac3c705b1988fbb0eff723ad5e885d.tar.gz
PeerTube-e2e0b645cdac3c705b1988fbb0eff723ad5e885d.tar.zst
PeerTube-e2e0b645cdac3c705b1988fbb0eff723ad5e885d.zip
Add video-playlist-element.created hook (#4196)
* add playlists.videos.list.params/results hooks closes #4192 * Revert "add playlists.videos.list.params/results hooks" This reverts commit ebd822ca0b769d88dbc5ae0062b286238cbced92. * add video-playlist-element.created hook closes #4192 * test: add playlist-element.created * Fix tests Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/video-playlist.ts3
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js4
-rw-r--r--server/tests/plugins/action-hooks.ts40
3 files changed, 45 insertions, 2 deletions
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index c25aed20b..5c4aa50ac 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -43,6 +43,7 @@ import {
43import { AccountModel } from '../../models/account/account' 43import { AccountModel } from '../../models/account/account'
44import { VideoPlaylistModel } from '../../models/video/video-playlist' 44import { VideoPlaylistModel } from '../../models/video/video-playlist'
45import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' 45import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
46import { Hooks } from '@server/lib/plugins/hooks'
46 47
47const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) 48const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
48 49
@@ -330,6 +331,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
330 331
331 logger.info('Video added in playlist %s at position %d.', videoPlaylist.uuid, playlistElement.position) 332 logger.info('Video added in playlist %s at position %d.', videoPlaylist.uuid, playlistElement.position)
332 333
334 Hooks.runAction('action:api.video-playlist-element.created', { playlistElement })
335
333 return res.json({ 336 return res.json({
334 videoPlaylistElement: { 337 videoPlaylistElement: {
335 id: playlistElement.id 338 id: playlistElement.id
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 5e922ad1f..f8e6f0b98 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -19,7 +19,9 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
19 'action:api.user.created', 19 'action:api.user.created',
20 'action:api.user.deleted', 20 'action:api.user.deleted',
21 'action:api.user.updated', 21 'action:api.user.updated',
22 'action:api.user.oauth2-got-token' 22 'action:api.user.oauth2-got-token',
23
24 'action:api.video-playlist-element.created'
23 ] 25 ]
24 26
25 for (const h of actionHooks) { 27 for (const h of actionHooks) {
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index ac9f2cea5..0f57ef7fe 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -1,13 +1,15 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { ServerHookName, VideoPrivacy } from '@shared/models' 4import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
5import { 5import {
6 addVideoCommentReply, 6 addVideoCommentReply,
7 addVideoCommentThread, 7 addVideoCommentThread,
8 addVideoInPlaylist,
8 blockUser, 9 blockUser,
9 createLive, 10 createLive,
10 createUser, 11 createUser,
12 createVideoPlaylist,
11 deleteVideoComment, 13 deleteVideoComment,
12 getPluginTestPath, 14 getPluginTestPath,
13 installPlugin, 15 installPlugin,
@@ -69,6 +71,7 @@ describe('Test plugin action hooks', function () {
69 }) 71 })
70 72
71 describe('Videos hooks', function () { 73 describe('Videos hooks', function () {
74
72 it('Should run action:api.video.uploaded', async function () { 75 it('Should run action:api.video.uploaded', async function () {
73 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 76 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
74 videoUUID = res.body.video.uuid 77 videoUUID = res.body.video.uuid
@@ -177,6 +180,41 @@ describe('Test plugin action hooks', function () {
177 }) 180 })
178 }) 181 })
179 182
183 describe('Playlist hooks', function () {
184 let playlistId: number
185 let videoId: number
186
187 before(async function () {
188 {
189 const res = await createVideoPlaylist({
190 url: servers[0].url,
191 token: servers[0].accessToken,
192 playlistAttrs: {
193 displayName: 'My playlist',
194 privacy: VideoPlaylistPrivacy.PRIVATE
195 }
196 })
197 playlistId = res.body.videoPlaylist.id
198 }
199
200 {
201 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
202 videoId = res.body.video.id
203 }
204 })
205
206 it('Should run action:api.video-playlist-element.created', async function () {
207 await addVideoInPlaylist({
208 url: servers[0].url,
209 token: servers[0].accessToken,
210 playlistId,
211 elementAttrs: { videoId }
212 })
213
214 await checkHook('action:api.video-playlist-element.created')
215 })
216 })
217
180 after(async function () { 218 after(async function () {
181 await cleanupTests(servers) 219 await cleanupTests(servers)
182 }) 220 })