]>
Commit | Line | Data |
---|---|---|
1 | async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) { | |
2 | const actionHooks = [ | |
3 | 'action:application.listening', | |
4 | ||
5 | 'action:api.video.updated', | |
6 | 'action:api.video.deleted', | |
7 | 'action:api.video.uploaded', | |
8 | 'action:api.video.viewed', | |
9 | ||
10 | 'action:api.video-thread.created', | |
11 | 'action:api.video-comment-reply.created', | |
12 | 'action:api.video-comment.deleted', | |
13 | ||
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' | |
21 | ] | |
22 | ||
23 | for (const h of actionHooks) { | |
24 | registerHook({ | |
25 | target: h, | |
26 | handler: () => peertubeHelpers.logger.debug('Run hook %s.', h) | |
27 | }) | |
28 | } | |
29 | ||
30 | registerHook({ | |
31 | target: 'filter:api.videos.list.params', | |
32 | handler: obj => addToCount(obj) | |
33 | }) | |
34 | ||
35 | registerHook({ | |
36 | target: 'filter:api.videos.list.result', | |
37 | handler: obj => addToTotal(obj) | |
38 | }) | |
39 | ||
40 | registerHook({ | |
41 | target: 'filter:api.video.get.result', | |
42 | handler: video => { | |
43 | video.name += ' <3' | |
44 | ||
45 | return video | |
46 | } | |
47 | }) | |
48 | ||
49 | registerHook({ | |
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 '} | |
54 | ||
55 | return { accepted: true } | |
56 | } | |
57 | }) | |
58 | ||
59 | registerHook({ | |
60 | target: 'filter:api.video-thread.create.accept.result', | |
61 | handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody) | |
62 | }) | |
63 | ||
64 | registerHook({ | |
65 | target: 'filter:api.video-comment-reply.create.accept.result', | |
66 | handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody) | |
67 | }) | |
68 | ||
69 | registerHook({ | |
70 | target: 'filter:api.video-threads.list.params', | |
71 | handler: obj => addToCount(obj) | |
72 | }) | |
73 | ||
74 | registerHook({ | |
75 | target: 'filter:api.video-threads.list.result', | |
76 | handler: obj => addToTotal(obj) | |
77 | }) | |
78 | ||
79 | registerHook({ | |
80 | target: 'filter:api.video-thread-comments.list.result', | |
81 | handler: obj => { | |
82 | obj.data.forEach(c => c.text += ' <3') | |
83 | ||
84 | return obj | |
85 | } | |
86 | }) | |
87 | ||
88 | registerHook({ | |
89 | target: 'filter:video.auto-blacklist.result', | |
90 | handler: (blacklisted, { video }) => { | |
91 | if (blacklisted) return true | |
92 | if (video.name.includes('please blacklist me')) return true | |
93 | ||
94 | return false | |
95 | } | |
96 | }) | |
97 | ||
98 | registerHook({ | |
99 | target: 'filter:api.user.signup.allowed.result', | |
100 | handler: (result, params) => { | |
101 | if (params && params.body.email.includes('jma')) { | |
102 | return { allowed: false, errorMessage: 'No jma' } | |
103 | } | |
104 | ||
105 | return result | |
106 | } | |
107 | }) | |
108 | } | |
109 | ||
110 | async function unregister () { | |
111 | return | |
112 | } | |
113 | ||
114 | module.exports = { | |
115 | register, | |
116 | unregister | |
117 | } | |
118 | ||
119 | // ############################################################################ | |
120 | ||
121 | function addToCount (obj) { | |
122 | return Object.assign({}, obj, { count: obj.count + 1 }) | |
123 | } | |
124 | ||
125 | function addToTotal (result) { | |
126 | return { | |
127 | data: result.data, | |
128 | total: result.total + 1 | |
129 | } | |
130 | } | |
131 | ||
132 | function checkCommentBadWord (accepted, commentBody) { | |
133 | if (!accepted) return { accepted: false } | |
134 | if (commentBody.text.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '} | |
135 | ||
136 | return { accepted: true } | |
137 | } |