1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
const actionHooks = [
'action:application.listening',
'action:api.video.updated',
'action:api.video.deleted',
'action:api.video.uploaded',
'action:api.video.viewed',
'action:api.video-thread.created',
'action:api.video-comment-reply.created',
'action:api.video-comment.deleted'
]
for (const h of actionHooks) {
registerHook({
target: h,
handler: () => peertubeHelpers.logger.debug('Run hook %s.', h)
})
}
registerHook({
target: 'filter:api.videos.list.params',
handler: obj => addToCount(obj)
})
registerHook({
target: 'filter:api.videos.list.result',
handler: obj => ({ data: obj.data, total: obj.total + 1 })
})
registerHook({
target: 'filter:api.video.get.result',
handler: video => {
video.name += ' <3'
return video
}
})
registerHook({
target: 'filter:api.video.upload.accept.result',
handler: ({ accepted }, { videoBody }) => {
if (accepted !== false) return { accepted: true }
if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
return { accepted: true }
}
})
}
async function unregister () {
return
}
module.exports = {
register,
unregister
}
// ############################################################################
function addToCount (obj) {
return Object.assign({}, obj, { count: obj.count + 1 })
}
|