]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/server/redundancy.ts
Refactor a little bit client canonical URL
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / redundancy.ts
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
5 function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) {
6 const path = '/api/v1/server/redundancy/' + host
7
8 return makePutBodyRequest({
9 url,
10 path,
11 token: accessToken,
12 fields: { redundancyAllowed },
13 statusCodeExpected: expectedStatus
14 })
15 }
16
17 function listVideoRedundancies (options: {
18 url: string
19 accessToken: string
20 target: VideoRedundanciesTarget
21 start?: number
22 count?: number
23 sort?: string
24 statusCodeExpected?: HttpStatusCode
25 }) {
26 const path = '/api/v1/server/redundancy/videos'
27
28 const { url, accessToken, target, statusCodeExpected, start, count, sort } = options
29
30 return makeGetRequest({
31 url,
32 token: accessToken,
33 path,
34 query: {
35 start: start ?? 0,
36 count: count ?? 5,
37 sort: sort ?? 'name',
38 target
39 },
40 statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200
41 })
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
52 return makePostBodyRequest({
53 url,
54 token: accessToken,
55 path,
56 fields: { videoId },
57 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
58 })
59 }
60
61 function removeVideoRedundancy (options: {
62 url: string
63 accessToken: string
64 redundancyId: number
65 }) {
66 const { url, accessToken, redundancyId } = options
67 const path = '/api/v1/server/redundancy/videos/' + redundancyId
68
69 return makeDeleteRequest({
70 url,
71 token: accessToken,
72 path,
73 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
74 })
75 }
76
77 export {
78 updateRedundancy,
79 listVideoRedundancies,
80 addVideoRedundancy,
81 removeVideoRedundancy
82 }