]>
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.live-video.created',
12 'action:api.video-thread.created',
13 'action:api.video-comment-reply.created',
14 'action:api.video-comment.deleted',
16 'action:api.user.blocked',
17 'action:api.user.unblocked',
18 'action:api.user.registered',
19 'action:api.user.created',
20 'action:api.user.deleted',
21 'action:api.user.updated',
22 'action:api.user.oauth2-got-token'
25 for (const h
of actionHooks
) {
28 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
33 target: 'filter:api.videos.list.params',
34 handler: obj
=> addToCount(obj
)
38 target: 'filter:api.videos.list.result',
39 handler: obj
=> addToTotal(obj
)
43 target: 'filter:api.accounts.videos.list.params',
44 handler: obj
=> addToCount(obj
)
48 target: 'filter:api.accounts.videos.list.result',
49 handler: obj
=> addToTotal(obj
, 2)
53 target: 'filter:api.video-channels.videos.list.params',
54 handler: obj
=> addToCount(obj
, 3)
58 target: 'filter:api.video-channels.videos.list.result',
59 handler: obj
=> addToTotal(obj
, 3)
63 target: 'filter:api.user.me.videos.list.params',
64 handler: obj
=> addToCount(obj
, 4)
68 target: 'filter:api.user.me.videos.list.result',
69 handler: obj
=> addToTotal(obj
, 4)
73 target: 'filter:api.video.get.result',
81 for (const hook
of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
84 handler: ({ accepted
}, { videoBody
, liveVideoBody
}) => {
85 if (!accepted
) return { accepted: false }
87 const name
= videoBody
91 if (name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
93 return { accepted: true }
99 target: 'filter:api.video.pre-import-url.accept.result',
100 handler: ({ accepted
}, { videoImportBody
}) => {
101 if (!accepted
) return { accepted: false }
102 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
104 return { accepted: true }
109 target: 'filter:api.video.pre-import-torrent.accept.result',
110 handler: ({ accepted
}, { videoImportBody
}) => {
111 if (!accepted
) return { accepted: false }
112 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
114 return { accepted: true }
119 target: 'filter:api.video.post-import-url.accept.result',
120 handler: ({ accepted
}, { video
}) => {
121 if (!accepted
) return { accepted: false }
122 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
124 return { accepted: true }
129 target: 'filter:api.video.post-import-torrent.accept.result',
130 handler: ({ accepted
}, { video
}) => {
131 if (!accepted
) return { accepted: false }
132 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
134 return { accepted: true }
139 target: 'filter:api.video-thread.create.accept.result',
140 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
144 target: 'filter:api.video-comment-reply.create.accept.result',
145 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
149 target: 'filter:api.video-threads.list.params',
150 handler: obj
=> addToCount(obj
)
154 target: 'filter:api.video-threads.list.result',
155 handler: obj
=> addToTotal(obj
)
159 target: 'filter:api.video-thread-comments.list.result',
161 obj
.data
.forEach(c
=> c
.text
+= ' <3')
168 target: 'filter:video.auto-blacklist.result',
169 handler: (blacklisted
, { video
}) => {
170 if (blacklisted
) return true
171 if (video
.name
.includes('please blacklist me')) return true
178 target: 'filter:api.user.signup.allowed.result',
179 handler: (result
, params
) => {
180 if (params
&& params
.body
.email
.includes('jma')) {
181 return { allowed: false, errorMessage: 'No jma' }
189 async
function unregister () {
198 // ############################################################################
200 function addToCount (obj
, amount
= 1) {
201 return Object
.assign({}, obj
, { count: obj
.count
+ amount
})
204 function addToTotal (result
, amount
= 1) {
207 total: result
.total
+ amount
211 function checkCommentBadWord (accepted
, commentBody
) {
212 if (!accepted
) return { accepted: false }
213 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
215 return { accepted: true }