diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 10:56:45 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | dab047092b51b453f175069573d8865fb17acdfc (patch) | |
tree | b53fbd6f6dfb5d5ce0e09da4ce694737dab3f07e /shared/extra-utils | |
parent | ae2abfd3aed3e75d39a316b49b914d187faa7475 (diff) | |
download | PeerTube-dab047092b51b453f175069573d8865fb17acdfc.tar.gz PeerTube-dab047092b51b453f175069573d8865fb17acdfc.tar.zst PeerTube-dab047092b51b453f175069573d8865fb17acdfc.zip |
Introduce redundancy command
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/server/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/server/redundancy-command.ts | 77 | ||||
-rw-r--r-- | shared/extra-utils/server/redundancy.ts | 88 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 |
4 files changed, 81 insertions, 88 deletions
diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index e602fec7e..3ee70f0cf 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts | |||
@@ -6,3 +6,4 @@ export * from './jobs' | |||
6 | export * from './jobs-command' | 6 | export * from './jobs-command' |
7 | export * from './plugins-command' | 7 | export * from './plugins-command' |
8 | export * from './plugins' | 8 | export * from './plugins' |
9 | export * from './redundancy-command' | ||
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 @@ | |||
1 | import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export 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 | } | ||
diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts deleted file mode 100644 index b83815a37..000000000 --- a/shared/extra-utils/server/redundancy.ts +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
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 ( | ||
6 | url: string, | ||
7 | accessToken: string, | ||
8 | host: string, | ||
9 | redundancyAllowed: boolean, | ||
10 | expectedStatus = HttpStatusCode.NO_CONTENT_204 | ||
11 | ) { | ||
12 | const path = '/api/v1/server/redundancy/' + host | ||
13 | |||
14 | return makePutBodyRequest({ | ||
15 | url, | ||
16 | path, | ||
17 | token: accessToken, | ||
18 | fields: { redundancyAllowed }, | ||
19 | statusCodeExpected: expectedStatus | ||
20 | }) | ||
21 | } | ||
22 | |||
23 | function listVideoRedundancies (options: { | ||
24 | url: string | ||
25 | accessToken: string | ||
26 | target: VideoRedundanciesTarget | ||
27 | start?: number | ||
28 | count?: number | ||
29 | sort?: string | ||
30 | statusCodeExpected?: HttpStatusCode | ||
31 | }) { | ||
32 | const path = '/api/v1/server/redundancy/videos' | ||
33 | |||
34 | const { url, accessToken, target, statusCodeExpected, start, count, sort } = options | ||
35 | |||
36 | return makeGetRequest({ | ||
37 | url, | ||
38 | token: accessToken, | ||
39 | path, | ||
40 | query: { | ||
41 | start: start ?? 0, | ||
42 | count: count ?? 5, | ||
43 | sort: sort ?? 'name', | ||
44 | target | ||
45 | }, | ||
46 | statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200 | ||
47 | }) | ||
48 | } | ||
49 | |||
50 | function addVideoRedundancy (options: { | ||
51 | url: string | ||
52 | accessToken: string | ||
53 | videoId: number | ||
54 | }) { | ||
55 | const path = '/api/v1/server/redundancy/videos' | ||
56 | const { url, accessToken, videoId } = options | ||
57 | |||
58 | return makePostBodyRequest({ | ||
59 | url, | ||
60 | token: accessToken, | ||
61 | path, | ||
62 | fields: { videoId }, | ||
63 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
64 | }) | ||
65 | } | ||
66 | |||
67 | function removeVideoRedundancy (options: { | ||
68 | url: string | ||
69 | accessToken: string | ||
70 | redundancyId: number | ||
71 | }) { | ||
72 | const { url, accessToken, redundancyId } = options | ||
73 | const path = '/api/v1/server/redundancy/videos/' + redundancyId | ||
74 | |||
75 | return makeDeleteRequest({ | ||
76 | url, | ||
77 | token: accessToken, | ||
78 | path, | ||
79 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
80 | }) | ||
81 | } | ||
82 | |||
83 | export { | ||
84 | updateRedundancy, | ||
85 | listVideoRedundancies, | ||
86 | addVideoRedundancy, | ||
87 | removeVideoRedundancy | ||
88 | } | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 79d6b7b1a..eaf39ecea 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -21,6 +21,7 @@ import { DebugCommand } from './debug-command' | |||
21 | import { FollowsCommand } from './follows-command' | 21 | import { FollowsCommand } from './follows-command' |
22 | import { JobsCommand } from './jobs-command' | 22 | import { JobsCommand } from './jobs-command' |
23 | import { PluginsCommand } from './plugins-command' | 23 | import { PluginsCommand } from './plugins-command' |
24 | import { RedundancyCommand } from './redundancy-command' | ||
24 | 25 | ||
25 | interface ServerInfo { | 26 | interface ServerInfo { |
26 | app: ChildProcess | 27 | app: ChildProcess |
@@ -87,6 +88,7 @@ interface ServerInfo { | |||
87 | followsCommand?: FollowsCommand | 88 | followsCommand?: FollowsCommand |
88 | jobsCommand?: JobsCommand | 89 | jobsCommand?: JobsCommand |
89 | pluginsCommand?: PluginsCommand | 90 | pluginsCommand?: PluginsCommand |
91 | redundancyCommand?: RedundancyCommand | ||
90 | } | 92 | } |
91 | 93 | ||
92 | function parallelTests () { | 94 | function parallelTests () { |
@@ -305,6 +307,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
305 | server.followsCommand = new FollowsCommand(server) | 307 | server.followsCommand = new FollowsCommand(server) |
306 | server.jobsCommand = new JobsCommand(server) | 308 | server.jobsCommand = new JobsCommand(server) |
307 | server.pluginsCommand = new PluginsCommand(server) | 309 | server.pluginsCommand = new PluginsCommand(server) |
310 | server.redundancyCommand = new RedundancyCommand(server) | ||
308 | 311 | ||
309 | res(server) | 312 | res(server) |
310 | }) | 313 | }) |