PeerTube/shared/extra-utils/server/redundancy.ts

82 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-01-10 03:11:28 -06:00
import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
import { VideoRedundanciesTarget } from '@shared/models'
2018-09-11 09:27:07 -05:00
2020-01-10 03:11:28 -06:00
function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) {
2018-09-11 09:27:07 -05:00
const path = '/api/v1/server/redundancy/' + host
return makePutBodyRequest({
url,
path,
token: accessToken,
fields: { redundancyAllowed },
statusCodeExpected: expectedStatus
})
}
2020-01-10 03:11:28 -06:00
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
})
}
2018-09-11 09:27:07 -05:00
export {
2020-01-10 03:11:28 -06:00
updateRedundancy,
listVideoRedundancies,
addVideoRedundancy,
removeVideoRedundancy
2018-09-11 09:27:07 -05:00
}