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 +++++++++++++++++++++++++++++++-- shared/extra-utils/videos/videos.ts | 18 ++++++++- 2 files changed, 83 insertions(+), 5 deletions(-) (limited to 'shared/extra-utils') 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 } diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts index 7a77a03ad..aa13273ae 100644 --- a/shared/extra-utils/videos/videos.ts +++ b/shared/extra-utils/videos/videos.ts @@ -607,15 +607,28 @@ async function videoUUIDToId (url: string, id: number | string) { return res.body.id } -async function uploadVideoAndGetId (options: { server: ServerInfo, videoName: string, nsfw?: boolean, token?: string }) { +async function uploadVideoAndGetId (options: { + server: ServerInfo, + videoName: string, + nsfw?: boolean, + privacy?: VideoPrivacy, + token?: string +}) { const videoAttrs: any = { name: options.videoName } if (options.nsfw) videoAttrs.nsfw = options.nsfw + if (options.privacy) videoAttrs.privacy = options.privacy const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs) return { id: res.body.video.id, uuid: res.body.video.uuid } } +async function getLocalIdByUUID (url: string, uuid: string) { + const res = await getVideo(url, uuid) + + return res.body.id +} + // --------------------------------------------------------------------------- export { @@ -645,5 +658,6 @@ export { completeVideoCheck, checkVideoFilesWereRemoved, getPlaylistVideos, - uploadVideoAndGetId + uploadVideoAndGetId, + getLocalIdByUUID } -- cgit v1.2.3