From b764380ac23f4e9d4677d08acdc3474c2931a16d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Jan 2020 10:11:28 +0100 Subject: Add ability to list redundancies --- shared/extra-utils/server/redundancy.ts | 70 +++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) (limited to 'shared/extra-utils/server/redundancy.ts') diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts index c39ff2c8b..7b488e23e 100644 --- a/shared/extra-utils/server/redundancy.ts +++ b/shared/extra-utils/server/redundancy.ts @@ -1,6 +1,7 @@ -import { makePutBodyRequest } from '../requests/requests' +import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' +import { VideoRedundanciesTarget } from '@shared/models' -async function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { +function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { const path = '/api/v1/server/redundancy/' + host return makePutBodyRequest({ @@ -12,6 +13,69 @@ async function updateRedundancy (url: string, accessToken: string, host: string, }) } +function listVideoRedundancies (options: { + url: string + accessToken: string, + target: VideoRedundanciesTarget, + start?: number, + count?: number, + sort?: string, + statusCodeExpected?: number +}) { + 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 || 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: 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: 204 + }) +} + export { - updateRedundancy + updateRedundancy, + listVideoRedundancies, + addVideoRedundancy, + removeVideoRedundancy } -- cgit v1.2.3