]>
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',
14 'action:api.user.blocked',
15 'action:api.user.unblocked',
16 'action:api.user.registered',
17 'action:api.user.created',
18 'action:api.user.deleted',
19 'action:api.user.updated',
20 'action:api.user.oauth2-got-token'
23 for (const h
of actionHooks
) {
26 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
31 target: 'filter:api.videos.list.params',
32 handler: obj
=> addToCount(obj
)
36 target: 'filter:api.videos.list.result',
37 handler: obj
=> addToTotal(obj
)
41 target: 'filter:api.video.get.result',
50 target: 'filter:api.video.upload.accept.result',
51 handler: ({ accepted
}, { videoBody
}) => {
52 if (!accepted
) return { accepted: false }
53 if (videoBody
.name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
55 return { accepted: true }
60 target: 'filter:api.video-thread.create.accept.result',
61 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
65 target: 'filter:api.video-comment-reply.create.accept.result',
66 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
70 target: 'filter:api.video-threads.list.params',
71 handler: obj
=> addToCount(obj
)
75 target: 'filter:api.video-threads.list.result',
76 handler: obj
=> addToTotal(obj
)
80 target: 'filter:api.video-thread-comments.list.result',
82 obj
.data
.forEach(c
=> c
.text
+= ' <3')
89 target: 'filter:video.auto-blacklist.result',
90 handler: (blacklisted
, { video
}) => {
91 if (blacklisted
) return true
92 if (video
.name
.includes('please blacklist me')) return true
99 target: 'filter:api.user.signup.allowed.result',
100 handler: (result
, params
) => {
101 if (params
&& params
.body
.email
.includes('jma')) {
102 return { allowed: false, errorMessage: 'No jma' }
110 async
function unregister () {
119 // ############################################################################
121 function addToCount (obj
) {
122 return Object
.assign({}, obj
, { count: obj
.count
+ 1 })
125 function addToTotal (result
) {
128 total: result
.total
+ 1
132 function checkCommentBadWord (accepted
, commentBody
) {
133 if (!accepted
) return { accepted: false }
134 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
136 return { accepted: true }