user-subscriptions.ts 1.9 KB

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