Move to eslint
[oweals/peertube.git] / shared / extra-utils / users / blocklist.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests'
4
5 function getAccountBlocklistByAccount (
6   url: string,
7   token: string,
8   start: number,
9   count: number,
10   sort = '-createdAt',
11   statusCodeExpected = 200
12 ) {
13   const path = '/api/v1/users/me/blocklist/accounts'
14
15   return makeGetRequest({
16     url,
17     token,
18     query: { start, count, sort },
19     path,
20     statusCodeExpected
21   })
22 }
23
24 function addAccountToAccountBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) {
25   const path = '/api/v1/users/me/blocklist/accounts'
26
27   return makePostBodyRequest({
28     url,
29     path,
30     token,
31     fields: {
32       accountName: accountToBlock
33     },
34     statusCodeExpected
35   })
36 }
37
38 function removeAccountFromAccountBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) {
39   const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock
40
41   return makeDeleteRequest({
42     url,
43     path,
44     token,
45     statusCodeExpected
46   })
47 }
48
49 function getServerBlocklistByAccount (
50   url: string,
51   token: string,
52   start: number,
53   count: number,
54   sort = '-createdAt',
55   statusCodeExpected = 200
56 ) {
57   const path = '/api/v1/users/me/blocklist/servers'
58
59   return makeGetRequest({
60     url,
61     token,
62     query: { start, count, sort },
63     path,
64     statusCodeExpected
65   })
66 }
67
68 function addServerToAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) {
69   const path = '/api/v1/users/me/blocklist/servers'
70
71   return makePostBodyRequest({
72     url,
73     path,
74     token,
75     fields: {
76       host: serverToBlock
77     },
78     statusCodeExpected
79   })
80 }
81
82 function removeServerFromAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) {
83   const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock
84
85   return makeDeleteRequest({
86     url,
87     path,
88     token,
89     statusCodeExpected
90   })
91 }
92
93 function getAccountBlocklistByServer (
94   url: string,
95   token: string,
96   start: number,
97   count: number,
98   sort = '-createdAt',
99   statusCodeExpected = 200
100 ) {
101   const path = '/api/v1/server/blocklist/accounts'
102
103   return makeGetRequest({
104     url,
105     token,
106     query: { start, count, sort },
107     path,
108     statusCodeExpected
109   })
110 }
111
112 function addAccountToServerBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) {
113   const path = '/api/v1/server/blocklist/accounts'
114
115   return makePostBodyRequest({
116     url,
117     path,
118     token,
119     fields: {
120       accountName: accountToBlock
121     },
122     statusCodeExpected
123   })
124 }
125
126 function removeAccountFromServerBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) {
127   const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock
128
129   return makeDeleteRequest({
130     url,
131     path,
132     token,
133     statusCodeExpected
134   })
135 }
136
137 function getServerBlocklistByServer (
138   url: string,
139   token: string,
140   start: number,
141   count: number,
142   sort = '-createdAt',
143   statusCodeExpected = 200
144 ) {
145   const path = '/api/v1/server/blocklist/servers'
146
147   return makeGetRequest({
148     url,
149     token,
150     query: { start, count, sort },
151     path,
152     statusCodeExpected
153   })
154 }
155
156 function addServerToServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) {
157   const path = '/api/v1/server/blocklist/servers'
158
159   return makePostBodyRequest({
160     url,
161     path,
162     token,
163     fields: {
164       host: serverToBlock
165     },
166     statusCodeExpected
167   })
168 }
169
170 function removeServerFromServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) {
171   const path = '/api/v1/server/blocklist/servers/' + serverToBlock
172
173   return makeDeleteRequest({
174     url,
175     path,
176     token,
177     statusCodeExpected
178   })
179 }
180
181 // ---------------------------------------------------------------------------
182
183 export {
184   getAccountBlocklistByAccount,
185   addAccountToAccountBlocklist,
186   removeAccountFromAccountBlocklist,
187   getServerBlocklistByAccount,
188   addServerToAccountBlocklist,
189   removeServerFromAccountBlocklist,
190
191   getAccountBlocklistByServer,
192   addAccountToServerBlocklist,
193   removeAccountFromServerBlocklist,
194   getServerBlocklistByServer,
195   addServerToServerBlocklist,
196   removeServerFromServerBlocklist
197 }