ActivityPub-federated video streaming platform using P2P directly in your web browser
Add video caption created and deleted hooks
lutangar5e3d29ab218f
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.tsindex 2d2213327c..c0e60848b2 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'import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators'import { VideoCaptionModel } from '../../../models/video/video-caption'+import { Hooks } from '@server/lib/plugins/hooks'const reqVideoCaptionAdd = createReqFiles([ 'captionfile' ],@@ -75,6 +76,8 @@ async function addVideoCaption (req: express.Request, res: express.Response) {await federateVideoIfNeeded(video, false, t)})+ Hooks.runAction('action:api.video-caption.created', { caption: videoCaption, req, res })+return res.status(HttpStatusCode.NO_CONTENT_204).end()}@@ -91,5 +94,7 @@ async function deleteVideoCaption (req: express.Request, res: express.Response)logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid)+ Hooks.runAction('action:api.video-caption.deleted', { caption: videoCaption, req, res })+return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()}diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.jsindex 04e0598486..90951d6110 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'action:api.video-comment-reply.created','action:api.video-comment.deleted',+ 'action:api.video-caption.created',+ 'action:api.video-caption.deleted',+'action:api.user.blocked','action:api.user.unblocked','action:api.user.registered',diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.tsindex 686926c170..8788a96448 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 () {})})+ describe('Captions hooks', function () {+ it('Should run action:api.video-caption.created', async function () {+ await servers[0].captions.add({ videoId: videoUUID, language: 'en', fixture: 'subtitle-good.srt' })++ await checkHook('action:api.video-caption.created')+ })++ it('Should run action:api.video-caption.deleted', async function () {+ await servers[0].captions.delete({ videoId: videoUUID, language: 'en' })++ await checkHook('action:api.video-caption.deleted')+ })+ })+describe('Users hooks', function () {let userId: numberdiff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.tsindex 056c41a7f7..bd2b27da5a 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 = {// Fired when a comment (thread or reply) is deleted'action:api.video-comment.deleted': true,+ // Fired when a caption is created+ 'action:api.video-caption.created': true,+ // Fired when a caption is deleted+ 'action:api.video-caption.deleted': true,+// Fired when a user is blocked (banned)'action:api.user.blocked': true,// Fired when a user is unblocked (unbanned)