blocklist.ts 4.2 KB

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