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