]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/fixtures/peertube-plugin-test/main.js
7715ab6e8cbd956d3c9ec3733f072976c6047ccb
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.video-playlist.videos.list.params',
49 handler: obj
=> addToCount(obj
)
53 target: 'filter:api.video-playlist.videos.list.result',
54 handler: obj
=> addToTotal(obj
)
58 target: 'filter:api.accounts.videos.list.params',
59 handler: obj
=> addToCount(obj
)
63 target: 'filter:api.accounts.videos.list.result',
64 handler: obj
=> addToTotal(obj
, 2)
68 target: 'filter:api.video-channels.videos.list.params',
69 handler: obj
=> addToCount(obj
, 3)
73 target: 'filter:api.video-channels.videos.list.result',
74 handler: obj
=> addToTotal(obj
, 3)
78 target: 'filter:api.user.me.videos.list.params',
79 handler: obj
=> addToCount(obj
, 4)
83 target: 'filter:api.user.me.videos.list.result',
84 handler: obj
=> addToTotal(obj
, 4)
88 target: 'filter:api.video.get.result',
96 for (const hook
of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
99 handler: ({ accepted
}, { videoBody
, liveVideoBody
}) => {
100 if (!accepted
) return { accepted: false }
102 const name
= videoBody
106 if (name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
108 return { accepted: true }
114 target: 'filter:api.video.pre-import-url.accept.result',
115 handler: ({ accepted
}, { videoImportBody
}) => {
116 if (!accepted
) return { accepted: false }
117 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
119 return { accepted: true }
124 target: 'filter:api.video.pre-import-torrent.accept.result',
125 handler: ({ accepted
}, { videoImportBody
}) => {
126 if (!accepted
) return { accepted: false }
127 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
129 return { accepted: true }
134 target: 'filter:api.video.post-import-url.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.post-import-torrent.accept.result',
145 handler: ({ accepted
}, { video
}) => {
146 if (!accepted
) return { accepted: false }
147 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
149 return { accepted: true }
154 target: 'filter:api.video-thread.create.accept.result',
155 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
159 target: 'filter:api.video-comment-reply.create.accept.result',
160 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
164 target: 'filter:api.video-threads.list.params',
165 handler: obj
=> addToCount(obj
)
169 target: 'filter:api.video-threads.list.result',
170 handler: obj
=> addToTotal(obj
)
174 target: 'filter:api.video-thread-comments.list.result',
176 obj
.data
.forEach(c
=> c
.text
+= ' <3')
183 target: 'filter:video.auto-blacklist.result',
184 handler: (blacklisted
, { video
}) => {
185 if (blacklisted
) return true
186 if (video
.name
.includes('please blacklist me')) return true
193 target: 'filter:api.user.signup.allowed.result',
194 handler: (result
, params
) => {
195 if (params
&& params
.body
.email
.includes('jma')) {
196 return { allowed: false, errorMessage: 'No jma' }
204 target: 'filter:api.download.torrent.allowed.result',
205 handler: (result
, params
) => {
206 if (params
&& params
.downloadName
.includes('bad torrent')) {
207 return { allowed: false, errorMessage: 'Liu Bei' }
215 target: 'filter:api.download.video.allowed.result',
216 handler: (result
, params
) => {
217 if (params
&& !params
.streamingPlaylist
&& params
.video
.name
.includes('bad file')) {
218 return { allowed: false, errorMessage: 'Cao Cao' }
221 if (params
&& params
.streamingPlaylist
&& params
.video
.name
.includes('bad playlist file')) {
222 return { allowed: false, errorMessage: 'Sun Jian' }
230 target: 'filter:html.embed.video.allowed.result',
231 handler: (result
, params
) => {
240 target: 'filter:html.embed.video-playlist.allowed.result',
241 handler: (result
, params
) => {
250 target: 'filter:api.server.stats.get.result',
251 handler: (result
) => {
252 return { ...result
, customStats: 14 }
256 // Upload/import/live attributes
257 for (const target
of [
258 'filter:api.video.upload.video-attribute.result',
259 'filter:api.video.import-url.video-attribute.result',
260 'filter:api.video.import-torrent.video-attribute.result',
261 'filter:api.video.live.video-attribute.result'
265 handler: (result
) => {
266 return { ...result
, description: result
.description
+ ' - ' + target
}
272 const filterHooks
= [
273 'filter:api.search.videos.local.list.params',
274 'filter:api.search.videos.local.list.result',
275 'filter:api.search.videos.index.list.params',
276 'filter:api.search.videos.index.list.result',
277 'filter:api.search.video-channels.local.list.params',
278 'filter:api.search.video-channels.local.list.result',
279 'filter:api.search.video-channels.index.list.params',
280 'filter:api.search.video-channels.index.list.result',
281 'filter:api.search.video-playlists.local.list.params',
282 'filter:api.search.video-playlists.local.list.result',
283 'filter:api.search.video-playlists.index.list.params',
284 'filter:api.search.video-playlists.index.list.result',
286 'filter:api.overviews.videos.list.params',
287 'filter:api.overviews.videos.list.result'
290 for (const h
of filterHooks
) {
294 peertubeHelpers
.logger
.debug('Run hook %s.', h
)
303 async
function unregister () {
312 // ############################################################################
314 function addToCount (obj
, amount
= 1) {
315 return Object
.assign({}, obj
, { count: obj
.count
+ amount
})
318 function addToTotal (result
, amount
= 1) {
321 total: result
.total
+ amount
325 function checkCommentBadWord (accepted
, commentBody
) {
326 if (!accepted
) return { accepted: false }
327 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
329 return { accepted: true }