aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/moderation/abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils/moderation/abuses.ts')
-rw-r--r--shared/extra-utils/moderation/abuses.ts156
1 files changed, 156 insertions, 0 deletions
diff --git a/shared/extra-utils/moderation/abuses.ts b/shared/extra-utils/moderation/abuses.ts
new file mode 100644
index 000000000..62af9556e
--- /dev/null
+++ b/shared/extra-utils/moderation/abuses.ts
@@ -0,0 +1,156 @@
1
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 })
55}
56
57function getAbusesList (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: 200
117 })
118}
119
120function updateAbuse (
121 url: string,
122 token: string,
123 abuseId: number,
124 body: AbuseUpdate,
125 statusCodeExpected = 204
126) {
127 const path = '/api/v1/abuses/' + abuseId
128
129 return makePutBodyRequest({
130 url,
131 token,
132 path,
133 fields: body,
134 statusCodeExpected
135 })
136}
137
138function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) {
139 const path = '/api/v1/abuses/' + abuseId
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}