]>
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.video-thread.created',
11 'action:api.video-comment-reply.created',
12 'action:api.video-comment.deleted',
14 'action:api.user.blocked',
15 'action:api.user.unblocked',
16 'action:api.user.registered',
17 'action:api.user.created',
18 'action:api.user.deleted',
19 'action:api.user.updated',
20 'action:api.user.oauth2-got-token'
23 for (const h
of actionHooks
) {
26 handler: () => peertubeHelpers
.logger
.debug('Run hook %s.', h
)
31 target: 'filter:api.videos.list.params',
32 handler: obj
=> addToCount(obj
)
36 target: 'filter:api.videos.list.result',
37 handler: obj
=> addToTotal(obj
)
41 target: 'filter:api.video.get.result',
50 target: 'filter:api.video.upload.accept.result',
51 handler: ({ accepted
}, { videoBody
}) => {
52 if (!accepted
) return { accepted: false }
53 if (videoBody
.name
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
55 return { accepted: true }
60 target: 'filter:api.video.pre-import-url.accept.result',
61 handler: ({ accepted
}, { videoImportBody
}) => {
62 if (!accepted
) return { accepted: false }
63 if (videoImportBody
.targetUrl
.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
65 return { accepted: true }
70 target: 'filter:api.video.pre-import-torrent.accept.result',
71 handler: ({ accepted
}, { videoImportBody
}) => {
72 if (!accepted
) return { accepted: false }
73 if (videoImportBody
.name
.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
75 return { accepted: true }
80 target: 'filter:api.video.post-import-url.accept.result',
81 handler: ({ accepted
}, { video
}) => {
82 if (!accepted
) return { accepted: false }
83 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
85 return { accepted: true }
90 target: 'filter:api.video.post-import-torrent.accept.result',
91 handler: ({ accepted
}, { video
}) => {
92 if (!accepted
) return { accepted: false }
93 if (video
.name
.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
95 return { accepted: true }
100 target: 'filter:api.video-thread.create.accept.result',
101 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
105 target: 'filter:api.video-comment-reply.create.accept.result',
106 handler: ({ accepted
}, { commentBody
}) => checkCommentBadWord(accepted
, commentBody
)
110 target: 'filter:api.video-threads.list.params',
111 handler: obj
=> addToCount(obj
)
115 target: 'filter:api.video-threads.list.result',
116 handler: obj
=> addToTotal(obj
)
120 target: 'filter:api.video-thread-comments.list.result',
122 obj
.data
.forEach(c
=> c
.text
+= ' <3')
129 target: 'filter:video.auto-blacklist.result',
130 handler: (blacklisted
, { video
}) => {
131 if (blacklisted
) return true
132 if (video
.name
.includes('please blacklist me')) return true
139 target: 'filter:api.user.signup.allowed.result',
140 handler: (result
, params
) => {
141 if (params
&& params
.body
.email
.includes('jma')) {
142 return { allowed: false, errorMessage: 'No jma' }
150 async
function unregister () {
159 // ############################################################################
161 function addToCount (obj
) {
162 return Object
.assign({}, obj
, { count: obj
.count
+ 1 })
165 function addToTotal (result
) {
168 total: result
.total
+ 1
172 function checkCommentBadWord (accepted
, commentBody
) {
173 if (!accepted
) return { accepted: false }
174 if (commentBody
.text
.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
176 return { accepted: true }