]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/fixtures/peertube-plugin-test/main.js
322c0610c934ccab9e62f8cb96f13c7707367056
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'
25 for (const h
of actionHooks
) {
28 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
33 target: 'filter:api.videos.list.params',
34 handler: obj
=> addToCount(obj
)
38 target: 'filter:api.videos.list.result',
39 handler: obj
=> addToTotal(obj
)
43 target: 'filter:api.video.get.result',
51 for (const hook
of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) {
54 handler: ({ accepted
}, { videoBody
, liveVideoBody
}) => {
55 if (!accepted
) return { accepted: false }
57 const name
= videoBody
61 if (name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
63 return { accepted: true }
69 target: 'filter:api.video.pre-import-url.accept.result',
70 handler: ({ accepted
}, { videoImportBody
}) => {
71 if (!accepted
) return { accepted: false }
72 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
74 return { accepted: true }
79 target: 'filter:api.video.pre-import-torrent.accept.result',
80 handler: ({ accepted
}, { videoImportBody
}) => {
81 if (!accepted
) return { accepted: false }
82 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
84 return { accepted: true }
89 target: 'filter:api.video.post-import-url.accept.result',
90 handler: ({ accepted
}, { video
}) => {
91 if (!accepted
) return { accepted: false }
92 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
94 return { accepted: true }
99 target: 'filter:api.video.post-import-torrent.accept.result',
100 handler: ({ accepted
}, { video
}) => {
101 if (!accepted
) return { accepted: false }
102 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
104 return { accepted: true }
109 target: 'filter:api.video-thread.create.accept.result',
110 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
114 target: 'filter:api.video-comment-reply.create.accept.result',
115 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
119 target: 'filter:api.video-threads.list.params',
120 handler: obj
=> addToCount(obj
)
124 target: 'filter:api.video-threads.list.result',
125 handler: obj
=> addToTotal(obj
)
129 target: 'filter:api.video-thread-comments.list.result',
131 obj
.data
.forEach(c
=> c
.text
+= ' <3')
138 target: 'filter:video.auto-blacklist.result',
139 handler: (blacklisted
, { video
}) => {
140 if (blacklisted
) return true
141 if (video
.name
.includes('please blacklist me')) return true
148 target: 'filter:api.user.signup.allowed.result',
149 handler: (result
, params
) => {
150 if (params
&& params
.body
.email
.includes('jma')) {
151 return { allowed: false, errorMessage: 'No jma' }
159 async
function unregister () {
168 // ############################################################################
170 function addToCount (obj
) {
171 return Object
.assign({}, obj
, { count: obj
.count
+ 1 })
174 function addToTotal (result
) {
177 total: result
.total
+ 1
181 function checkCommentBadWord (accepted
, commentBody
) {
182 if (!accepted
) return { accepted: false }
183 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
185 return { accepted: true }