]>
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',
4 'action:notifier.notification.created',
6 'action:api.video.updated',
7 'action:api.video.deleted',
8 'action:api.video.uploaded',
9 'action:api.video.viewed',
11 'action:api.video-channel.created',
12 'action:api.video-channel.updated',
13 'action:api.video-channel.deleted',
15 'action:api.live-video.created',
17 'action:api.video-thread.created',
18 'action:api.video-comment-reply.created',
19 'action:api.video-comment.deleted',
21 'action:api.video-caption.created',
22 'action:api.video-caption.deleted',
24 'action:api.user.blocked',
25 'action:api.user.unblocked',
26 'action:api.user.registered',
27 'action:api.user.created',
28 'action:api.user.deleted',
29 'action:api.user.updated',
30 'action:api.user.oauth2-got-token',
32 'action:api.video-playlist-element.created'
35 for (const h
of actionHooks
) {
38 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
43 target: 'filter:api.videos.list.params',
44 handler: obj
=> addToCount(obj
)
48 target: 'filter:api.videos.list.result',
49 handler: obj
=> addToTotal(obj
)
53 target: 'filter:api.video-playlist.videos.list.params',
54 handler: obj
=> addToCount(obj
)
58 target: 'filter:api.video-playlist.videos.list.result',
59 handler: obj
=> addToTotal(obj
)
63 target: 'filter:api.accounts.videos.list.params',
64 handler: obj
=> addToCount(obj
)
68 target: 'filter:api.accounts.videos.list.result',
69 handler: obj
=> addToTotal(obj
, 2)
73 target: 'filter:api.video-channels.videos.list.params',
74 handler: obj
=> addToCount(obj
, 3)
78 target: 'filter:api.video-channels.videos.list.result',
79 handler: obj
=> addToTotal(obj
, 3)
83 target: 'filter:api.user.me.videos.list.params',
84 handler: obj
=> addToCount(obj
, 4)
88 target: 'filter:api.user.me.videos.list.result',
89 handler: obj
=> addToTotal(obj
, 4)
93 target: 'filter:api.user.me.subscription-videos.list.params',
94 handler: obj
=> addToCount(obj
)
98 target: 'filter:api.user.me.subscription-videos.list.result',
99 handler: obj
=> addToTotal(obj
, 4)
103 target: 'filter:api.video.get.result',
111 // ---------------------------------------------------------------------------
114 target: 'filter:api.video-channels.list.params',
115 handler: obj
=> addToCount(obj
, 1)
119 target: 'filter:api.video-channels.list.result',
120 handler: obj
=> addToTotal(obj
, 1)
124 target: 'filter:api.video-channel.get.result',
125 handler: channel
=> {
126 channel
.name
+= ' <3'
132 // ---------------------------------------------------------------------------
134 for (const hook
of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
137 handler: ({ accepted
}, { videoBody
, liveVideoBody
}) => {
138 if (!accepted
) return { accepted: false }
140 const name
= videoBody
144 if (name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
146 return { accepted: true }
152 target: 'filter:api.video.pre-import-url.accept.result',
153 handler: ({ accepted
}, { videoImportBody
}) => {
154 if (!accepted
) return { accepted: false }
155 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
157 return { accepted: true }
162 target: 'filter:api.video.pre-import-torrent.accept.result',
163 handler: ({ accepted
}, { videoImportBody
}) => {
164 if (!accepted
) return { accepted: false }
165 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
167 return { accepted: true }
172 target: 'filter:api.video.post-import-url.accept.result',
173 handler: ({ accepted
}, { video
}) => {
174 if (!accepted
) return { accepted: false }
175 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
177 return { accepted: true }
182 target: 'filter:api.video.post-import-torrent.accept.result',
183 handler: ({ accepted
}, { video
}) => {
184 if (!accepted
) return { accepted: false }
185 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
187 return { accepted: true }
191 // ---------------------------------------------------------------------------
194 target: 'filter:api.video-thread.create.accept.result',
195 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
199 target: 'filter:api.video-comment-reply.create.accept.result',
200 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
204 target: 'filter:activity-pub.remote-video-comment.create.accept.result',
205 handler: ({ accepted
}, { comment
}) => checkCommentBadWord(accepted
, comment
)
208 // ---------------------------------------------------------------------------
211 target: 'filter:api.video-threads.list.params',
212 handler: obj
=> addToCount(obj
)
216 target: 'filter:api.video-threads.list.result',
217 handler: obj
=> addToTotal(obj
)
221 target: 'filter:api.video-thread-comments.list.result',
223 obj
.data
.forEach(c
=> c
.text
+= ' <3')
230 target: 'filter:video.auto-blacklist.result',
231 handler: (blacklisted
, { video
}) => {
232 if (blacklisted
) return true
233 if (video
.name
.includes('please blacklist me')) return true
241 target: 'filter:api.user.signup.allowed.result',
242 handler: (result
, params
) => {
243 if (params
&& params
.body
&& params
.body
.email
&& params
.body
.email
.includes('jma 1')) {
244 return { allowed: false, errorMessage: 'No jma 1' }
252 target: 'filter:api.user.request-signup.allowed.result',
253 handler: (result
, params
) => {
254 if (params
&& params
.body
&& params
.body
.email
&& params
.body
.email
.includes('jma 2')) {
255 return { allowed: false, errorMessage: 'No jma 2' }
264 target: 'filter:api.download.torrent.allowed.result',
265 handler: (result
, params
) => {
266 if (params
&& params
.downloadName
.includes('bad torrent')) {
267 return { allowed: false, errorMessage: 'Liu Bei' }
275 target: 'filter:api.download.video.allowed.result',
276 handler: async (result
, params
) => {
277 const loggedInUser
= await peertubeHelpers
.user
.getAuthUser(params
.res
)
278 if (loggedInUser
) return { allowed: true }
280 if (params
&& !params
.streamingPlaylist
&& params
.video
.name
.includes('bad file')) {
281 return { allowed: false, errorMessage: 'Cao Cao' }
284 if (params
&& params
.streamingPlaylist
&& params
.video
.name
.includes('bad playlist file')) {
285 return { allowed: false, errorMessage: 'Sun Jian' }
293 target: 'filter:html.embed.video.allowed.result',
294 handler: (result
, params
) => {
303 target: 'filter:html.embed.video-playlist.allowed.result',
304 handler: (result
, params
) => {
313 target: 'filter:api.server.stats.get.result',
314 handler: (result
) => {
315 return { ...result
, customStats: 14 }
320 target: 'filter:job-queue.process.params',
321 handler: (object
, context
) => {
322 if (context
.type
!== 'video-studio-edition') return object
324 object
.data
.tasks
= [
339 target: 'filter:transcoding.auto.resolutions-to-transcode.result',
340 handler: (object
, context
) => {
341 if (context
.video
.name
.includes('transcode-filter')) {
349 // Upload/import/live attributes
350 for (const target
of [
351 'filter:api.video.upload.video-attribute.result',
352 'filter:api.video.import-url.video-attribute.result',
353 'filter:api.video.import-torrent.video-attribute.result',
354 'filter:api.video.live.video-attribute.result'
358 handler: (result
) => {
359 return { ...result
, description: result
.description
+ ' - ' + target
}
365 const filterHooks
= [
366 'filter:api.search.videos.local.list.params',
367 'filter:api.search.videos.local.list.result',
368 'filter:api.search.videos.index.list.params',
369 'filter:api.search.videos.index.list.result',
370 'filter:api.search.video-channels.local.list.params',
371 'filter:api.search.video-channels.local.list.result',
372 'filter:api.search.video-channels.index.list.params',
373 'filter:api.search.video-channels.index.list.result',
374 'filter:api.search.video-playlists.local.list.params',
375 'filter:api.search.video-playlists.local.list.result',
376 'filter:api.search.video-playlists.index.list.params',
377 'filter:api.search.video-playlists.index.list.result',
379 'filter:api.overviews.videos.list.params',
380 'filter:api.overviews.videos.list.result',
382 'filter:job-queue.process.params',
383 'filter:job-queue.process.result'
386 for (const h
of filterHooks
) {
390 peertubeHelpers
.logger
.debug('Run hook %s.', h
)
399 async
function unregister () {
408 // ############################################################################
410 function addToCount (obj
, amount
= 1) {
411 return Object
.assign({}, obj
, { count: obj
.count
+ amount
})
414 function addToTotal (result
, amount
= 1) {
417 total: result
.total
+ amount
421 function checkCommentBadWord (accepted
, commentBody
) {
422 if (!accepted
) return { accepted: false }
423 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
425 return { accepted: true }