]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/moderation/abuses.ts
Translated using Weblate (Portuguese (Brazil))
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / moderation / abuses.ts
1 import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
2 import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
3 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4
5 function 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 || HttpStatusCode.OK_200
54 })
55 }
56
57 function getAdminAbusesList (options: {
58 url: string
59 token: string
60
61 start?: number
62 count?: number
63 sort?: string
64
65 id?: number
66 predefinedReason?: AbusePredefinedReasonsString
67 search?: string
68 filter?: AbuseFilter
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,
79 start,
80 count,
81 sort,
82 id,
83 predefinedReason,
84 search,
85 filter,
86 state,
87 videoIs,
88 searchReporter,
89 searchReportee,
90 searchVideo,
91 searchVideoChannel
92 } = options
93 const path = '/api/v1/abuses'
94
95 const query = {
96 id,
97 predefinedReason,
98 search,
99 state,
100 filter,
101 videoIs,
102 start,
103 count,
104 sort: sort || 'createdAt',
105 searchReporter,
106 searchReportee,
107 searchVideo,
108 searchVideoChannel
109 }
110
111 return makeGetRequest({
112 url,
113 path,
114 token,
115 query,
116 statusCodeExpected: HttpStatusCode.OK_200
117 })
118 }
119
120 function getUserAbusesList (options: {
121 url: string
122 token: string
123
124 start?: number
125 count?: number
126 sort?: string
127
128 id?: number
129 search?: string
130 state?: AbuseState
131 }) {
132 const {
133 url,
134 token,
135 start,
136 count,
137 sort,
138 id,
139 search,
140 state
141 } = options
142 const path = '/api/v1/users/me/abuses'
143
144 const query = {
145 id,
146 search,
147 state,
148 start,
149 count,
150 sort: sort || 'createdAt'
151 }
152
153 return makeGetRequest({
154 url,
155 path,
156 token,
157 query,
158 statusCodeExpected: HttpStatusCode.OK_200
159 })
160 }
161
162 function updateAbuse (
163 url: string,
164 token: string,
165 abuseId: number,
166 body: AbuseUpdate,
167 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
168 ) {
169 const path = '/api/v1/abuses/' + abuseId
170
171 return makePutBodyRequest({
172 url,
173 token,
174 path,
175 fields: body,
176 statusCodeExpected
177 })
178 }
179
180 function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
181 const path = '/api/v1/abuses/' + abuseId
182
183 return makeDeleteRequest({
184 url,
185 token,
186 path,
187 statusCodeExpected
188 })
189 }
190
191 function listAbuseMessages (url: string, token: string, abuseId: number, statusCodeExpected = HttpStatusCode.OK_200) {
192 const path = '/api/v1/abuses/' + abuseId + '/messages'
193
194 return makeGetRequest({
195 url,
196 token,
197 path,
198 statusCodeExpected
199 })
200 }
201
202 function deleteAbuseMessage (
203 url: string,
204 token: string,
205 abuseId: number,
206 messageId: number,
207 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
208 ) {
209 const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId
210
211 return makeDeleteRequest({
212 url,
213 token,
214 path,
215 statusCodeExpected
216 })
217 }
218
219 function addAbuseMessage (url: string, token: string, abuseId: number, message: string, statusCodeExpected = HttpStatusCode.OK_200) {
220 const path = '/api/v1/abuses/' + abuseId + '/messages'
221
222 return makePostBodyRequest({
223 url,
224 token,
225 path,
226 fields: { message },
227 statusCodeExpected
228 })
229 }
230
231 // ---------------------------------------------------------------------------
232
233 export {
234 reportAbuse,
235 getAdminAbusesList,
236 updateAbuse,
237 deleteAbuse,
238 getUserAbusesList,
239 listAbuseMessages,
240 deleteAbuseMessage,
241 addAbuseMessage
242 }