]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/filter-hooks.ts
Merge branch 'release/5.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / filter-hooks.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import {
5 HttpStatusCode,
6 PeerTubeProblemDocument,
7 VideoDetails,
8 VideoImportState,
9 VideoPlaylist,
10 VideoPlaylistPrivacy,
11 VideoPrivacy
12 } from '@shared/models'
13 import {
14 cleanupTests,
15 createMultipleServers,
16 doubleFollow,
17 makeGetRequest,
18 makeRawRequest,
19 PeerTubeServer,
20 PluginsCommand,
21 setAccessTokensToServers,
22 setDefaultVideoChannel,
23 waitJobs
24 } from '@shared/server-commands'
25 import { FIXTURE_URLS } from '../shared'
26
27 describe('Test plugin filter hooks', function () {
28 let servers: PeerTubeServer[]
29 let videoUUID: string
30 let threadId: number
31 let videoPlaylistUUID: string
32
33 before(async function () {
34 this.timeout(60000)
35
36 servers = await createMultipleServers(2)
37 await setAccessTokensToServers(servers)
38 await setDefaultVideoChannel(servers)
39 await doubleFollow(servers[0], servers[1])
40
41 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
42 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
43 {
44 ({ uuid: videoPlaylistUUID } = await servers[0].playlists.create({
45 attributes: {
46 displayName: 'my super playlist',
47 privacy: VideoPlaylistPrivacy.PUBLIC,
48 description: 'my super description',
49 videoChannelId: servers[0].store.channel.id
50 }
51 }))
52 }
53
54 for (let i = 0; i < 10; i++) {
55 const video = await servers[0].videos.upload({ attributes: { name: 'default video ' + i } })
56 await servers[0].playlists.addElement({ playlistId: videoPlaylistUUID, attributes: { videoId: video.id } })
57 }
58
59 const { data } = await servers[0].videos.list()
60 videoUUID = data[0].uuid
61
62 await servers[0].config.updateCustomSubConfig({
63 newConfig: {
64 live: { enabled: true },
65 signup: { enabled: true },
66 import: {
67 videos: {
68 http: { enabled: true },
69 torrent: { enabled: true }
70 }
71 }
72 }
73 })
74
75 // Root subscribes to itself
76 await servers[0].subscriptions.add({ targetUri: 'root_channel@' + servers[0].host })
77 })
78
79 describe('Videos', function () {
80
81 it('Should run filter:api.videos.list.params', async function () {
82 const { data } = await servers[0].videos.list({ start: 0, count: 2 })
83
84 // 2 plugins do +1 to the count parameter
85 expect(data).to.have.lengthOf(4)
86 })
87
88 it('Should run filter:api.videos.list.result', async function () {
89 const { total } = await servers[0].videos.list({ start: 0, count: 0 })
90
91 // Plugin do +1 to the total result
92 expect(total).to.equal(11)
93 })
94
95 it('Should run filter:api.video-playlist.videos.list.params', async function () {
96 const { data } = await servers[0].playlists.listVideos({
97 count: 2,
98 playlistId: videoPlaylistUUID
99 })
100
101 // 1 plugin do +1 to the count parameter
102 expect(data).to.have.lengthOf(3)
103 })
104
105 it('Should run filter:api.video-playlist.videos.list.result', async function () {
106 const { total } = await servers[0].playlists.listVideos({
107 count: 0,
108 playlistId: videoPlaylistUUID
109 })
110
111 // Plugin do +1 to the total result
112 expect(total).to.equal(11)
113 })
114
115 it('Should run filter:api.accounts.videos.list.params', async function () {
116 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
117
118 // 1 plugin do +1 to the count parameter
119 expect(data).to.have.lengthOf(3)
120 })
121
122 it('Should run filter:api.accounts.videos.list.result', async function () {
123 const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
124
125 // Plugin do +2 to the total result
126 expect(total).to.equal(12)
127 })
128
129 it('Should run filter:api.video-channels.videos.list.params', async function () {
130 const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
131
132 // 1 plugin do +3 to the count parameter
133 expect(data).to.have.lengthOf(5)
134 })
135
136 it('Should run filter:api.video-channels.videos.list.result', async function () {
137 const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
138
139 // Plugin do +3 to the total result
140 expect(total).to.equal(13)
141 })
142
143 it('Should run filter:api.user.me.videos.list.params', async function () {
144 const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
145
146 // 1 plugin do +4 to the count parameter
147 expect(data).to.have.lengthOf(6)
148 })
149
150 it('Should run filter:api.user.me.videos.list.result', async function () {
151 const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
152
153 // Plugin do +4 to the total result
154 expect(total).to.equal(14)
155 })
156
157 it('Should run filter:api.user.me.subscription-videos.list.params', async function () {
158 const { data } = await servers[0].videos.listMySubscriptionVideos({ start: 0, count: 2 })
159
160 // 1 plugin do +1 to the count parameter
161 expect(data).to.have.lengthOf(3)
162 })
163
164 it('Should run filter:api.user.me.subscription-videos.list.result', async function () {
165 const { total } = await servers[0].videos.listMySubscriptionVideos({ start: 0, count: 2 })
166
167 // Plugin do +4 to the total result
168 expect(total).to.equal(14)
169 })
170
171 it('Should run filter:api.video.get.result', async function () {
172 const video = await servers[0].videos.get({ id: videoUUID })
173 expect(video.name).to.contain('<3')
174 })
175 })
176
177 describe('Video/live/import accept', function () {
178
179 it('Should run filter:api.video.upload.accept.result', async function () {
180 await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
181 })
182
183 it('Should run filter:api.live-video.create.accept.result', async function () {
184 const attributes = {
185 name: 'video with bad word',
186 privacy: VideoPrivacy.PUBLIC,
187 channelId: servers[0].store.channel.id
188 }
189
190 await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
191 })
192
193 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
194 const attributes = {
195 name: 'normal title',
196 privacy: VideoPrivacy.PUBLIC,
197 channelId: servers[0].store.channel.id,
198 targetUrl: FIXTURE_URLS.goodVideo + 'bad'
199 }
200 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
201 })
202
203 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
204 const attributes = {
205 name: 'bad torrent',
206 privacy: VideoPrivacy.PUBLIC,
207 channelId: servers[0].store.channel.id,
208 torrentfile: 'video-720p.torrent' as any
209 }
210 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
211 })
212
213 it('Should run filter:api.video.post-import-url.accept.result', async function () {
214 this.timeout(60000)
215
216 let videoImportId: number
217
218 {
219 const attributes = {
220 name: 'title with bad word',
221 privacy: VideoPrivacy.PUBLIC,
222 channelId: servers[0].store.channel.id,
223 targetUrl: FIXTURE_URLS.goodVideo
224 }
225 const body = await servers[0].imports.importVideo({ attributes })
226 videoImportId = body.id
227 }
228
229 await waitJobs(servers)
230
231 {
232 const body = await servers[0].imports.getMyVideoImports()
233 const videoImports = body.data
234
235 const videoImport = videoImports.find(i => i.id === videoImportId)
236
237 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
238 expect(videoImport.state.label).to.equal('Rejected')
239 }
240 })
241
242 it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
243 this.timeout(60000)
244
245 let videoImportId: number
246
247 {
248 const attributes = {
249 name: 'title with bad word',
250 privacy: VideoPrivacy.PUBLIC,
251 channelId: servers[0].store.channel.id,
252 torrentfile: 'video-720p.torrent' as any
253 }
254 const body = await servers[0].imports.importVideo({ attributes })
255 videoImportId = body.id
256 }
257
258 await waitJobs(servers)
259
260 {
261 const { data: videoImports } = await servers[0].imports.getMyVideoImports()
262
263 const videoImport = videoImports.find(i => i.id === videoImportId)
264
265 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
266 expect(videoImport.state.label).to.equal('Rejected')
267 }
268 })
269 })
270
271 describe('Video comments accept', function () {
272
273 it('Should run filter:api.video-thread.create.accept.result', async function () {
274 await servers[0].comments.createThread({
275 videoId: videoUUID,
276 text: 'comment with bad word',
277 expectedStatus: HttpStatusCode.FORBIDDEN_403
278 })
279 })
280
281 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
282 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
283 threadId = created.id
284
285 await servers[0].comments.addReply({
286 videoId: videoUUID,
287 toCommentId: threadId,
288 text: 'comment with bad word',
289 expectedStatus: HttpStatusCode.FORBIDDEN_403
290 })
291 await servers[0].comments.addReply({
292 videoId: videoUUID,
293 toCommentId: threadId,
294 text: 'comment with good word',
295 expectedStatus: HttpStatusCode.OK_200
296 })
297 })
298
299 it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a thread creation', async function () {
300 this.timeout(30000)
301
302 await servers[1].comments.createThread({ videoId: videoUUID, text: 'comment with bad word' })
303
304 await waitJobs(servers)
305
306 {
307 const thread = await servers[0].comments.listThreads({ videoId: videoUUID })
308 expect(thread.data).to.have.lengthOf(1)
309 expect(thread.data[0].text).to.not.include(' bad ')
310 }
311
312 {
313 const thread = await servers[1].comments.listThreads({ videoId: videoUUID })
314 expect(thread.data).to.have.lengthOf(2)
315 }
316 })
317
318 it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a reply creation', async function () {
319 this.timeout(30000)
320
321 const { data } = await servers[1].comments.listThreads({ videoId: videoUUID })
322 const threadIdServer2 = data.find(t => t.text === 'thread').id
323
324 await servers[1].comments.addReply({
325 videoId: videoUUID,
326 toCommentId: threadIdServer2,
327 text: 'comment with bad word'
328 })
329
330 await waitJobs(servers)
331
332 {
333 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
334 expect(tree.children).to.have.lengthOf(1)
335 expect(tree.children[0].comment.text).to.not.include(' bad ')
336 }
337
338 {
339 const tree = await servers[1].comments.getThread({ videoId: videoUUID, threadId: threadIdServer2 })
340 expect(tree.children).to.have.lengthOf(2)
341 }
342 })
343 })
344
345 describe('Video comments', function () {
346
347 it('Should run filter:api.video-threads.list.params', async function () {
348 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
349
350 // our plugin do +1 to the count parameter
351 expect(data).to.have.lengthOf(1)
352 })
353
354 it('Should run filter:api.video-threads.list.result', async function () {
355 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
356
357 // Plugin do +1 to the total result
358 expect(total).to.equal(2)
359 })
360
361 it('Should run filter:api.video-thread-comments.list.params')
362
363 it('Should run filter:api.video-thread-comments.list.result', async function () {
364 const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
365
366 expect(thread.comment.text.endsWith(' <3')).to.be.true
367 })
368
369 it('Should run filter:api.overviews.videos.list.{params,result}', async function () {
370 await servers[0].overviews.getVideos({ page: 1 })
371
372 // 3 because we get 3 samples per page
373 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
374 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
375 })
376 })
377
378 describe('filter:video.auto-blacklist.result', function () {
379
380 async function checkIsBlacklisted (id: number | string, value: boolean) {
381 const video = await servers[0].videos.getWithToken({ id })
382 expect(video.blacklisted).to.equal(value)
383 }
384
385 it('Should blacklist on upload', async function () {
386 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } })
387 await checkIsBlacklisted(uuid, true)
388 })
389
390 it('Should blacklist on import', async function () {
391 this.timeout(15000)
392
393 const attributes = {
394 name: 'video please blacklist me',
395 targetUrl: FIXTURE_URLS.goodVideo,
396 channelId: servers[0].store.channel.id
397 }
398 const body = await servers[0].imports.importVideo({ attributes })
399 await checkIsBlacklisted(body.video.uuid, true)
400 })
401
402 it('Should blacklist on update', async function () {
403 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
404 await checkIsBlacklisted(uuid, false)
405
406 await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
407 await checkIsBlacklisted(uuid, true)
408 })
409
410 it('Should blacklist on remote upload', async function () {
411 this.timeout(120000)
412
413 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } })
414 await waitJobs(servers)
415
416 await checkIsBlacklisted(uuid, true)
417 })
418
419 it('Should blacklist on remote update', async function () {
420 this.timeout(120000)
421
422 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } })
423 await waitJobs(servers)
424
425 await checkIsBlacklisted(uuid, false)
426
427 await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
428 await waitJobs(servers)
429
430 await checkIsBlacklisted(uuid, true)
431 })
432 })
433
434 describe('Should run filter:api.user.signup.allowed.result', function () {
435
436 before(async function () {
437 await servers[0].config.updateExistingSubConfig({ newConfig: { signup: { requiresApproval: false } } })
438 })
439
440 it('Should run on config endpoint', async function () {
441 const body = await servers[0].config.getConfig()
442 expect(body.signup.allowed).to.be.true
443 })
444
445 it('Should allow a signup', async function () {
446 await servers[0].registrations.register({ username: 'john1' })
447 })
448
449 it('Should not allow a signup', async function () {
450 const res = await servers[0].registrations.register({
451 username: 'jma 1',
452 expectedStatus: HttpStatusCode.FORBIDDEN_403
453 })
454
455 expect(res.body.error).to.equal('No jma 1')
456 })
457 })
458
459 describe('Should run filter:api.user.request-signup.allowed.result', function () {
460
461 before(async function () {
462 await servers[0].config.updateExistingSubConfig({ newConfig: { signup: { requiresApproval: true } } })
463 })
464
465 it('Should run on config endpoint', async function () {
466 const body = await servers[0].config.getConfig()
467 expect(body.signup.allowed).to.be.true
468 })
469
470 it('Should allow a signup request', async function () {
471 await servers[0].registrations.requestRegistration({ username: 'john2', registrationReason: 'tt' })
472 })
473
474 it('Should not allow a signup request', async function () {
475 const body = await servers[0].registrations.requestRegistration({
476 username: 'jma 2',
477 registrationReason: 'tt',
478 expectedStatus: HttpStatusCode.FORBIDDEN_403
479 })
480
481 expect((body as unknown as PeerTubeProblemDocument).error).to.equal('No jma 2')
482 })
483 })
484
485 describe('Download hooks', function () {
486 const downloadVideos: VideoDetails[] = []
487 let downloadVideo2Token: string
488
489 before(async function () {
490 this.timeout(120000)
491
492 await servers[0].config.updateCustomSubConfig({
493 newConfig: {
494 transcoding: {
495 webtorrent: {
496 enabled: true
497 },
498 hls: {
499 enabled: true
500 }
501 }
502 }
503 })
504
505 const uuids: string[] = []
506
507 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
508 const uuid = (await servers[0].videos.quickUpload({ name })).uuid
509 uuids.push(uuid)
510 }
511
512 await waitJobs(servers)
513
514 for (const uuid of uuids) {
515 downloadVideos.push(await servers[0].videos.get({ id: uuid }))
516 }
517
518 downloadVideo2Token = await servers[0].videoToken.getVideoFileToken({ videoId: downloadVideos[2].uuid })
519 })
520
521 it('Should run filter:api.download.torrent.allowed.result', async function () {
522 const res = await makeRawRequest({ url: downloadVideos[0].files[0].torrentDownloadUrl, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
523 expect(res.body.error).to.equal('Liu Bei')
524
525 await makeRawRequest({ url: downloadVideos[1].files[0].torrentDownloadUrl, expectedStatus: HttpStatusCode.OK_200 })
526 await makeRawRequest({ url: downloadVideos[2].files[0].torrentDownloadUrl, expectedStatus: HttpStatusCode.OK_200 })
527 })
528
529 it('Should run filter:api.download.video.allowed.result', async function () {
530 {
531 const refused = downloadVideos[1].files[0].fileDownloadUrl
532 const allowed = [
533 downloadVideos[0].files[0].fileDownloadUrl,
534 downloadVideos[2].files[0].fileDownloadUrl
535 ]
536
537 const res = await makeRawRequest({ url: refused, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
538 expect(res.body.error).to.equal('Cao Cao')
539
540 for (const url of allowed) {
541 await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
542 await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
543 }
544 }
545
546 {
547 const refused = downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl
548
549 const allowed = [
550 downloadVideos[2].files[0].fileDownloadUrl,
551 downloadVideos[0].streamingPlaylists[0].files[0].fileDownloadUrl,
552 downloadVideos[1].streamingPlaylists[0].files[0].fileDownloadUrl
553 ]
554
555 // Only streaming playlist is refuse
556 const res = await makeRawRequest({ url: refused, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
557 expect(res.body.error).to.equal('Sun Jian')
558
559 // But not we there is a user in res
560 await makeRawRequest({ url: refused, token: servers[0].accessToken, expectedStatus: HttpStatusCode.OK_200 })
561 await makeRawRequest({ url: refused, query: { videoFileToken: downloadVideo2Token }, expectedStatus: HttpStatusCode.OK_200 })
562
563 // Other files work
564 for (const url of allowed) {
565 await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 })
566 }
567 }
568 })
569 })
570
571 describe('Embed filters', function () {
572 const embedVideos: VideoDetails[] = []
573 const embedPlaylists: VideoPlaylist[] = []
574
575 before(async function () {
576 this.timeout(60000)
577
578 await servers[0].config.disableTranscoding()
579
580 for (const name of [ 'bad embed', 'good embed' ]) {
581 {
582 const uuid = (await servers[0].videos.quickUpload({ name })).uuid
583 embedVideos.push(await servers[0].videos.get({ id: uuid }))
584 }
585
586 {
587 const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC }
588 const { id } = await servers[0].playlists.create({ attributes })
589
590 const playlist = await servers[0].playlists.get({ playlistId: id })
591 embedPlaylists.push(playlist)
592 }
593 }
594 })
595
596 it('Should run filter:html.embed.video.allowed.result', async function () {
597 const res = await makeGetRequest({ url: servers[0].url, path: embedVideos[0].embedPath, expectedStatus: HttpStatusCode.OK_200 })
598 expect(res.text).to.equal('Lu Bu')
599 })
600
601 it('Should run filter:html.embed.video-playlist.allowed.result', async function () {
602 const res = await makeGetRequest({ url: servers[0].url, path: embedPlaylists[0].embedPath, expectedStatus: HttpStatusCode.OK_200 })
603 expect(res.text).to.equal('Diao Chan')
604 })
605 })
606
607 describe('Search filters', function () {
608
609 before(async function () {
610 await servers[0].config.updateCustomSubConfig({
611 newConfig: {
612 search: {
613 searchIndex: {
614 enabled: true,
615 isDefaultSearch: false,
616 disableLocalSearch: false
617 }
618 }
619 }
620 })
621 })
622
623 it('Should run filter:api.search.videos.local.list.{params,result}', async function () {
624 await servers[0].search.advancedVideoSearch({
625 search: {
626 search: 'Sun Quan'
627 }
628 })
629
630 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
631 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
632 })
633
634 it('Should run filter:api.search.videos.index.list.{params,result}', async function () {
635 await servers[0].search.advancedVideoSearch({
636 search: {
637 search: 'Sun Quan',
638 searchTarget: 'search-index'
639 }
640 })
641
642 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
643 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
644 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1)
645 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1)
646 })
647
648 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {
649 await servers[0].search.advancedChannelSearch({
650 search: {
651 search: 'Sun Ce'
652 }
653 })
654
655 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
656 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
657 })
658
659 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {
660 await servers[0].search.advancedChannelSearch({
661 search: {
662 search: 'Sun Ce',
663 searchTarget: 'search-index'
664 }
665 })
666
667 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
668 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
669 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1)
670 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1)
671 })
672
673 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () {
674 await servers[0].search.advancedPlaylistSearch({
675 search: {
676 search: 'Sun Jian'
677 }
678 })
679
680 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
681 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
682 })
683
684 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () {
685 await servers[0].search.advancedPlaylistSearch({
686 search: {
687 search: 'Sun Jian',
688 searchTarget: 'search-index'
689 }
690 })
691
692 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
693 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
694 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1)
695 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1)
696 })
697 })
698
699 describe('Upload/import/live attributes filters', function () {
700
701 before(async function () {
702 await servers[0].config.enableLive({ transcoding: false, allowReplay: false })
703 await servers[0].config.enableImports()
704 await servers[0].config.disableTranscoding()
705 })
706
707 it('Should run filter:api.video.upload.video-attribute.result', async function () {
708 for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
709 const { id } = await servers[0].videos.upload({ attributes: { name: 'video', description: 'upload' }, mode })
710
711 const video = await servers[0].videos.get({ id })
712 expect(video.description).to.equal('upload - filter:api.video.upload.video-attribute.result')
713 }
714 })
715
716 it('Should run filter:api.video.import-url.video-attribute.result', async function () {
717 const attributes = {
718 name: 'video',
719 description: 'import url',
720 channelId: servers[0].store.channel.id,
721 targetUrl: FIXTURE_URLS.goodVideo,
722 privacy: VideoPrivacy.PUBLIC
723 }
724 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
725
726 const video = await servers[0].videos.get({ id })
727 expect(video.description).to.equal('import url - filter:api.video.import-url.video-attribute.result')
728 })
729
730 it('Should run filter:api.video.import-torrent.video-attribute.result', async function () {
731 const attributes = {
732 name: 'video',
733 description: 'import torrent',
734 channelId: servers[0].store.channel.id,
735 magnetUri: FIXTURE_URLS.magnet,
736 privacy: VideoPrivacy.PUBLIC
737 }
738 const { video: { id } } = await servers[0].imports.importVideo({ attributes })
739
740 const video = await servers[0].videos.get({ id })
741 expect(video.description).to.equal('import torrent - filter:api.video.import-torrent.video-attribute.result')
742 })
743
744 it('Should run filter:api.video.live.video-attribute.result', async function () {
745 const fields = {
746 name: 'live',
747 description: 'live',
748 channelId: servers[0].store.channel.id,
749 privacy: VideoPrivacy.PUBLIC
750 }
751 const { id } = await servers[0].live.create({ fields })
752
753 const video = await servers[0].videos.get({ id })
754 expect(video.description).to.equal('live - filter:api.video.live.video-attribute.result')
755 })
756 })
757
758 describe('Stats filters', function () {
759
760 it('Should run filter:api.server.stats.get.result', async function () {
761 const data = await servers[0].stats.get()
762
763 expect((data as any).customStats).to.equal(14)
764 })
765
766 })
767
768 describe('Job queue filters', function () {
769 let videoUUID: string
770
771 before(async function () {
772 this.timeout(120_000)
773
774 await servers[0].config.enableMinimumTranscoding()
775 const { uuid } = await servers[0].videos.quickUpload({ name: 'studio' })
776
777 const video = await servers[0].videos.get({ id: uuid })
778 expect(video.duration).at.least(2)
779 videoUUID = video.uuid
780
781 await waitJobs(servers)
782
783 await servers[0].config.enableStudio()
784 })
785
786 it('Should run filter:job-queue.process.params', async function () {
787 this.timeout(120_000)
788
789 await servers[0].videoStudio.createEditionTasks({
790 videoId: videoUUID,
791 tasks: [
792 {
793 name: 'add-intro',
794 options: {
795 file: 'video_very_short_240p.mp4'
796 }
797 }
798 ]
799 })
800
801 await waitJobs(servers)
802
803 await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.params', 1, false)
804
805 const video = await servers[0].videos.get({ id: videoUUID })
806 expect(video.duration).at.most(2)
807 })
808
809 it('Should run filter:job-queue.process.result', async function () {
810 await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.result', 1, false)
811 })
812 })
813
814 describe('Transcoding filters', async function () {
815
816 it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () {
817 const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' })
818
819 await waitJobs(servers)
820
821 const video = await servers[0].videos.get({ id: uuid })
822 expect(video.files).to.have.lengthOf(2)
823 expect(video.files.find(f => f.resolution.id === 100 as any)).to.exist
824 })
825 })
826
827 describe('Video channel filters', async function () {
828
829 it('Should run filter:api.video-channels.list.params', async function () {
830 const { data } = await servers[0].channels.list({ start: 0, count: 0 })
831
832 // plugin do +1 to the count parameter
833 expect(data).to.have.lengthOf(1)
834 })
835
836 it('Should run filter:api.video-channels.list.result', async function () {
837 const { total } = await servers[0].channels.list({ start: 0, count: 1 })
838
839 // plugin do +1 to the total parameter
840 expect(total).to.equal(4)
841 })
842
843 it('Should run filter:api.video-channel.get.result', async function () {
844 const channel = await servers[0].channels.get({ channelName: 'root_channel' })
845 expect(channel.displayName).to.equal('Main root channel <3')
846 })
847 })
848
849 after(async function () {
850 await cleanupTests(servers)
851 })
852 })