]>
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',
24 'action:api.video-playlist-element.created'
27 for (const h
of actionHooks
) {
30 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
35 target: 'filter:api.videos.list.params',
36 handler: obj
=> addToCount(obj
)
40 target: 'filter:api.videos.list.result',
41 handler: obj
=> addToTotal(obj
)
45 target: 'filter:api.accounts.videos.list.params',
46 handler: obj
=> addToCount(obj
)
50 target: 'filter:api.accounts.videos.list.result',
51 handler: obj
=> addToTotal(obj
, 2)
55 target: 'filter:api.video-channels.videos.list.params',
56 handler: obj
=> addToCount(obj
, 3)
60 target: 'filter:api.video-channels.videos.list.result',
61 handler: obj
=> addToTotal(obj
, 3)
65 target: 'filter:api.user.me.videos.list.params',
66 handler: obj
=> addToCount(obj
, 4)
70 target: 'filter:api.user.me.videos.list.result',
71 handler: obj
=> addToTotal(obj
, 4)
75 target: 'filter:api.video.get.result',
83 for (const hook
of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
86 handler: ({ accepted
}, { videoBody
, liveVideoBody
}) => {
87 if (!accepted
) return { accepted: false }
89 const name
= videoBody
93 if (name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
95 return { accepted: true }
101 target: 'filter:api.video.pre-import-url.accept.result',
102 handler: ({ accepted
}, { videoImportBody
}) => {
103 if (!accepted
) return { accepted: false }
104 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
106 return { accepted: true }
111 target: 'filter:api.video.pre-import-torrent.accept.result',
112 handler: ({ accepted
}, { videoImportBody
}) => {
113 if (!accepted
) return { accepted: false }
114 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
116 return { accepted: true }
121 target: 'filter:api.video.post-import-url.accept.result',
122 handler: ({ accepted
}, { video
}) => {
123 if (!accepted
) return { accepted: false }
124 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
126 return { accepted: true }
131 target: 'filter:api.video.post-import-torrent.accept.result',
132 handler: ({ accepted
}, { video
}) => {
133 if (!accepted
) return { accepted: false }
134 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
136 return { accepted: true }
141 target: 'filter:api.video-thread.create.accept.result',
142 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
146 target: 'filter:api.video-comment-reply.create.accept.result',
147 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
151 target: 'filter:api.video-threads.list.params',
152 handler: obj
=> addToCount(obj
)
156 target: 'filter:api.video-threads.list.result',
157 handler: obj
=> addToTotal(obj
)
161 target: 'filter:api.video-thread-comments.list.result',
163 obj
.data
.forEach(c
=> c
.text
+= ' <3')
170 target: 'filter:video.auto-blacklist.result',
171 handler: (blacklisted
, { video
}) => {
172 if (blacklisted
) return true
173 if (video
.name
.includes('please blacklist me')) return true
180 target: 'filter:api.user.signup.allowed.result',
181 handler: (result
, params
) => {
182 if (params
&& params
.body
.email
.includes('jma')) {
183 return { allowed: false, errorMessage: 'No jma' }
191 target: 'filter:api.download.torrent.allowed.result',
192 handler: (result
, params
) => {
193 if (params
&& params
.downloadName
.includes('bad torrent')) {
194 return { allowed: false, errorMessage: 'Liu Bei' }
202 target: 'filter:api.download.video.allowed.result',
203 handler: (result
, params
) => {
204 if (params
&& !params
.streamingPlaylist
&& params
.video
.name
.includes('bad file')) {
205 return { allowed: false, errorMessage: 'Cao Cao' }
208 if (params
&& params
.streamingPlaylist
&& params
.video
.name
.includes('bad playlist file')) {
209 return { allowed: false, errorMessage: 'Sun Jian' }
217 target: 'filter:html.embed.video.allowed.result',
218 handler: (result
, params
) => {
227 target: 'filter:html.embed.video-playlist.allowed.result',
228 handler: (result
, params
) => {
237 const filterHooks
= [
238 'filter:api.search.videos.local.list.params',
239 'filter:api.search.videos.local.list.result',
240 'filter:api.search.videos.index.list.params',
241 'filter:api.search.videos.index.list.result',
242 'filter:api.search.video-channels.local.list.params',
243 'filter:api.search.video-channels.local.list.result',
244 'filter:api.search.video-channels.index.list.params',
245 'filter:api.search.video-channels.index.list.result',
246 'filter:api.search.video-playlists.local.list.params',
247 'filter:api.search.video-playlists.local.list.result',
248 'filter:api.search.video-playlists.index.list.params',
249 'filter:api.search.video-playlists.index.list.result',
251 'filter:api.overviews.videos.list.params',
252 'filter:api.overviews.videos.list.result'
255 for (const h
of filterHooks
) {
259 peertubeHelpers
.logger
.debug('Run hook %s.', h
)
268 async
function unregister () {
277 // ############################################################################
279 function addToCount (obj
, amount
= 1) {
280 return Object
.assign({}, obj
, { count: obj
.count
+ amount
})
283 function addToTotal (result
, amount
= 1) {
286 total: result
.total
+ amount
290 function checkCommentBadWord (accepted
, commentBody
) {
291 if (!accepted
) return { accepted: false }
292 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
294 return { accepted: true }