aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/fixtures/peertube-plugin-test-four
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-05-07 14:58:24 +0200
committerChocobozzz <me@florianbigard.com>2020-05-07 15:07:01 +0200
commit80fdaf064562aff968f4c9cea1cf220bc12a70da (patch)
treea0ec49f433b828660f741b394dfd87056cd2c6ef /server/tests/fixtures/peertube-plugin-test-four
parent3cc665f48fd233d09f778d7e887488dde6f03ef6 (diff)
downloadPeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.gz
PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.tar.zst
PeerTube-80fdaf064562aff968f4c9cea1cf220bc12a70da.zip
Add moderation helpers to plugins
Diffstat (limited to 'server/tests/fixtures/peertube-plugin-test-four')
-rw-r--r--server/tests/fixtures/peertube-plugin-test-four/main.js107
1 files changed, 91 insertions, 16 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js
index 2e81550c1..067c3fe15 100644
--- a/server/tests/fixtures/peertube-plugin-test-four/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-four/main.js
@@ -1,30 +1,70 @@
1async function register ({ 1async function register ({
2 peertubeHelpers, 2 peertubeHelpers,
3 registerHook 3 registerHook,
4 getRouter
4}) { 5}) {
5 const logger = peertubeHelpers.logger 6 const logger = peertubeHelpers.logger
6 7
7 logger.info('Hello world from plugin four') 8 logger.info('Hello world from plugin four')
8 9
9 const username = 'root' 10 {
10 const results = await peertubeHelpers.database.query( 11 const username = 'root'
11 'SELECT "email" from "user" WHERE "username" = $username', 12 const results = await peertubeHelpers.database.query(
12 { 13 'SELECT "email" from "user" WHERE "username" = $username',
13 type: 'SELECT', 14 {
14 bind: { username } 15 type: 'SELECT',
15 } 16 bind: { username }
16 ) 17 }
18 )
19
20 logger.info('root email is ' + results[0]['email'])
21 }
22
23 {
24 registerHook({
25 target: 'action:api.video.viewed',
26 handler: async ({ video }) => {
27 const videoFromDB = await peertubeHelpers.videos.loadByUrl(video.url)
28 logger.info('video from DB uuid is %s.', videoFromDB.uuid)
29
30 await peertubeHelpers.videos.removeVideo(video.id)
17 31
18 logger.info('root email is ' + results[0]['email']) 32 logger.info('Video deleted by plugin four.')
33 }
34 })
35 }
19 36
20 registerHook({ 37 {
21 target: 'action:api.video.viewed', 38 const serverActor = await peertubeHelpers.server.getServerActor()
22 handler: async ({ video }) => { 39 logger.info('server actor name is %s', serverActor.preferredUsername)
23 await peertubeHelpers.videos.removeVideo(video.id) 40 }
24 41
25 logger.info('Video deleted by plugin four.') 42 {
43 logger.info('server url is %s', peertubeHelpers.config.getWebserverUrl())
44 }
45
46 {
47 const actions = {
48 blockServer,
49 unblockServer,
50 blockAccount,
51 unblockAccount,
52 blacklist,
53 unblacklist
26 } 54 }
27 }) 55
56 const router = getRouter()
57 router.post('/commander', async (req, res) => {
58 try {
59 await actions[req.body.command](peertubeHelpers, req.body)
60
61 res.sendStatus(204)
62 } catch (err) {
63 logger.error('Error in commander.', { err })
64 res.sendStatus(500)
65 }
66 })
67 }
28} 68}
29 69
30async function unregister () { 70async function unregister () {
@@ -37,3 +77,38 @@ module.exports = {
37} 77}
38 78
39// ########################################################################### 79// ###########################################################################
80
81async function blockServer (peertubeHelpers, body) {
82 const serverActor = await peertubeHelpers.server.getServerActor()
83
84 await peertubeHelpers.moderation.blockServer({ byAccountId: serverActor.Account.id, hostToBlock: body.hostToBlock })
85}
86
87async function unblockServer (peertubeHelpers, body) {
88 const serverActor = await peertubeHelpers.server.getServerActor()
89
90 await peertubeHelpers.moderation.unblockServer({ byAccountId: serverActor.Account.id, hostToUnblock: body.hostToUnblock })
91}
92
93async function blockAccount (peertubeHelpers, body) {
94 const serverActor = await peertubeHelpers.server.getServerActor()
95
96 await peertubeHelpers.moderation.blockAccount({ byAccountId: serverActor.Account.id, handleToBlock: body.handleToBlock })
97}
98
99async function unblockAccount (peertubeHelpers, body) {
100 const serverActor = await peertubeHelpers.server.getServerActor()
101
102 await peertubeHelpers.moderation.unblockAccount({ byAccountId: serverActor.Account.id, handleToUnblock: body.handleToUnblock })
103}
104
105async function blacklist (peertubeHelpers, body) {
106 await peertubeHelpers.moderation.blacklistVideo({
107 videoIdOrUUID: body.videoUUID,
108 createOptions: body
109 })
110}
111
112async function unblacklist (peertubeHelpers, body) {
113 await peertubeHelpers.moderation.unblacklistVideo({ videoIdOrUUID: body.videoUUID })
114}