]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/fixtures/peertube-plugin-test/main.js
1 async
function register ({ registerHook
, registerSetting
, settingsManager
, storageManager
, peertubeHelpers
}) {
3 'action:application.listening',
5 'action:api.video.updated',
6 'action:api.video.deleted',
7 'action:api.video.uploaded',
8 'action:api.video.viewed',
10 'action:api.video-thread.created',
11 'action:api.video-comment-reply.created',
12 'action:api.video-comment.deleted'
15 for (const h
of actionHooks
) {
18 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
23 target: 'filter:api.videos.list.params',
24 handler: obj
=> addToCount(obj
)
28 target: 'filter:api.videos.list.result',
29 handler: obj
=> addToTotal(obj
)
33 target: 'filter:api.video.get.result',
42 target: 'filter:api.video.upload.accept.result',
43 handler: ({ accepted
}, { videoBody
}) => {
44 if (!accepted
) return { accepted: false }
45 if (videoBody
.name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
47 return { accepted: true }
52 target: 'filter:api.video-thread.create.accept.result',
53 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
57 target: 'filter:api.video-comment-reply.create.accept.result',
58 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
62 target: 'filter:api.video-threads.list.params',
63 handler: obj
=> addToCount(obj
)
67 target: 'filter:api.video-threads.list.result',
68 handler: obj
=> addToTotal(obj
)
72 target: 'filter:api.video-thread-comments.list.result',
74 obj
.data
.forEach(c
=> c
.text
+= ' <3')
81 target: 'filter:video.auto-blacklist.result',
82 handler: (blacklisted
, { video
}) => {
83 if (blacklisted
) return true
84 if (video
.name
.includes('please blacklist me')) return true
91 async
function unregister () {
100 // ############################################################################
102 function addToCount (obj
) {
103 return Object
.assign({}, obj
, { count: obj
.count
+ 1 })
106 function addToTotal (result
) {
109 total: result
.total
+ 1
113 function checkCommentBadWord (accepted
, commentBody
) {
114 if (!accepted
) return { accepted: false }
115 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
117 return { accepted: true }