aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlutangar <johan.dufour@gmail.com>2021-12-17 16:41:01 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-12-23 09:35:35 +0100
commit5e3d29ab218f2e7fcfb59f64777d901625dc5a49 (patch)
tree40c98f82ffd0ab12f5e986049f6ea6938a3d347d
parent293074ae7920040ede7e01d0aec4dabbeeb864ff (diff)
downloadPeerTube-5e3d29ab218f2e7fcfb59f64777d901625dc5a49.tar.gz
PeerTube-5e3d29ab218f2e7fcfb59f64777d901625dc5a49.tar.zst
PeerTube-5e3d29ab218f2e7fcfb59f64777d901625dc5a49.zip
Add video caption created and deleted hooks
-rw-r--r--server/controllers/api/videos/captions.ts5
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js3
-rw-r--r--server/tests/plugins/action-hooks.ts14
-rw-r--r--shared/models/plugins/server/server-hook.model.ts5
4 files changed, 27 insertions, 0 deletions
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts
index 2d2213327..c0e60848b 100644
--- a/server/controllers/api/videos/captions.ts
+++ b/server/controllers/api/videos/captions.ts
@@ -12,6 +12,7 @@ import { federateVideoIfNeeded } from '../../../lib/activitypub/videos'
12import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 12import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
13import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' 13import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators'
14import { VideoCaptionModel } from '../../../models/video/video-caption' 14import { VideoCaptionModel } from '../../../models/video/video-caption'
15import { Hooks } from '@server/lib/plugins/hooks'
15 16
16const reqVideoCaptionAdd = createReqFiles( 17const reqVideoCaptionAdd = createReqFiles(
17 [ 'captionfile' ], 18 [ 'captionfile' ],
@@ -75,6 +76,8 @@ async function addVideoCaption (req: express.Request, res: express.Response) {
75 await federateVideoIfNeeded(video, false, t) 76 await federateVideoIfNeeded(video, false, t)
76 }) 77 })
77 78
79 Hooks.runAction('action:api.video-caption.created', { caption: videoCaption, req, res })
80
78 return res.status(HttpStatusCode.NO_CONTENT_204).end() 81 return res.status(HttpStatusCode.NO_CONTENT_204).end()
79} 82}
80 83
@@ -91,5 +94,7 @@ async function deleteVideoCaption (req: express.Request, res: express.Response)
91 94
92 logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid) 95 logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid)
93 96
97 Hooks.runAction('action:api.video-caption.deleted', { caption: videoCaption, req, res })
98
94 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() 99 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
95} 100}
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 04e059848..90951d611 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -13,6 +13,9 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
13 'action:api.video-comment-reply.created', 13 'action:api.video-comment-reply.created',
14 'action:api.video-comment.deleted', 14 'action:api.video-comment.deleted',
15 15
16 'action:api.video-caption.created',
17 'action:api.video-caption.deleted',
18
16 'action:api.user.blocked', 19 'action:api.user.blocked',
17 'action:api.user.unblocked', 20 'action:api.user.unblocked',
18 'action:api.user.registered', 21 'action:api.user.registered',
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index 686926c17..8788a9644 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -103,6 +103,20 @@ describe('Test plugin action hooks', function () {
103 }) 103 })
104 }) 104 })
105 105
106 describe('Captions hooks', function () {
107 it('Should run action:api.video-caption.created', async function () {
108 await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })
109
110 await checkHook('action:api.video-caption.created')
111 })
112
113 it('Should run action:api.video-caption.deleted', async function () {
114 await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })
115
116 await checkHook('action:api.video-caption.deleted')
117 })
118 })
119
106 describe('Users hooks', function () { 120 describe('Users hooks', function () {
107 let userId: number 121 let userId: number
108 122
diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts
index 056c41a7f..bd2b27da5 100644
--- a/shared/models/plugins/server/server-hook.model.ts
+++ b/shared/models/plugins/server/server-hook.model.ts
@@ -115,6 +115,11 @@ export const serverActionHookObject = {
115 // Fired when a comment (thread or reply) is deleted 115 // Fired when a comment (thread or reply) is deleted
116 'action:api.video-comment.deleted': true, 116 'action:api.video-comment.deleted': true,
117 117
118 // Fired when a caption is created
119 'action:api.video-caption.created': true,
120 // Fired when a caption is deleted
121 'action:api.video-caption.deleted': true,
122
118 // Fired when a user is blocked (banned) 123 // Fired when a user is blocked (banned)
119 'action:api.user.blocked': true, 124 'action:api.user.blocked': true,
120 // Fired when a user is unblocked (unbanned) 125 // Fired when a user is unblocked (unbanned)