blacklist-command.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { HttpStatusCode, ResultList, VideoBlacklist, VideoBlacklistType } from '@shared/models'
  2. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  3. export class BlacklistCommand extends AbstractCommand {
  4. add (options: OverrideCommandOptions & {
  5. videoId: number | string
  6. reason?: string
  7. unfederate?: boolean
  8. }) {
  9. const { videoId, reason, unfederate } = options
  10. const path = '/api/v1/videos/' + videoId + '/blacklist'
  11. return this.postBodyRequest({
  12. ...options,
  13. path,
  14. fields: { reason, unfederate },
  15. implicitToken: true,
  16. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  17. })
  18. }
  19. update (options: OverrideCommandOptions & {
  20. videoId: number | string
  21. reason?: string
  22. }) {
  23. const { videoId, reason } = options
  24. const path = '/api/v1/videos/' + videoId + '/blacklist'
  25. return this.putBodyRequest({
  26. ...options,
  27. path,
  28. fields: { reason },
  29. implicitToken: true,
  30. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  31. })
  32. }
  33. remove (options: OverrideCommandOptions & {
  34. videoId: number | string
  35. }) {
  36. const { videoId } = options
  37. const path = '/api/v1/videos/' + videoId + '/blacklist'
  38. return this.deleteRequest({
  39. ...options,
  40. path,
  41. implicitToken: true,
  42. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  43. })
  44. }
  45. list (options: OverrideCommandOptions & {
  46. sort?: string
  47. type?: VideoBlacklistType
  48. } = {}) {
  49. const { sort, type } = options
  50. const path = '/api/v1/videos/blacklist/'
  51. const query = { sort, type }
  52. return this.getRequestBody<ResultList<VideoBlacklist>>({
  53. ...options,
  54. path,
  55. query,
  56. implicitToken: true,
  57. defaultExpectedStatus: HttpStatusCode.OK_200
  58. })
  59. }
  60. }