subscriptions-command.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { HttpStatusCode, ResultList, Video, VideoChannel } from '@shared/models'
  2. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  3. export class SubscriptionsCommand extends AbstractCommand {
  4. add (options: OverrideCommandOptions & {
  5. targetUri: string
  6. }) {
  7. const path = '/api/v1/users/me/subscriptions'
  8. return this.postBodyRequest({
  9. ...options,
  10. path,
  11. fields: { uri: options.targetUri },
  12. implicitToken: true,
  13. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  14. })
  15. }
  16. list (options: OverrideCommandOptions & {
  17. sort?: string // default -createdAt
  18. search?: string
  19. } = {}) {
  20. const { sort = '-createdAt', search } = options
  21. const path = '/api/v1/users/me/subscriptions'
  22. return this.getRequestBody<ResultList<VideoChannel>>({
  23. ...options,
  24. path,
  25. query: {
  26. sort,
  27. search
  28. },
  29. implicitToken: true,
  30. defaultExpectedStatus: HttpStatusCode.OK_200
  31. })
  32. }
  33. listVideos (options: OverrideCommandOptions & {
  34. sort?: string // default -createdAt
  35. } = {}) {
  36. const { sort = '-createdAt' } = options
  37. const path = '/api/v1/users/me/subscriptions/videos'
  38. return this.getRequestBody<ResultList<Video>>({
  39. ...options,
  40. path,
  41. query: { sort },
  42. implicitToken: true,
  43. defaultExpectedStatus: HttpStatusCode.OK_200
  44. })
  45. }
  46. get (options: OverrideCommandOptions & {
  47. uri: string
  48. }) {
  49. const path = '/api/v1/users/me/subscriptions/' + options.uri
  50. return this.getRequestBody<VideoChannel>({
  51. ...options,
  52. path,
  53. implicitToken: true,
  54. defaultExpectedStatus: HttpStatusCode.OK_200
  55. })
  56. }
  57. remove (options: OverrideCommandOptions & {
  58. uri: string
  59. }) {
  60. const path = '/api/v1/users/me/subscriptions/' + options.uri
  61. return this.deleteRequest({
  62. ...options,
  63. path,
  64. implicitToken: true,
  65. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  66. })
  67. }
  68. exist (options: OverrideCommandOptions & {
  69. uris: string[]
  70. }) {
  71. const path = '/api/v1/users/me/subscriptions/exist'
  72. return this.getRequestBody<{ [id: string ]: boolean }>({
  73. ...options,
  74. path,
  75. query: { 'uris[]': options.uris },
  76. implicitToken: true,
  77. defaultExpectedStatus: HttpStatusCode.OK_200
  78. })
  79. }
  80. }