]>
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
}) {
4 'action:application.listening',
5 'action:notifier.notification.created',
7 'action:api.video.updated',
8 'action:api.video.deleted',
9 'action:api.video.uploaded',
10 'action:api.video.viewed',
12 'action:api.video-channel.created',
13 'action:api.video-channel.updated',
14 'action:api.video-channel.deleted',
16 'action:api.live-video.created',
18 'action:api.video-thread.created',
19 'action:api.video-comment-reply.created',
20 'action:api.video-comment.deleted',
22 'action:api.video-caption.created',
23 'action:api.video-caption.deleted',
25 'action:api.user.blocked',
26 'action:api.user.unblocked',
27 'action:api.user.registered',
28 'action:api.user.created',
29 'action:api.user.deleted',
30 'action:api.user.updated',
31 'action:api.user.oauth2-got-token',
33 'action:api.video-playlist-element.created'
36 for (const h
of actionHooks
) {
39 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
43 for (const h
of [ 'action:activity-pub.remote-video.created', 'action:activity-pub.remote-video.updated' ]) {
46 handler: ({ video
, videoAPObject
}) => {
47 peertubeHelpers
.logger
.debug('Run hook %s - AP %s - video %s.', h
, video
.name
, videoAPObject
.name
)
54 target: 'filter:api.videos.list.params',
55 handler: obj
=> addToCount(obj
)
59 target: 'filter:api.videos.list.result',
60 handler: obj
=> addToTotal(obj
)
64 target: 'filter:api.video-playlist.videos.list.params',
65 handler: obj
=> addToCount(obj
)
69 target: 'filter:api.video-playlist.videos.list.result',
70 handler: obj
=> addToTotal(obj
)
74 target: 'filter:api.accounts.videos.list.params',
75 handler: obj
=> addToCount(obj
)
79 target: 'filter:api.accounts.videos.list.result',
80 handler: obj
=> addToTotal(obj
, 2)
84 target: 'filter:api.video-channels.videos.list.params',
85 handler: obj
=> addToCount(obj
, 3)
89 target: 'filter:api.video-channels.videos.list.result',
90 handler: obj
=> addToTotal(obj
, 3)
94 target: 'filter:api.user.me.videos.list.params',
95 handler: obj
=> addToCount(obj
, 4)
99 target: 'filter:api.user.me.videos.list.result',
100 handler: obj
=> addToTotal(obj
, 4)
104 target: 'filter:api.user.me.subscription-videos.list.params',
105 handler: obj
=> Object
.assign({}, obj
, { count: 1 })
109 target: 'filter:api.user.me.subscription-videos.list.result',
110 handler: obj
=> addToTotal(obj
, 4)
114 target: 'filter:api.video.get.result',
122 // ---------------------------------------------------------------------------
125 target: 'filter:api.video-channels.list.params',
126 handler: obj
=> addToCount(obj
, 1)
130 target: 'filter:api.video-channels.list.result',
131 handler: obj
=> addToTotal(obj
, 1)
135 target: 'filter:api.video-channel.get.result',
136 handler: channel
=> {
137 channel
.name
+= ' <3'
143 // ---------------------------------------------------------------------------
145 for (const hook
of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
148 handler: ({ accepted
}, { videoBody
, liveVideoBody
}) => {
149 if (!accepted
) return { accepted: false }
151 const name
= videoBody
155 if (name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
157 return { accepted: true }
163 target: 'filter:api.video.pre-import-url.accept.result',
164 handler: ({ accepted
}, { videoImportBody
}) => {
165 if (!accepted
) return { accepted: false }
166 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
168 return { accepted: true }
173 target: 'filter:api.video.pre-import-torrent.accept.result',
174 handler: ({ accepted
}, { videoImportBody
}) => {
175 if (!accepted
) return { accepted: false }
176 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
178 return { accepted: true }
183 target: 'filter:api.video.post-import-url.accept.result',
184 handler: ({ accepted
}, { video
}) => {
185 if (!accepted
) return { accepted: false }
186 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
188 return { accepted: true }
193 target: 'filter:api.video.post-import-torrent.accept.result',
194 handler: ({ accepted
}, { video
}) => {
195 if (!accepted
) return { accepted: false }
196 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
198 return { accepted: true }
202 // ---------------------------------------------------------------------------
205 target: 'filter:api.video-thread.create.accept.result',
206 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
210 target: 'filter:api.video-comment-reply.create.accept.result',
211 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
215 target: 'filter:activity-pub.remote-video-comment.create.accept.result',
216 handler: ({ accepted
}, { comment
}) => checkCommentBadWord(accepted
, comment
)
219 // ---------------------------------------------------------------------------
222 target: 'filter:activity-pub.activity.context.build.result',
223 handler: context
=> context
.concat([ { recordedAt: 'https://schema.org/recordedAt' } ])
227 target: 'filter:activity-pub.video.json-ld.build.result',
228 handler: (jsonld
, { video
}) => ({ ...jsonld
, videoName: video
.name
})
231 // ---------------------------------------------------------------------------
234 target: 'filter:api.video-threads.list.params',
235 handler: obj
=> addToCount(obj
)
239 target: 'filter:api.video-threads.list.result',
240 handler: obj
=> addToTotal(obj
)
244 target: 'filter:api.video-thread-comments.list.result',
246 obj
.data
.forEach(c
=> c
.text
+= ' <3')
253 target: 'filter:video.auto-blacklist.result',
254 handler: (blacklisted
, { video
}) => {
255 if (blacklisted
) return true
256 if (video
.name
.includes('please blacklist me')) return true
264 target: 'filter:api.user.signup.allowed.result',
265 handler: (result
, params
) => {
266 if (params
&& params
.body
&& params
.body
.email
&& params
.body
.email
.includes('jma 1')) {
267 return { allowed: false, errorMessage: 'No jma 1' }
275 target: 'filter:api.user.request-signup.allowed.result',
276 handler: (result
, params
) => {
277 if (params
&& params
.body
&& params
.body
.email
&& params
.body
.email
.includes('jma 2')) {
278 return { allowed: false, errorMessage: 'No jma 2' }
287 target: 'filter:api.download.torrent.allowed.result',
288 handler: (result
, params
) => {
289 if (params
&& params
.downloadName
.includes('bad torrent')) {
290 return { allowed: false, errorMessage: 'Liu Bei' }
298 target: 'filter:api.download.video.allowed.result',
299 handler: async (result
, params
) => {
300 const loggedInUser
= await peertubeHelpers
.user
.getAuthUser(params
.res
)
301 if (loggedInUser
) return { allowed: true }
303 if (params
&& !params
.streamingPlaylist
&& params
.video
.name
.includes('bad file')) {
304 return { allowed: false, errorMessage: 'Cao Cao' }
307 if (params
&& params
.streamingPlaylist
&& params
.video
.name
.includes('bad playlist file')) {
308 return { allowed: false, errorMessage: 'Sun Jian' }
316 target: 'filter:html.embed.video.allowed.result',
317 handler: (result
, params
) => {
326 target: 'filter:html.embed.video-playlist.allowed.result',
327 handler: (result
, params
) => {
336 target: 'filter:api.server.stats.get.result',
337 handler: (result
) => {
338 return { ...result
, customStats: 14 }
343 target: 'filter:job-queue.process.params',
344 handler: (object
, context
) => {
345 if (context
.type
!== 'video-studio-edition') return object
347 object
.data
.tasks
= [
362 target: 'filter:transcoding.auto.resolutions-to-transcode.result',
363 handler: (object
, context
) => {
364 if (context
.video
.name
.includes('transcode-filter')) {
372 // Upload/import/live attributes
373 for (const target
of [
374 'filter:api.video.upload.video-attribute.result',
375 'filter:api.video.import-url.video-attribute.result',
376 'filter:api.video.import-torrent.video-attribute.result',
377 'filter:api.video.live.video-attribute.result'
381 handler: (result
) => {
382 return { ...result
, description: result
.description
+ ' - ' + target
}
388 const filterHooks
= [
389 'filter:api.search.videos.local.list.params',
390 'filter:api.search.videos.local.list.result',
391 'filter:api.search.videos.index.list.params',
392 'filter:api.search.videos.index.list.result',
393 'filter:api.search.video-channels.local.list.params',
394 'filter:api.search.video-channels.local.list.result',
395 'filter:api.search.video-channels.index.list.params',
396 'filter:api.search.video-channels.index.list.result',
397 'filter:api.search.video-playlists.local.list.params',
398 'filter:api.search.video-playlists.local.list.result',
399 'filter:api.search.video-playlists.index.list.params',
400 'filter:api.search.video-playlists.index.list.result',
402 'filter:api.overviews.videos.list.params',
403 'filter:api.overviews.videos.list.result',
405 'filter:job-queue.process.params',
406 'filter:job-queue.process.result'
409 for (const h
of filterHooks
) {
413 peertubeHelpers
.logger
.debug('Run hook %s.', h
)
422 async
function unregister () {
431 // ############################################################################
433 function addToCount (obj
, amount
= 1) {
434 return Object
.assign({}, obj
, { count: obj
.count
+ amount
})
437 function addToTotal (result
, amount
= 1) {
440 total: result
.total
+ amount
444 function checkCommentBadWord (accepted
, commentBody
) {
445 if (!accepted
) return { accepted: false }
446 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
448 return { accepted: true }