]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add video-playlist-element.created hook (#4196)
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>
Mon, 28 Jun 2021 07:22:15 +0000 (09:22 +0200)
committerGitHub <noreply@github.com>
Mon, 28 Jun 2021 07:22:15 +0000 (09:22 +0200)
* 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>
server/controllers/api/video-playlist.ts
server/tests/fixtures/peertube-plugin-test/main.js
server/tests/plugins/action-hooks.ts
shared/models/plugins/server/server-hook.model.ts

index c25aed20b4e530bcf20570ec8926d598597722b9..5c4aa50ace938cb2de63a1ac9c1a60903da657c3 100644 (file)
@@ -43,6 +43,7 @@ import {
 import { AccountModel } from '../../models/account/account'
 import { VideoPlaylistModel } from '../../models/video/video-playlist'
 import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
+import { Hooks } from '@server/lib/plugins/hooks'
 
 const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
 
@@ -330,6 +331,8 @@ async function addVideoInPlaylist (req: express.Request, res: express.Response)
 
   logger.info('Video added in playlist %s at position %d.', videoPlaylist.uuid, playlistElement.position)
 
+  Hooks.runAction('action:api.video-playlist-element.created', { playlistElement })
+
   return res.json({
     videoPlaylistElement: {
       id: playlistElement.id
index 5e922ad1f641121ec885a40d75f557c1109cd9df..f8e6f0b98129406ce82742b57abd0fc684afb2ff 100644 (file)
@@ -19,7 +19,9 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
     'action:api.user.created',
     'action:api.user.deleted',
     'action:api.user.updated',
-    'action:api.user.oauth2-got-token'
+    'action:api.user.oauth2-got-token',
+
+    'action:api.video-playlist-element.created'
   ]
 
   for (const h of actionHooks) {
index ac9f2cea5b97075826550e01b4338b9ec04ab832..0f57ef7fee486876d991b74e239c165f71f605cd 100644 (file)
@@ -1,13 +1,15 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
-import { ServerHookName, VideoPrivacy } from '@shared/models'
+import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
 import {
   addVideoCommentReply,
   addVideoCommentThread,
+  addVideoInPlaylist,
   blockUser,
   createLive,
   createUser,
+  createVideoPlaylist,
   deleteVideoComment,
   getPluginTestPath,
   installPlugin,
@@ -69,6 +71,7 @@ describe('Test plugin action hooks', function () {
   })
 
   describe('Videos hooks', function () {
+
     it('Should run action:api.video.uploaded', async function () {
       const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
       videoUUID = res.body.video.uuid
@@ -177,6 +180,41 @@ describe('Test plugin action hooks', function () {
     })
   })
 
+  describe('Playlist hooks', function () {
+    let playlistId: number
+    let videoId: number
+
+    before(async function () {
+      {
+        const res = await createVideoPlaylist({
+          url: servers[0].url,
+          token: servers[0].accessToken,
+          playlistAttrs: {
+            displayName: 'My playlist',
+            privacy: VideoPlaylistPrivacy.PRIVATE
+          }
+        })
+        playlistId = res.body.videoPlaylist.id
+      }
+
+      {
+        const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' })
+        videoId = res.body.video.id
+      }
+    })
+
+    it('Should run action:api.video-playlist-element.created', async function () {
+      await addVideoInPlaylist({
+        url: servers[0].url,
+        token: servers[0].accessToken,
+        playlistId,
+        elementAttrs: { videoId }
+      })
+
+      await checkHook('action:api.video-playlist-element.created')
+    })
+  })
+
   after(async function () {
     await cleanupTests(servers)
   })
index dae243dbf5d563563e2b8f6a911a789926d074d5..5f29534b585a9a784797318a91a38d1365b106ef 100644 (file)
@@ -114,7 +114,10 @@ export const serverActionHookObject = {
   'action:api.user.updated': true,
 
   // Fired when a user got a new oauth2 token
-  'action:api.user.oauth2-got-token': true
+  'action:api.user.oauth2-got-token': true,
+
+  // Fired when a video is added to a playlist
+  'action:api.video-playlist-element.created': true
 }
 
 export type ServerActionHookName = keyof typeof serverActionHookObject