Add ability to list redundancies

This commit is contained in:
Chocobozzz
2020-01-10 10:11:28 +01:00
committed by Chocobozzz
parent 3ae0bbd23c
commit b764380ac2
64 changed files with 1807 additions and 195 deletions

View File

@@ -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,
})
}
export {
updateRedundancy
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,
listVideoRedundancies,
addVideoRedundancy,
removeVideoRedundancy
}

View File

@@ -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
}

View File

@@ -1 +1,3 @@
export * from './videos-redundancy.model'
export * from './videos-redundancy-strategy.model'
export * from './video-redundancies-filters.model'
export * from './video-redundancy.model'

View File

@@ -0,0 +1 @@
export type VideoRedundanciesTarget = 'my-videos' | 'remote-videos'

View File

@@ -0,0 +1,33 @@
export interface VideoRedundancy {
id: number
name: string
url: string
uuid: string
redundancies: {
files: FileRedundancyInformation[]
streamingPlaylists: StreamingPlaylistRedundancyInformation[]
}
}
interface RedundancyInformation {
id: number
fileUrl: string
strategy: string
createdAt: Date | string
updatedAt: Date | string
expiresOn: Date | string
size: number
}
export interface FileRedundancyInformation extends RedundancyInformation {
}
export interface StreamingPlaylistRedundancyInformation extends RedundancyInformation {
}

View File

@@ -1,4 +1,5 @@
export type VideoRedundancyStrategy = 'most-views' | 'trending' | 'recently-added'
export type VideoRedundancyStrategyWithManual = VideoRedundancyStrategy | 'manual'
export type MostViewsRedundancyStrategy = {
strategy: 'most-views'
@@ -19,4 +20,4 @@ export type RecentlyAddedStrategy = {
minLifetime: number
}
export type VideosRedundancy = MostViewsRedundancyStrategy | TrendingRedundancyStrategy | RecentlyAddedStrategy
export type VideosRedundancyStrategy = MostViewsRedundancyStrategy | TrendingRedundancyStrategy | RecentlyAddedStrategy

View File

@@ -9,7 +9,8 @@ export type JobType = 'activitypub-http-unicast' |
'email' |
'video-import' |
'videos-views' |
'activitypub-refresher'
'activitypub-refresher' |
'video-redundancy'
export interface Job {
id: number

View File

@@ -1,4 +1,4 @@
import { VideoRedundancyStrategy } from '../redundancy'
import { VideoRedundancyStrategyWithManual } from '../redundancy'
export interface ServerStats {
totalUsers: number
@@ -13,11 +13,13 @@ export interface ServerStats {
totalInstanceFollowers: number
totalInstanceFollowing: number
videosRedundancy: {
strategy: VideoRedundancyStrategy
totalSize: number
totalUsed: number
totalVideoFiles: number
totalVideos: number
}[]
videosRedundancy: VideosRedundancyStats[]
}
export interface VideosRedundancyStats {
strategy: VideoRedundancyStrategyWithManual
totalSize: number
totalUsed: number
totalVideoFiles: number
totalVideos: number
}

View File

@@ -33,5 +33,7 @@ export enum UserRight {
SEE_ALL_VIDEOS,
CHANGE_VIDEO_OWNERSHIP,
MANAGE_PLUGINS
MANAGE_PLUGINS,
MANAGE_VIDEOS_REDUNDANCIES
}

View File

@@ -1,4 +1,4 @@
import { AccountSummary, VideoChannelSummary, VideoResolution, VideoState } from '../../index'
import { AccountSummary, VideoChannelSummary, VideoState } from '../../index'
import { Account } from '../actors'
import { VideoChannel } from './channel/video-channel.model'
import { VideoPrivacy } from './video-privacy.enum'