aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/server/redundancy-command.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-07 10:56:45 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commitdab047092b51b453f175069573d8865fb17acdfc (patch)
treeb53fbd6f6dfb5d5ce0e09da4ce694737dab3f07e /shared/extra-utils/server/redundancy-command.ts
parentae2abfd3aed3e75d39a316b49b914d187faa7475 (diff)
downloadPeerTube-dab047092b51b453f175069573d8865fb17acdfc.tar.gz
PeerTube-dab047092b51b453f175069573d8865fb17acdfc.tar.zst
PeerTube-dab047092b51b453f175069573d8865fb17acdfc.zip
Introduce redundancy command
Diffstat (limited to 'shared/extra-utils/server/redundancy-command.ts')
-rw-r--r--shared/extra-utils/server/redundancy-command.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/shared/extra-utils/server/redundancy-command.ts b/shared/extra-utils/server/redundancy-command.ts
new file mode 100644
index 000000000..d717d35f8
--- /dev/null
+++ b/shared/extra-utils/server/redundancy-command.ts
@@ -0,0 +1,77 @@
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 },
19 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
20 })
21 }
22
23 listVideos (options: OverrideCommandOptions & {
24 target: VideoRedundanciesTarget
25 start?: number
26 count?: number
27 sort?: string
28 }) {
29 const path = '/api/v1/server/redundancy/videos'
30
31 const { target, start, count, sort } = options
32
33 return this.getRequestBody<ResultList<VideoRedundancy>>({
34 ...options,
35
36 path,
37
38 query: {
39 start: start ?? 0,
40 count: count ?? 5,
41 sort: sort ?? 'name',
42 target
43 },
44
45 defaultExpectedStatus: HttpStatusCode.OK_200
46 })
47 }
48
49 addVideo (options: OverrideCommandOptions & {
50 videoId: number
51 }) {
52 const path = '/api/v1/server/redundancy/videos'
53 const { videoId } = options
54
55 return this.postBodyRequest({
56 ...options,
57
58 path,
59 fields: { videoId },
60 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
61 })
62 }
63
64 removeVideo (options: OverrideCommandOptions & {
65 redundancyId: number
66 }) {
67 const { redundancyId } = options
68 const path = '/api/v1/server/redundancy/videos/' + redundancyId
69
70 return this.deleteRequest({
71 ...options,
72
73 path,
74 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
75 })
76 }
77}