]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/redundancy.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / redundancy.ts
CommitLineData
b764380a
C
1import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
2import { VideoRedundanciesTarget } from '@shared/models'
c48e82b5 3
b764380a 4function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) {
c48e82b5
C
5 const path = '/api/v1/server/redundancy/' + host
6
7 return makePutBodyRequest({
8 url,
9 path,
10 token: accessToken,
11 fields: { redundancyAllowed },
12 statusCodeExpected: expectedStatus
13 })
14}
15
b764380a
C
16function listVideoRedundancies (options: {
17 url: string
a1587156
C
18 accessToken: string
19 target: VideoRedundanciesTarget
20 start?: number
21 count?: number
22 sort?: string
b764380a
C
23 statusCodeExpected?: number
24}) {
25 const path = '/api/v1/server/redundancy/videos'
26
27 const { url, accessToken, target, statusCodeExpected, start, count, sort } = options
28
29 return makeGetRequest({
30 url,
31 token: accessToken,
32 path,
33 query: {
34 start: start ?? 0,
35 count: count ?? 5,
36 sort: sort ?? 'name',
37 target
38 },
39 statusCodeExpected: statusCodeExpected || 200
40 })
41}
42
43function addVideoRedundancy (options: {
a1587156
C
44 url: string
45 accessToken: string
b764380a
C
46 videoId: number
47}) {
48 const path = '/api/v1/server/redundancy/videos'
49 const { url, accessToken, videoId } = options
50
51 return makePostBodyRequest({
52 url,
53 token: accessToken,
54 path,
55 fields: { videoId },
56 statusCodeExpected: 204
57 })
58}
59
60function removeVideoRedundancy (options: {
a1587156
C
61 url: string
62 accessToken: string
b764380a
C
63 redundancyId: number
64}) {
65 const { url, accessToken, redundancyId } = options
66 const path = '/api/v1/server/redundancy/videos/' + redundancyId
67
68 return makeDeleteRequest({
69 url,
70 token: accessToken,
71 path,
72 statusCodeExpected: 204
73 })
74}
75
c48e82b5 76export {
b764380a
C
77 updateRedundancy,
78 listVideoRedundancies,
79 addVideoRedundancy,
80 removeVideoRedundancy
c48e82b5 81}