redundancy-command.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { HttpStatusCode, ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
  2. import { AbstractCommand, OverrideCommandOptions } from '../shared'
  3. export class RedundancyCommand extends AbstractCommand {
  4. updateRedundancy (options: OverrideCommandOptions & {
  5. host: string
  6. redundancyAllowed: boolean
  7. }) {
  8. const { host, redundancyAllowed } = options
  9. const path = '/api/v1/server/redundancy/' + host
  10. return this.putBodyRequest({
  11. ...options,
  12. path,
  13. fields: { redundancyAllowed },
  14. implicitToken: true,
  15. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  16. })
  17. }
  18. listVideos (options: OverrideCommandOptions & {
  19. target: VideoRedundanciesTarget
  20. start?: number
  21. count?: number
  22. sort?: string
  23. }) {
  24. const path = '/api/v1/server/redundancy/videos'
  25. const { target, start, count, sort } = options
  26. return this.getRequestBody<ResultList<VideoRedundancy>>({
  27. ...options,
  28. path,
  29. query: {
  30. start: start ?? 0,
  31. count: count ?? 5,
  32. sort: sort ?? 'name',
  33. target
  34. },
  35. implicitToken: true,
  36. defaultExpectedStatus: HttpStatusCode.OK_200
  37. })
  38. }
  39. addVideo (options: OverrideCommandOptions & {
  40. videoId: number
  41. }) {
  42. const path = '/api/v1/server/redundancy/videos'
  43. const { videoId } = options
  44. return this.postBodyRequest({
  45. ...options,
  46. path,
  47. fields: { videoId },
  48. implicitToken: true,
  49. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  50. })
  51. }
  52. removeVideo (options: OverrideCommandOptions & {
  53. redundancyId: number
  54. }) {
  55. const { redundancyId } = options
  56. const path = '/api/v1/server/redundancy/videos/' + redundancyId
  57. return this.deleteRequest({
  58. ...options,
  59. path,
  60. implicitToken: true,
  61. defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
  62. })
  63. }
  64. }