From dab047092b51b453f175069573d8865fb17acdfc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:56:45 +0200 Subject: Introduce redundancy command --- shared/extra-utils/server/index.ts | 1 + shared/extra-utils/server/redundancy-command.ts | 77 ++++++++++++++++++++++ shared/extra-utils/server/redundancy.ts | 88 ------------------------- shared/extra-utils/server/servers.ts | 3 + 4 files changed, 81 insertions(+), 88 deletions(-) create mode 100644 shared/extra-utils/server/redundancy-command.ts delete mode 100644 shared/extra-utils/server/redundancy.ts (limited to 'shared/extra-utils/server') 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' export * from './jobs-command' export * from './plugins-command' export * from './plugins' +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 @@ +import { ResultList, VideoRedundanciesTarget, VideoRedundancy } from '@shared/models' +import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class RedundancyCommand extends AbstractCommand { + + updateRedundancy (options: OverrideCommandOptions & { + host: string + redundancyAllowed: boolean + }) { + const { host, redundancyAllowed } = options + const path = '/api/v1/server/redundancy/' + host + + return this.putBodyRequest({ + ...options, + + path, + fields: { redundancyAllowed }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + listVideos (options: OverrideCommandOptions & { + target: VideoRedundanciesTarget + start?: number + count?: number + sort?: string + }) { + const path = '/api/v1/server/redundancy/videos' + + const { target, start, count, sort } = options + + return this.getRequestBody>({ + ...options, + + path, + + query: { + start: start ?? 0, + count: count ?? 5, + sort: sort ?? 'name', + target + }, + + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + addVideo (options: OverrideCommandOptions & { + videoId: number + }) { + const path = '/api/v1/server/redundancy/videos' + const { videoId } = options + + return this.postBodyRequest({ + ...options, + + path, + fields: { videoId }, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } + + removeVideo (options: OverrideCommandOptions & { + redundancyId: number + }) { + const { redundancyId } = options + const path = '/api/v1/server/redundancy/videos/' + redundancyId + + return this.deleteRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 + }) + } +} 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 @@ -import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' -import { VideoRedundanciesTarget } from '@shared/models' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' - -function updateRedundancy ( - url: string, - accessToken: string, - host: string, - redundancyAllowed: boolean, - expectedStatus = HttpStatusCode.NO_CONTENT_204 -) { - const path = '/api/v1/server/redundancy/' + host - - return makePutBodyRequest({ - url, - path, - token: accessToken, - fields: { redundancyAllowed }, - statusCodeExpected: expectedStatus - }) -} - -function listVideoRedundancies (options: { - url: string - accessToken: string - target: VideoRedundanciesTarget - start?: number - count?: number - sort?: string - statusCodeExpected?: HttpStatusCode -}) { - const path = '/api/v1/server/redundancy/videos' - - const { url, accessToken, target, statusCodeExpected, start, count, sort } = options - - return makeGetRequest({ - url, - token: accessToken, - path, - query: { - start: start ?? 0, - count: count ?? 5, - sort: sort ?? 'name', - target - }, - statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200 - }) -} - -function addVideoRedundancy (options: { - url: string - accessToken: string - videoId: number -}) { - const path = '/api/v1/server/redundancy/videos' - const { url, accessToken, videoId } = options - - return makePostBodyRequest({ - url, - token: accessToken, - path, - fields: { videoId }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 - }) -} - -function removeVideoRedundancy (options: { - url: string - accessToken: string - redundancyId: number -}) { - const { url, accessToken, redundancyId } = options - const path = '/api/v1/server/redundancy/videos/' + redundancyId - - return makeDeleteRequest({ - url, - token: accessToken, - path, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 - }) -} - -export { - updateRedundancy, - listVideoRedundancies, - addVideoRedundancy, - removeVideoRedundancy -} 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' import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' import { PluginsCommand } from './plugins-command' +import { RedundancyCommand } from './redundancy-command' interface ServerInfo { app: ChildProcess @@ -87,6 +88,7 @@ interface ServerInfo { followsCommand?: FollowsCommand jobsCommand?: JobsCommand pluginsCommand?: PluginsCommand + redundancyCommand?: RedundancyCommand } function parallelTests () { @@ -305,6 +307,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.followsCommand = new FollowsCommand(server) server.jobsCommand = new JobsCommand(server) server.pluginsCommand = new PluginsCommand(server) + server.redundancyCommand = new RedundancyCommand(server) res(server) }) -- cgit v1.2.3