mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add ability to list redundancies
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export type VideoRedundanciesTarget = 'my-videos' | 'remote-videos'
|
||||
33
shared/models/redundancy/video-redundancy.model.ts
Normal file
33
shared/models/redundancy/video-redundancy.model.ts
Normal 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 {
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -33,5 +33,7 @@ export enum UserRight {
|
||||
SEE_ALL_VIDEOS,
|
||||
CHANGE_VIDEO_OWNERSHIP,
|
||||
|
||||
MANAGE_PLUGINS
|
||||
MANAGE_PLUGINS,
|
||||
|
||||
MANAGE_VIDEOS_REDUNDANCIES
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user