redundancy.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
  2. import { VideoRedundanciesTarget } from '@shared/models'
  3. import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
  4. function updateRedundancy (
  5. url: string,
  6. accessToken: string,
  7. host: string,
  8. redundancyAllowed: boolean,
  9. expectedStatus = HttpStatusCode.NO_CONTENT_204
  10. ) {
  11. const path = '/api/v1/server/redundancy/' + host
  12. return makePutBodyRequest({
  13. url,
  14. path,
  15. token: accessToken,
  16. fields: { redundancyAllowed },
  17. statusCodeExpected: expectedStatus
  18. })
  19. }
  20. function listVideoRedundancies (options: {
  21. url: string
  22. accessToken: string
  23. target: VideoRedundanciesTarget
  24. start?: number
  25. count?: number
  26. sort?: string
  27. statusCodeExpected?: HttpStatusCode
  28. }) {
  29. const path = '/api/v1/server/redundancy/videos'
  30. const { url, accessToken, target, statusCodeExpected, start, count, sort } = options
  31. return makeGetRequest({
  32. url,
  33. token: accessToken,
  34. path,
  35. query: {
  36. start: start ?? 0,
  37. count: count ?? 5,
  38. sort: sort ?? 'name',
  39. target
  40. },
  41. statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200
  42. })
  43. }
  44. function addVideoRedundancy (options: {
  45. url: string
  46. accessToken: string
  47. videoId: number
  48. }) {
  49. const path = '/api/v1/server/redundancy/videos'
  50. const { url, accessToken, videoId } = options
  51. return makePostBodyRequest({
  52. url,
  53. token: accessToken,
  54. path,
  55. fields: { videoId },
  56. statusCodeExpected: HttpStatusCode.NO_CONTENT_204
  57. })
  58. }
  59. function removeVideoRedundancy (options: {
  60. url: string
  61. accessToken: string
  62. redundancyId: number
  63. }) {
  64. const { url, accessToken, redundancyId } = options
  65. const path = '/api/v1/server/redundancy/videos/' + redundancyId
  66. return makeDeleteRequest({
  67. url,
  68. token: accessToken,
  69. path,
  70. statusCodeExpected: HttpStatusCode.NO_CONTENT_204
  71. })
  72. }
  73. export {
  74. updateRedundancy,
  75. listVideoRedundancies,
  76. addVideoRedundancy,
  77. removeVideoRedundancy
  78. }