]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/server/redundancy-command.ts
Specify if we want to fallback to the server token
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / redundancy-command.ts
CommitLineData
dab04709
C
1import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { AbstractCommand, OverrideCommandOptions } from '../shared'
4
5export class RedundancyCommand extends AbstractCommand {
6
7 updateRedundancy (options: OverrideCommandOptions & {
8 host: string
9 redundancyAllowed: boolean
10 }) {
11 const { host, redundancyAllowed } = options
12 const path = '/api/v1/server/redundancy/' + host
13
14 return this.putBodyRequest({
15 ...options,
16
17 path,
18 fields: { redundancyAllowed },
a1637fa1 19 implicitToken: true,
dab04709
C
20 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
21 })
22 }
23
24 listVideos (options: OverrideCommandOptions & {
25 target: VideoRedundanciesTarget
26 start?: number
27 count?: number
28 sort?: string
29 }) {
30 const path = '/api/v1/server/redundancy/videos'
31
32 const { target, start, count, sort } = options
33
34 return this.getRequestBody<ResultList<VideoRedundancy>>({
35 ...options,
36
37 path,
38
39 query: {
40 start: start ?? 0,
41 count: count ?? 5,
42 sort: sort ?? 'name',
43 target
44 },
45
a1637fa1 46 implicitToken: true,
dab04709
C
47 defaultExpectedStatus: HttpStatusCode.OK_200
48 })
49 }
50
51 addVideo (options: OverrideCommandOptions & {
52 videoId: number
53 }) {
54 const path = '/api/v1/server/redundancy/videos'
55 const { videoId } = options
56
57 return this.postBodyRequest({
58 ...options,
59
60 path,
61 fields: { videoId },
a1637fa1 62 implicitToken: true,
dab04709
C
63 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
64 })
65 }
66
67 removeVideo (options: OverrideCommandOptions & {
68 redundancyId: number
69 }) {
70 const { redundancyId } = options
71 const path = '/api/v1/server/redundancy/videos/' + redundancyId
72
73 return this.deleteRequest({
74 ...options,
75
76 path,
a1637fa1 77 implicitToken: true,
dab04709
C
78 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
79 })
80 }
81}