]>
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.video-caption.created',
17 'action:api.video-caption.deleted',
19 'action:api.user.blocked',
20 'action:api.user.unblocked',
21 'action:api.user.registered',
22 'action:api.user.created',
23 'action:api.user.deleted',
24 'action:api.user.updated',
25 'action:api.user.oauth2-got-token',
27 'action:api.video-playlist-element.created'
30 for (const h
of actionHooks
) {
33 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
38 target: 'filter:api.videos.list.params',
39 handler: obj
=> addToCount(obj
)
43 target: 'filter:api.videos.list.result',
44 handler: obj
=> addToTotal(obj
)
48 target: 'filter:api.accounts.videos.list.params',
49 handler: obj
=> addToCount(obj
)
53 target: 'filter:api.accounts.videos.list.result',
54 handler: obj
=> addToTotal(obj
, 2)
58 target: 'filter:api.video-channels.videos.list.params',
59 handler: obj
=> addToCount(obj
, 3)
63 target: 'filter:api.video-channels.videos.list.result',
64 handler: obj
=> addToTotal(obj
, 3)
68 target: 'filter:api.user.me.videos.list.params',
69 handler: obj
=> addToCount(obj
, 4)
73 target: 'filter:api.user.me.videos.list.result',
74 handler: obj
=> addToTotal(obj
, 4)
78 target: 'filter:api.video.get.result',
86 for (const hook
of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
89 handler: ({ accepted
}, { videoBody
, liveVideoBody
}) => {
90 if (!accepted
) return { accepted: false }
92 const name
= videoBody
96 if (name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
98 return { accepted: true }
104 target: 'filter:api.video.pre-import-url.accept.result',
105 handler: ({ accepted
}, { videoImportBody
}) => {
106 if (!accepted
) return { accepted: false }
107 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
109 return { accepted: true }
114 target: 'filter:api.video.pre-import-torrent.accept.result',
115 handler: ({ accepted
}, { videoImportBody
}) => {
116 if (!accepted
) return { accepted: false }
117 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
119 return { accepted: true }
124 target: 'filter:api.video.post-import-url.accept.result',
125 handler: ({ accepted
}, { video
}) => {
126 if (!accepted
) return { accepted: false }
127 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
129 return { accepted: true }
134 target: 'filter:api.video.post-import-torrent.accept.result',
135 handler: ({ accepted
}, { video
}) => {
136 if (!accepted
) return { accepted: false }
137 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
139 return { accepted: true }
144 target: 'filter:api.video-thread.create.accept.result',
145 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
149 target: 'filter:api.video-comment-reply.create.accept.result',
150 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
154 target: 'filter:api.video-threads.list.params',
155 handler: obj
=> addToCount(obj
)
159 target: 'filter:api.video-threads.list.result',
160 handler: obj
=> addToTotal(obj
)
164 target: 'filter:api.video-thread-comments.list.result',
166 obj
.data
.forEach(c
=> c
.text
+= ' <3')
173 target: 'filter:video.auto-blacklist.result',
174 handler: (blacklisted
, { video
}) => {
175 if (blacklisted
) return true
176 if (video
.name
.includes('please blacklist me')) return true
183 target: 'filter:api.user.signup.allowed.result',
184 handler: (result
, params
) => {
185 if (params
&& params
.body
.email
.includes('jma')) {
186 return { allowed: false, errorMessage: 'No jma' }
194 target: 'filter:api.download.torrent.allowed.result',
195 handler: (result
, params
) => {
196 if (params
&& params
.downloadName
.includes('bad torrent')) {
197 return { allowed: false, errorMessage: 'Liu Bei' }
205 target: 'filter:api.download.video.allowed.result',
206 handler: (result
, params
) => {
207 if (params
&& !params
.streamingPlaylist
&& params
.video
.name
.includes('bad file')) {
208 return { allowed: false, errorMessage: 'Cao Cao' }
211 if (params
&& params
.streamingPlaylist
&& params
.video
.name
.includes('bad playlist file')) {
212 return { allowed: false, errorMessage: 'Sun Jian' }
220 target: 'filter:html.embed.video.allowed.result',
221 handler: (result
, params
) => {
230 target: 'filter:html.embed.video-playlist.allowed.result',
231 handler: (result
, params
) => {
240 target: 'filter:api.server.stats.get.result',
241 handler: (result
) => {
242 return { ...result
, customStats: 14 }
246 // Upload/import/live attributes
247 for (const target
of [
248 'filter:api.video.upload.video-attribute.result',
249 'filter:api.video.import-url.video-attribute.result',
250 'filter:api.video.import-torrent.video-attribute.result',
251 'filter:api.video.live.video-attribute.result'
255 handler: (result
) => {
256 return { ...result
, description: result
.description
+ ' - ' + target
}
262 const filterHooks
= [
263 'filter:api.search.videos.local.list.params',
264 'filter:api.search.videos.local.list.result',
265 'filter:api.search.videos.index.list.params',
266 'filter:api.search.videos.index.list.result',
267 'filter:api.search.video-channels.local.list.params',
268 'filter:api.search.video-channels.local.list.result',
269 'filter:api.search.video-channels.index.list.params',
270 'filter:api.search.video-channels.index.list.result',
271 'filter:api.search.video-playlists.local.list.params',
272 'filter:api.search.video-playlists.local.list.result',
273 'filter:api.search.video-playlists.index.list.params',
274 'filter:api.search.video-playlists.index.list.result',
276 'filter:api.overviews.videos.list.params',
277 'filter:api.overviews.videos.list.result'
280 for (const h
of filterHooks
) {
284 peertubeHelpers
.logger
.debug('Run hook %s.', h
)
293 async
function unregister () {
302 // ############################################################################
304 function addToCount (obj
, amount
= 1) {
305 return Object
.assign({}, obj
, { count: obj
.count
+ amount
})
308 function addToTotal (result
, amount
= 1) {
311 total: result
.total
+ amount
315 function checkCommentBadWord (accepted
, commentBody
) {
316 if (!accepted
) return { accepted: false }
317 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
319 return { accepted: true }