aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/fixtures/peertube-plugin-test
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/fixtures/peertube-plugin-test')
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js57
1 files changed, 55 insertions, 2 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index c5317ab41..7c53f6afe 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -26,7 +26,7 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
26 26
27 registerHook({ 27 registerHook({
28 target: 'filter:api.videos.list.result', 28 target: 'filter:api.videos.list.result',
29 handler: obj => ({ data: obj.data, total: obj.total + 1 }) 29 handler: obj => addToTotal(obj)
30 }) 30 })
31 31
32 registerHook({ 32 registerHook({
@@ -41,12 +41,51 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
41 registerHook({ 41 registerHook({
42 target: 'filter:api.video.upload.accept.result', 42 target: 'filter:api.video.upload.accept.result',
43 handler: ({ accepted }, { videoBody }) => { 43 handler: ({ accepted }, { videoBody }) => {
44 if (accepted !== false) return { accepted: true } 44 if (!accepted) return { accepted: false }
45 if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '} 45 if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
46 46
47 return { accepted: true } 47 return { accepted: true }
48 } 48 }
49 }) 49 })
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 })
50} 89}
51 90
52async function unregister () { 91async function unregister () {
@@ -63,3 +102,17 @@ module.exports = {
63function addToCount (obj) { 102function addToCount (obj) {
64 return Object.assign({}, obj, { count: obj.count + 1 }) 103 return Object.assign({}, obj, { count: obj.count + 1 })
65} 104}
105
106function addToTotal (result) {
107 return {
108 data: result.data,
109 total: result.total + 1
110 }
111}
112
113function checkCommentBadWord (accepted, commentBody) {
114 if (!accepted) return { accepted: false }
115 if (commentBody.text.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
116
117 return { accepted: true }
118}