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