aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/moderation/abuses.ts88
1 files changed, 61 insertions, 27 deletions
diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts
index 48a51e2b8..1af703f92 100644
--- a/shared/extra-utils/moderation/abuses.ts
+++ b/shared/extra-utils/moderation/abuses.ts
@@ -1,25 +1,57 @@
1import * as request from 'supertest'
2import { AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
3import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests'
4 1
5function reportAbuse ( 2import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models'
6 url: string, 3import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
7 token: string, 4
8 videoId: number | string, 5function reportAbuse (options: {
9 reason: string, 6 url: string
10 predefinedReasons?: AbusePredefinedReasonsString[], 7 token: string
11 startAt?: number, 8
12 endAt?: number, 9 reason: string
13 specialStatus = 200 10
14) { 11 accountId?: number
15 const path = '/api/v1/videos/' + videoId + '/abuse' 12 videoId?: number
16 13 commentId?: number
17 return request(url) 14
18 .post(path) 15 predefinedReasons?: AbusePredefinedReasonsString[]
19 .set('Accept', 'application/json') 16
20 .set('Authorization', 'Bearer ' + token) 17 startAt?: number
21 .send({ reason, predefinedReasons, startAt, endAt }) 18 endAt?: number
22 .expect(specialStatus) 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 })
23} 55}
24 56
25function getAbusesList (options: { 57function getAbusesList (options: {
@@ -28,6 +60,7 @@ function getAbusesList (options: {
28 id?: number 60 id?: number
29 predefinedReason?: AbusePredefinedReasonsString 61 predefinedReason?: AbusePredefinedReasonsString
30 search?: string 62 search?: string
63 filter?: AbuseFilter,
31 state?: AbuseState 64 state?: AbuseState
32 videoIs?: AbuseVideoIs 65 videoIs?: AbuseVideoIs
33 searchReporter?: string 66 searchReporter?: string
@@ -41,6 +74,7 @@ function getAbusesList (options: {
41 id, 74 id,
42 predefinedReason, 75 predefinedReason,
43 search, 76 search,
77 filter,
44 state, 78 state,
45 videoIs, 79 videoIs,
46 searchReporter, 80 searchReporter,
@@ -48,7 +82,7 @@ function getAbusesList (options: {
48 searchVideo, 82 searchVideo,
49 searchVideoChannel 83 searchVideoChannel
50 } = options 84 } = options
51 const path = '/api/v1/videos/abuse' 85 const path = '/api/v1/abuses'
52 86
53 const query = { 87 const query = {
54 sort: 'createdAt', 88 sort: 'createdAt',
@@ -56,6 +90,7 @@ function getAbusesList (options: {
56 predefinedReason, 90 predefinedReason,
57 search, 91 search,
58 state, 92 state,
93 filter,
59 videoIs, 94 videoIs,
60 searchReporter, 95 searchReporter,
61 searchReportee, 96 searchReportee,
@@ -75,12 +110,11 @@ function getAbusesList (options: {
75function updateAbuse ( 110function updateAbuse (
76 url: string, 111 url: string,
77 token: string, 112 token: string,
78 videoId: string | number, 113 abuseId: number,
79 videoAbuseId: number,
80 body: AbuseUpdate, 114 body: AbuseUpdate,
81 statusCodeExpected = 204 115 statusCodeExpected = 204
82) { 116) {
83 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId 117 const path = '/api/v1/abuses/' + abuseId
84 118
85 return makePutBodyRequest({ 119 return makePutBodyRequest({
86 url, 120 url,
@@ -91,8 +125,8 @@ function updateAbuse (
91 }) 125 })
92} 126}
93 127
94function deleteAbuse (url: string, token: string, videoId: string | number, videoAbuseId: number, statusCodeExpected = 204) { 128function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) {
95 const path = '/api/v1/videos/' + videoId + '/abuse/' + videoAbuseId 129 const path = '/api/v1/abuses/' + abuseId
96 130
97 return makeDeleteRequest({ 131 return makeDeleteRequest({
98 url, 132 url,