user-subscriptions.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests'
  2. import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
  3. function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
  4. const path = '/api/v1/users/me/subscriptions'
  5. return makePostBodyRequest({
  6. url,
  7. path,
  8. token,
  9. statusCodeExpected,
  10. fields: { uri: targetUri }
  11. })
  12. }
  13. function listUserSubscriptions (parameters: {
  14. url: string
  15. token: string
  16. sort?: string
  17. search?: string
  18. statusCodeExpected?: number
  19. }) {
  20. const { url, token, sort = '-createdAt', search, statusCodeExpected = HttpStatusCode.OK_200 } = parameters
  21. const path = '/api/v1/users/me/subscriptions'
  22. return makeGetRequest({
  23. url,
  24. path,
  25. token,
  26. statusCodeExpected,
  27. query: {
  28. sort,
  29. search
  30. }
  31. })
  32. }
  33. function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) {
  34. const path = '/api/v1/users/me/subscriptions/videos'
  35. return makeGetRequest({
  36. url,
  37. path,
  38. token,
  39. statusCodeExpected,
  40. query: { sort }
  41. })
  42. }
  43. function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.OK_200) {
  44. const path = '/api/v1/users/me/subscriptions/' + uri
  45. return makeGetRequest({
  46. url,
  47. path,
  48. token,
  49. statusCodeExpected
  50. })
  51. }
  52. function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
  53. const path = '/api/v1/users/me/subscriptions/' + uri
  54. return makeDeleteRequest({
  55. url,
  56. path,
  57. token,
  58. statusCodeExpected
  59. })
  60. }
  61. function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = HttpStatusCode.OK_200) {
  62. const path = '/api/v1/users/me/subscriptions/exist'
  63. return makeGetRequest({
  64. url,
  65. path,
  66. query: { 'uris[]': uris },
  67. token,
  68. statusCodeExpected
  69. })
  70. }
  71. // ---------------------------------------------------------------------------
  72. export {
  73. areSubscriptionsExist,
  74. addUserSubscription,
  75. listUserSubscriptions,
  76. getUserSubscription,
  77. listUserSubscriptionVideos,
  78. removeUserSubscription
  79. }