]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/fixtures/peertube-plugin-test/main.js
Add hook filters tests
[github/Chocobozzz/PeerTube.git] / server / tests / fixtures / peertube-plugin-test / main.js
1 async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
2 const actionHooks = [
3 'action:application.listening',
4
5 'action:api.video.updated',
6 'action:api.video.deleted',
7 'action:api.video.uploaded',
8 'action:api.video.viewed',
9
10 'action:api.video-thread.created',
11 'action:api.video-comment-reply.created',
12 'action:api.video-comment.deleted'
13 ]
14
15 for (const h of actionHooks) {
16 registerHook({
17 target: h,
18 handler: () => peertubeHelpers.logger.debug('Run hook %s.', h)
19 })
20 }
21
22 registerHook({
23 target: 'filter:api.videos.list.params',
24 handler: obj => addToCount(obj)
25 })
26
27 registerHook({
28 target: 'filter:api.videos.list.result',
29 handler: obj => ({ data: obj.data, total: obj.total + 1 })
30 })
31
32 registerHook({
33 target: 'filter:api.video.get.result',
34 handler: video => {
35 video.name += ' <3'
36
37 return video
38 }
39 })
40
41 registerHook({
42 target: 'filter:api.video.upload.accept.result',
43 handler: ({ accepted }, { videoBody }) => {
44 if (accepted !== false) return { accepted: true }
45 if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
46
47 return { accepted: true }
48 }
49 })
50 }
51
52 async function unregister () {
53 return
54 }
55
56 module.exports = {
57 register,
58 unregister
59 }
60
61 // ############################################################################
62
63 function addToCount (obj) {
64 return Object.assign({}, obj, { count: obj.count + 1 })
65 }