]>
Commit | Line | Data |
---|---|---|
d95d1559 | 1 | |
57f6896f C |
2 | import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, AbuseUpdate, AbuseVideoIs } from '@shared/models' |
3 | import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | |
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 || 200 | |
54 | }) | |
d95d1559 C |
55 | } |
56 | ||
57 | function getAbusesList (options: { | |
58 | url: string | |
59 | token: string | |
60 | id?: number | |
61 | predefinedReason?: AbusePredefinedReasonsString | |
62 | search?: string | |
57f6896f | 63 | filter?: AbuseFilter, |
d95d1559 C |
64 | state?: AbuseState |
65 | videoIs?: AbuseVideoIs | |
66 | searchReporter?: string | |
67 | searchReportee?: string | |
68 | searchVideo?: string | |
69 | searchVideoChannel?: string | |
70 | }) { | |
71 | const { | |
72 | url, | |
73 | token, | |
74 | id, | |
75 | predefinedReason, | |
76 | search, | |
57f6896f | 77 | filter, |
d95d1559 C |
78 | state, |
79 | videoIs, | |
80 | searchReporter, | |
81 | searchReportee, | |
82 | searchVideo, | |
83 | searchVideoChannel | |
84 | } = options | |
57f6896f | 85 | const path = '/api/v1/abuses' |
d95d1559 C |
86 | |
87 | const query = { | |
88 | sort: 'createdAt', | |
89 | id, | |
90 | predefinedReason, | |
91 | search, | |
92 | state, | |
57f6896f | 93 | filter, |
d95d1559 C |
94 | videoIs, |
95 | searchReporter, | |
96 | searchReportee, | |
97 | searchVideo, | |
98 | searchVideoChannel | |
99 | } | |
100 | ||
101 | return makeGetRequest({ | |
102 | url, | |
103 | path, | |
104 | token, | |
105 | query, | |
106 | statusCodeExpected: 200 | |
107 | }) | |
108 | } | |
109 | ||
110 | function updateAbuse ( | |
111 | url: string, | |
112 | token: string, | |
57f6896f | 113 | abuseId: number, |
d95d1559 C |
114 | body: AbuseUpdate, |
115 | statusCodeExpected = 204 | |
116 | ) { | |
57f6896f | 117 | const path = '/api/v1/abuses/' + abuseId |
d95d1559 C |
118 | |
119 | return makePutBodyRequest({ | |
120 | url, | |
121 | token, | |
122 | path, | |
123 | fields: body, | |
124 | statusCodeExpected | |
125 | }) | |
126 | } | |
127 | ||
57f6896f C |
128 | function deleteAbuse (url: string, token: string, abuseId: number, statusCodeExpected = 204) { |
129 | const path = '/api/v1/abuses/' + abuseId | |
d95d1559 C |
130 | |
131 | return makeDeleteRequest({ | |
132 | url, | |
133 | token, | |
134 | path, | |
135 | statusCodeExpected | |
136 | }) | |
137 | } | |
138 | ||
139 | // --------------------------------------------------------------------------- | |
140 | ||
141 | export { | |
142 | reportAbuse, | |
143 | getAbusesList, | |
144 | updateAbuse, | |
145 | deleteAbuse | |
146 | } |