]>
Commit | Line | Data |
---|---|---|
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 | 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 | }) | |
84 | } | |
85 | ||
86 | } | |
87 | ||
88 | async function unregister () { | |
89 | return | |
90 | } | |
91 | ||
92 | module.exports = { | |
93 | register, | |
94 | unregister | |
95 | } | |
96 | ||
97 | // ########################################################################### | |
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 | } |