diff options
Diffstat (limited to 'server/tests/fixtures/peertube-plugin-test-four/main.js')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-four/main.js | 201 |
1 files changed, 0 insertions, 201 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js deleted file mode 100644 index b10177b45..000000000 --- a/server/tests/fixtures/peertube-plugin-test-four/main.js +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
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('/server-listening-config', async (req, res) => { | ||
80 | const config = await peertubeHelpers.config.getServerListeningConfig() | ||
81 | |||
82 | return res.json({ config }) | ||
83 | }) | ||
84 | |||
85 | router.get('/static-route', async (req, res) => { | ||
86 | const staticRoute = peertubeHelpers.plugin.getBaseStaticRoute() | ||
87 | |||
88 | return res.json({ staticRoute }) | ||
89 | }) | ||
90 | |||
91 | router.get('/router-route', async (req, res) => { | ||
92 | const routerRoute = peertubeHelpers.plugin.getBaseRouterRoute() | ||
93 | |||
94 | return res.json({ routerRoute }) | ||
95 | }) | ||
96 | |||
97 | router.get('/user/:id', async (req, res) => { | ||
98 | const user = await peertubeHelpers.user.loadById(req.params.id) | ||
99 | if (!user) return res.status(404).end() | ||
100 | |||
101 | return res.json({ | ||
102 | username: user.username | ||
103 | }) | ||
104 | }) | ||
105 | |||
106 | router.get('/user', async (req, res) => { | ||
107 | const user = await peertubeHelpers.user.getAuthUser(res) | ||
108 | if (!user) return res.sendStatus(404) | ||
109 | |||
110 | const isAdmin = user.role === 0 | ||
111 | const isModerator = user.role === 1 | ||
112 | const isUser = user.role === 2 | ||
113 | |||
114 | return res.json({ | ||
115 | id: user.id, | ||
116 | username: user.username, | ||
117 | displayName: user.Account.name, | ||
118 | isAdmin, | ||
119 | isModerator, | ||
120 | isUser | ||
121 | }) | ||
122 | }) | ||
123 | |||
124 | router.get('/video-files/:id', async (req, res) => { | ||
125 | const details = await peertubeHelpers.videos.getFiles(req.params.id) | ||
126 | if (!details) return res.sendStatus(404) | ||
127 | |||
128 | return res.json(details) | ||
129 | }) | ||
130 | |||
131 | router.get('/ffprobe', async (req, res) => { | ||
132 | const result = await peertubeHelpers.videos.ffprobe(req.query.path) | ||
133 | if (!result) return res.sendStatus(404) | ||
134 | |||
135 | return res.json(result) | ||
136 | }) | ||
137 | |||
138 | router.post('/send-notification', async (req, res) => { | ||
139 | peertubeHelpers.socket.sendNotification(req.body.userId, { | ||
140 | type: 1, | ||
141 | userId: req.body.userId | ||
142 | }) | ||
143 | |||
144 | return res.sendStatus(201) | ||
145 | }) | ||
146 | |||
147 | router.post('/send-video-live-new-state/:uuid', async (req, res) => { | ||
148 | const video = await peertubeHelpers.videos.loadByIdOrUUID(req.params.uuid) | ||
149 | peertubeHelpers.socket.sendVideoLiveNewState(video) | ||
150 | |||
151 | return res.sendStatus(201) | ||
152 | }) | ||
153 | } | ||
154 | |||
155 | } | ||
156 | |||
157 | async function unregister () { | ||
158 | return | ||
159 | } | ||
160 | |||
161 | module.exports = { | ||
162 | register, | ||
163 | unregister | ||
164 | } | ||
165 | |||
166 | // ########################################################################### | ||
167 | |||
168 | async function blockServer (peertubeHelpers, body) { | ||
169 | const serverActor = await peertubeHelpers.server.getServerActor() | ||
170 | |||
171 | await peertubeHelpers.moderation.blockServer({ byAccountId: serverActor.Account.id, hostToBlock: body.hostToBlock }) | ||
172 | } | ||
173 | |||
174 | async function unblockServer (peertubeHelpers, body) { | ||
175 | const serverActor = await peertubeHelpers.server.getServerActor() | ||
176 | |||
177 | await peertubeHelpers.moderation.unblockServer({ byAccountId: serverActor.Account.id, hostToUnblock: body.hostToUnblock }) | ||
178 | } | ||
179 | |||
180 | async function blockAccount (peertubeHelpers, body) { | ||
181 | const serverActor = await peertubeHelpers.server.getServerActor() | ||
182 | |||
183 | await peertubeHelpers.moderation.blockAccount({ byAccountId: serverActor.Account.id, handleToBlock: body.handleToBlock }) | ||
184 | } | ||
185 | |||
186 | async function unblockAccount (peertubeHelpers, body) { | ||
187 | const serverActor = await peertubeHelpers.server.getServerActor() | ||
188 | |||
189 | await peertubeHelpers.moderation.unblockAccount({ byAccountId: serverActor.Account.id, handleToUnblock: body.handleToUnblock }) | ||
190 | } | ||
191 | |||
192 | async function blacklist (peertubeHelpers, body) { | ||
193 | await peertubeHelpers.moderation.blacklistVideo({ | ||
194 | videoIdOrUUID: body.videoUUID, | ||
195 | createOptions: body | ||
196 | }) | ||
197 | } | ||
198 | |||
199 | async function unblacklist (peertubeHelpers, body) { | ||
200 | await peertubeHelpers.moderation.unblacklistVideo({ videoIdOrUUID: body.videoUUID }) | ||
201 | } | ||