]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/fixtures/peertube-plugin-test-four/main.js
Fix import tests
[github/Chocobozzz/PeerTube.git] / server / tests / fixtures / peertube-plugin-test-four / main.js
1 async function register ({
2 peertubeHelpers,
3 registerHook,
4 getRouter
5 }) {
6 const logger = peertubeHelpers.logger
7
8 logger.info('Hello world from plugin four')
9
10 {
11 const username = 'root'
12 const results = await peertubeHelpers.database.query(
13 'SELECT "email" from "user" WHERE "username" = $username',
14 {
15 type: 'SELECT',
16 bind: { username }
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 videoFromDB1 = await peertubeHelpers.videos.loadByUrl(video.url)
28 const videoFromDB2 = await peertubeHelpers.videos.loadByIdOrUUID(video.id)
29 const videoFromDB3 = await peertubeHelpers.videos.loadByIdOrUUID(video.uuid)
30
31 if (videoFromDB1.uuid !== videoFromDB2.uuid || videoFromDB2.uuid !== videoFromDB3.uuid) return
32
33 logger.info('video from DB uuid is %s.', videoFromDB1.uuid)
34
35 await peertubeHelpers.videos.removeVideo(video.id)
36
37 logger.info('Video deleted by plugin four.')
38 }
39 })
40 }
41
42 {
43 const serverActor = await peertubeHelpers.server.getServerActor()
44 logger.info('server actor name is %s', serverActor.preferredUsername)
45 }
46
47 {
48 logger.info('server url is %s', peertubeHelpers.config.getWebserverUrl())
49 }
50
51 {
52 const actions = {
53 blockServer,
54 unblockServer,
55 blockAccount,
56 unblockAccount,
57 blacklist,
58 unblacklist
59 }
60
61 const router = getRouter()
62 router.post('/commander', async (req, res) => {
63 try {
64 await actions[req.body.command](peertubeHelpers, req.body)
65
66 res.sendStatus(204)
67 } catch (err) {
68 logger.error('Error in commander.', { err })
69 res.sendStatus(500)
70 }
71 })
72 }
73 }
74
75 async function unregister () {
76 return
77 }
78
79 module.exports = {
80 register,
81 unregister
82 }
83
84 // ###########################################################################
85
86 async function blockServer (peertubeHelpers, body) {
87 const serverActor = await peertubeHelpers.server.getServerActor()
88
89 await peertubeHelpers.moderation.blockServer({ byAccountId: serverActor.Account.id, hostToBlock: body.hostToBlock })
90 }
91
92 async function unblockServer (peertubeHelpers, body) {
93 const serverActor = await peertubeHelpers.server.getServerActor()
94
95 await peertubeHelpers.moderation.unblockServer({ byAccountId: serverActor.Account.id, hostToUnblock: body.hostToUnblock })
96 }
97
98 async function blockAccount (peertubeHelpers, body) {
99 const serverActor = await peertubeHelpers.server.getServerActor()
100
101 await peertubeHelpers.moderation.blockAccount({ byAccountId: serverActor.Account.id, handleToBlock: body.handleToBlock })
102 }
103
104 async function unblockAccount (peertubeHelpers, body) {
105 const serverActor = await peertubeHelpers.server.getServerActor()
106
107 await peertubeHelpers.moderation.unblockAccount({ byAccountId: serverActor.Account.id, handleToUnblock: body.handleToUnblock })
108 }
109
110 async function blacklist (peertubeHelpers, body) {
111 await peertubeHelpers.moderation.blacklistVideo({
112 videoIdOrUUID: body.videoUUID,
113 createOptions: body
114 })
115 }
116
117 async function unblacklist (peertubeHelpers, body) {
118 await peertubeHelpers.moderation.unblacklistVideo({ videoIdOrUUID: body.videoUUID })
119 }