]>
Commit | Line | Data |
---|---|---|
1b05d82d | 1 | async function register ({ |
ab3ead3a | 2 | peertubeHelpers, |
80fdaf06 C |
3 | registerHook, |
4 | getRouter | |
1b05d82d | 5 | }) { |
ab3ead3a C |
6 | const logger = peertubeHelpers.logger |
7 | ||
8 | logger.info('Hello world from plugin four') | |
1b05d82d | 9 | |
80fdaf06 C |
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 }) => { | |
6559da28 C |
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) | |
80fdaf06 C |
34 | |
35 | await peertubeHelpers.videos.removeVideo(video.id) | |
1b05d82d | 36 | |
80fdaf06 C |
37 | logger.info('Video deleted by plugin four.') |
38 | } | |
39 | }) | |
40 | } | |
ab3ead3a | 41 | |
80fdaf06 C |
42 | { |
43 | const serverActor = await peertubeHelpers.server.getServerActor() | |
44 | logger.info('server actor name is %s', serverActor.preferredUsername) | |
45 | } | |
ab3ead3a | 46 | |
80fdaf06 C |
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 | |
ab3ead3a | 59 | } |
80fdaf06 C |
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 | }) | |
22820226 C |
72 | |
73 | router.get('/server-config', async (req, res) => { | |
74 | const serverConfig = await peertubeHelpers.config.getServerConfig() | |
75 | ||
76 | return res.json({ serverConfig }) | |
77 | }) | |
78 | ||
79 | router.get('/static-route', async (req, res) => { | |
80 | const staticRoute = await peertubeHelpers.plugin.getBaseStaticRoute() | |
81 | ||
82 | return res.json({ staticRoute }) | |
83 | }) | |
80fdaf06 | 84 | } |
22820226 | 85 | |
1b05d82d C |
86 | } |
87 | ||
88 | async function unregister () { | |
89 | return | |
90 | } | |
91 | ||
92 | module.exports = { | |
93 | register, | |
94 | unregister | |
95 | } | |
96 | ||
97 | // ########################################################################### | |
80fdaf06 C |
98 | |
99 | async function blockServer (peertubeHelpers, body) { | |
100 | const serverActor = await peertubeHelpers.server.getServerActor() | |
101 | ||
102 | await peertubeHelpers.moderation.blockServer({ byAccountId: serverActor.Account.id, hostToBlock: body.hostToBlock }) | |
103 | } | |
104 | ||
105 | async function unblockServer (peertubeHelpers, body) { | |
106 | const serverActor = await peertubeHelpers.server.getServerActor() | |
107 | ||
108 | await peertubeHelpers.moderation.unblockServer({ byAccountId: serverActor.Account.id, hostToUnblock: body.hostToUnblock }) | |
109 | } | |
110 | ||
111 | async function blockAccount (peertubeHelpers, body) { | |
112 | const serverActor = await peertubeHelpers.server.getServerActor() | |
113 | ||
114 | await peertubeHelpers.moderation.blockAccount({ byAccountId: serverActor.Account.id, handleToBlock: body.handleToBlock }) | |
115 | } | |
116 | ||
117 | async function unblockAccount (peertubeHelpers, body) { | |
118 | const serverActor = await peertubeHelpers.server.getServerActor() | |
119 | ||
120 | await peertubeHelpers.moderation.unblockAccount({ byAccountId: serverActor.Account.id, handleToUnblock: body.handleToUnblock }) | |
121 | } | |
122 | ||
123 | async function blacklist (peertubeHelpers, body) { | |
124 | await peertubeHelpers.moderation.blacklistVideo({ | |
125 | videoIdOrUUID: body.videoUUID, | |
126 | createOptions: body | |
127 | }) | |
128 | } | |
129 | ||
130 | async function unblacklist (peertubeHelpers, body) { | |
131 | await peertubeHelpers.moderation.unblacklistVideo({ videoIdOrUUID: body.videoUUID }) | |
132 | } |