aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server/redundancy.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-10 10:11:28 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-01-28 11:35:26 +0100
commitb764380ac23f4e9d4677d08acdc3474c2931a16d (patch)
tree0d2c440ed8b56c35e47f2274586a11da63852086 /shared/extra-utils/server/redundancy.ts
parent3ae0bbd23c6f1b2790975328d8eae6a8317c223d (diff)
downloadPeerTube-b764380ac23f4e9d4677d08acdc3474c2931a16d.tar.gz
PeerTube-b764380ac23f4e9d4677d08acdc3474c2931a16d.tar.zst
PeerTube-b764380ac23f4e9d4677d08acdc3474c2931a16d.zip
Add ability to list redundancies
Diffstat (limited to 'shared/extra-utils/server/redundancy.ts')
-rw-r--r--shared/extra-utils/server/redundancy.ts70
1 files changed, 67 insertions, 3 deletions
diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts
index c39ff2c8b..7b488e23e 100644
--- a/shared/extra-utils/server/redundancy.ts
+++ b/shared/extra-utils/server/redundancy.ts
@@ -1,6 +1,7 @@
1import { makePutBodyRequest } from '../requests/requests' 1import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
2import { VideoRedundanciesTarget } from '@shared/models'
2 3
3async function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { 4function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) {
4 const path = '/api/v1/server/redundancy/' + host 5 const path = '/api/v1/server/redundancy/' + host
5 6
6 return makePutBodyRequest({ 7 return makePutBodyRequest({
@@ -12,6 +13,69 @@ async function updateRedundancy (url: string, accessToken: string, host: string,
12 }) 13 })
13} 14}
14 15
16function listVideoRedundancies (options: {
17 url: string
18 accessToken: string,
19 target: VideoRedundanciesTarget,
20 start?: number,
21 count?: number,
22 sort?: string,
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: {
44 url: string,
45 accessToken: string,
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: {
61 url: string,
62 accessToken: string,
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
15export { 76export {
16 updateRedundancy 77 updateRedundancy,
78 listVideoRedundancies,
79 addVideoRedundancy,
80 removeVideoRedundancy
17} 81}