]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/moderation/abuses.ts
Increase timeout for moderation notifications
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / moderation / abuses.ts
CommitLineData
d95d1559 1
57f6896f
C
2import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
3import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
4
5function reportAbuse (options: {
6 url: string
7 token: string
8
9 reason: string
10
11 accountId?: number
12 videoId?: number
13 commentId?: number
14
15 predefinedReasons?: AbusePredefinedReasonsString[]
16
17 startAt?: number
18 endAt?: number
19
20 statusCodeExpected?: number
21}) {
22 const path = '/api/v1/abuses'
23
24 const video = options.videoId ? {
25 id: options.videoId,
26 startAt: options.startAt,
27 endAt: options.endAt
28 } : undefined
29
30 const comment = options.commentId ? {
31 id: options.commentId
32 } : undefined
33
34 const account = options.accountId ? {
35 id: options.accountId
36 } : undefined
37
38 const body = {
39 account,
40 video,
41 comment,
42
43 reason: options.reason,
44 predefinedReasons: options.predefinedReasons
45 }
46
47 return makePostBodyRequest({
48 url: options.url,
49 path,
50 token: options.token,
51
52 fields: body,
53 statusCodeExpected: options.statusCodeExpected || 200
54 })
d95d1559
C
55}
56
57function getAbusesList (options: {
58 url: string
59 token: string
310b5219
C
60
61 start?: number
62 count?: number
63 sort?: string
64
d95d1559
C
65 id?: number
66 predefinedReason?: AbusePredefinedReasonsString
67 search?: string
310b5219 68 filter?: AbuseFilter
d95d1559
C
69 state?: AbuseState
70 videoIs?: AbuseVideoIs
71 searchReporter?: string
72 searchReportee?: string
73 searchVideo?: string
74 searchVideoChannel?: string
75}) {
76 const {
77 url,
78 token,
310b5219
C
79 start,
80 count,
81 sort,
d95d1559
C
82 id,
83 predefinedReason,
84 search,
57f6896f 85 filter,
d95d1559
C
86 state,
87 videoIs,
88 searchReporter,
89 searchReportee,
90 searchVideo,
91 searchVideoChannel
92 } = options
57f6896f 93 const path = '/api/v1/abuses'
d95d1559
C
94
95 const query = {
d95d1559
C
96 id,
97 predefinedReason,
98 search,
99 state,
57f6896f 100 filter,
d95d1559 101 videoIs,
310b5219
C
102 start,
103 count,
104 sort: sort || 'createdAt',
d95d1559
C
105 searchReporter,
106 searchReportee,
107 searchVideo,
108 searchVideoChannel
109 }
110
111 return makeGetRequest({
112 url,
113 path,
114 token,
115 query,
116 statusCodeExpected: 200
117 })
118}
119
120function updateAbuse (
121 url: string,
122 token: string,
57f6896f 123 abuseId: number,
d95d1559
C
124 body: AbuseUpdate,
125 statusCodeExpected = 204
126) {
57f6896f 127 const path = '/api/v1/abuses/' + abuseId
d95d1559
C
128
129 return makePutBodyRequest({
130 url,
131 token,
132 path,
133 fields: body,
134 statusCodeExpected
135 })
136}
137
57f6896f
C
138function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) {
139 const path = '/api/v1/abuses/' + abuseId
d95d1559
C
140
141 return makeDeleteRequest({
142 url,
143 token,
144 path,
145 statusCodeExpected
146 })
147}
148
149// ---------------------------------------------------------------------------
150
151export {
152 reportAbuse,
153 getAbusesList,
154 updateAbuse,
155 deleteAbuse
156}