2020-01-10 10:11:28 +01:00
|
|
|
import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
|
|
|
|
import { VideoRedundanciesTarget } from '@shared/models'
|
2020-12-07 14:32:36 +01:00
|
|
|
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
2018-09-11 16:27:07 +02:00
|
|
|
|
2020-01-10 10:11:28 +01:00
|
|
|
function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) {
|
2018-09-11 16:27:07 +02:00
|
|
|
const path = '/api/v1/server/redundancy/' + host
|
|
|
|
|
|
|
|
return makePutBodyRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
token: accessToken,
|
|
|
|
fields: { redundancyAllowed },
|
|
|
|
statusCodeExpected: expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-10 10:11:28 +01:00
|
|
|
function listVideoRedundancies (options: {
|
|
|
|
url: string
|
2020-01-31 16:56:52 +01:00
|
|
|
accessToken: string
|
|
|
|
target: VideoRedundanciesTarget
|
|
|
|
start?: number
|
|
|
|
count?: number
|
|
|
|
sort?: string
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected?: HttpStatusCode
|
2020-01-10 10:11:28 +01:00
|
|
|
}) {
|
|
|
|
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
|
|
|
|
},
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: statusCodeExpected || HttpStatusCode.OK_200
|
2020-01-10 10:11:28 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function addVideoRedundancy (options: {
|
2020-01-31 16:56:52 +01:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
2020-01-10 10:11:28 +01:00
|
|
|
videoId: number
|
|
|
|
}) {
|
|
|
|
const path = '/api/v1/server/redundancy/videos'
|
|
|
|
const { url, accessToken, videoId } = options
|
|
|
|
|
|
|
|
return makePostBodyRequest({
|
|
|
|
url,
|
|
|
|
token: accessToken,
|
|
|
|
path,
|
|
|
|
fields: { videoId },
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
|
2020-01-10 10:11:28 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeVideoRedundancy (options: {
|
2020-01-31 16:56:52 +01:00
|
|
|
url: string
|
|
|
|
accessToken: string
|
2020-01-10 10:11:28 +01:00
|
|
|
redundancyId: number
|
|
|
|
}) {
|
|
|
|
const { url, accessToken, redundancyId } = options
|
|
|
|
const path = '/api/v1/server/redundancy/videos/' + redundancyId
|
|
|
|
|
|
|
|
return makeDeleteRequest({
|
|
|
|
url,
|
|
|
|
token: accessToken,
|
|
|
|
path,
|
2020-12-07 14:32:36 +01:00
|
|
|
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
|
2020-01-10 10:11:28 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-09-11 16:27:07 +02:00
|
|
|
export {
|
2020-01-10 10:11:28 +01:00
|
|
|
updateRedundancy,
|
|
|
|
listVideoRedundancies,
|
|
|
|
addVideoRedundancy,
|
|
|
|
removeVideoRedundancy
|
2018-09-11 16:27:07 +02:00
|
|
|
}
|