]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/fixtures/peertube-plugin-test/main.js
Add missing channel playlists AP endpoint
[github/Chocobozzz/PeerTube.git] / server / tests / fixtures / peertube-plugin-test / main.js
CommitLineData
89cd1275
C
1async 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',
6f3fe96f
C
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'
89cd1275
C
21 ]
22
23 for (const h of actionHooks) {
24 registerHook({
25 target: h,
26 handler: () => peertubeHelpers.logger.debug('Run hook %s.', h)
27 })
28 }
9b474844
C
29
30 registerHook({
89cd1275
C
31 target: 'filter:api.videos.list.params',
32 handler: obj => addToCount(obj)
9b474844
C
33 })
34
89cd1275
C
35 registerHook({
36 target: 'filter:api.videos.list.result',
6691c522 37 handler: obj => addToTotal(obj)
9b474844
C
38 })
39
89cd1275
C
40 registerHook({
41 target: 'filter:api.video.get.result',
42 handler: video => {
43 video.name += ' <3'
9b474844 44
89cd1275
C
45 return video
46 }
47 })
48
49 registerHook({
50 target: 'filter:api.video.upload.accept.result',
51 handler: ({ accepted }, { videoBody }) => {
6691c522 52 if (!accepted) return { accepted: false }
89cd1275
C
53 if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
54
55 return { accepted: true }
56 }
57 })
6691c522
C
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 })
4ce7eb71
C
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 })
9b474844
C
108}
109
110async function unregister () {
111 return
112}
113
114module.exports = {
115 register,
116 unregister
117}
118
119// ############################################################################
120
89cd1275
C
121function addToCount (obj) {
122 return Object.assign({}, obj, { count: obj.count + 1 })
9b474844 123}
6691c522
C
124
125function addToTotal (result) {
126 return {
127 data: result.data,
128 total: result.total + 1
129 }
130}
131
132function 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}