]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/videos/video-abuses.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-abuses.ts
1 import * as request from 'supertest'
2 import { VideoAbuseUpdate } from '../../models/videos/abuse/video-abuse-update.model'
3 import { makeDeleteRequest, makePutBodyRequest, makeGetRequest } from '../requests/requests'
4 import { VideoAbuseState } from '@shared/models'
5 import { VideoAbuseVideoIs } from '@shared/models/videos/abuse/video-abuse-video-is.type'
6
7 function reportVideoAbuse (url: string, token: string, videoId: number | string, reason: string, specialStatus = 200) {
8 const path = '/api/v1/videos/' + videoId + '/abuse'
9
10 return request(url)
11 .post(path)
12 .set('Accept', 'application/json')
13 .set('Authorization', 'Bearer ' + token)
14 .send({ reason })
15 .expect(specialStatus)
16 }
17
18 function getVideoAbusesList (options: {
19 url: string
20 token: string
21 id?: number
22 search?: string
23 state?: VideoAbuseState
24 videoIs?: VideoAbuseVideoIs
25 searchReporter?: string
26 searchReportee?: string
27 searchVideo?: string
28 searchVideoChannel?: string
29 }) {
30 const {
31 url,
32 token,
33 id,
34 search,
35 state,
36 videoIs,
37 searchReporter,
38 searchReportee,
39 searchVideo,
40 searchVideoChannel
41 } = options
42 const path = '/api/v1/videos/abuse'
43
44 const query = {
45 sort: 'createdAt',
46 id,
47 search,
48 state,
49 videoIs,
50 searchReporter,
51 searchReportee,
52 searchVideo,
53 searchVideoChannel
54 }
55
56 return makeGetRequest({
57 url,
58 path,
59 token,
60 query,
61 statusCodeExpected: 200
62 })
63 }
64
65 function updateVideoAbuse (
66 url: string,
67 token: string,
68 videoId: string | number,
69 videoAbuseId: number,
70 body: VideoAbuseUpdate,
71 statusCodeExpected = 204
72 ) {
73 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
74
75 return makePutBodyRequest({
76 url,
77 token,
78 path,
79 fields: body,
80 statusCodeExpected
81 })
82 }
83
84 function deleteVideoAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) {
85 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId
86
87 return makeDeleteRequest({
88 url,
89 token,
90 path,
91 statusCodeExpected
92 })
93 }
94
95 // ---------------------------------------------------------------------------
96
97 export {
98 reportVideoAbuse,
99 getVideoAbusesList,
100 updateVideoAbuse,
101 deleteVideoAbuse
102 }