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 +++++- shared/models/redundancy/index.ts | 4 +- .../redundancy/video-redundancies-filters.model.ts | 1 + shared/models/redundancy/video-redundancy.model.ts | 33 ++++++++++ .../redundancy/videos-redundancy-strategy.model.ts | 23 +++++++ .../models/redundancy/videos-redundancy.model.ts | 22 ------- shared/models/server/job.model.ts | 3 +- shared/models/server/server-stats.model.ts | 18 +++--- shared/models/users/user-right.enum.ts | 4 +- shared/models/videos/video.model.ts | 2 +- 11 files changed, 159 insertions(+), 39 deletions(-) create mode 100644 shared/models/redundancy/video-redundancies-filters.model.ts create mode 100644 shared/models/redundancy/video-redundancy.model.ts create mode 100644 shared/models/redundancy/videos-redundancy-strategy.model.ts delete mode 100644 shared/models/redundancy/videos-redundancy.model.ts (limited to 'shared') 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 } diff --git a/shared/models/redundancy/index.ts b/shared/models/redundancy/index.ts index 61bf0fca7..649cc489f 100644 --- a/shared/models/redundancy/index.ts +++ b/shared/models/redundancy/index.ts @@ -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' diff --git a/shared/models/redundancy/video-redundancies-filters.model.ts b/shared/models/redundancy/video-redundancies-filters.model.ts new file mode 100644 index 000000000..05ba7dfd3 --- /dev/null +++ b/shared/models/redundancy/video-redundancies-filters.model.ts @@ -0,0 +1 @@ +export type VideoRedundanciesTarget = 'my-videos' | 'remote-videos' diff --git a/shared/models/redundancy/video-redundancy.model.ts b/shared/models/redundancy/video-redundancy.model.ts new file mode 100644 index 000000000..014f69634 --- /dev/null +++ b/shared/models/redundancy/video-redundancy.model.ts @@ -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 { + +} diff --git a/shared/models/redundancy/videos-redundancy-strategy.model.ts b/shared/models/redundancy/videos-redundancy-strategy.model.ts new file mode 100644 index 000000000..15409abf0 --- /dev/null +++ b/shared/models/redundancy/videos-redundancy-strategy.model.ts @@ -0,0 +1,23 @@ +export type VideoRedundancyStrategy = 'most-views' | 'trending' | 'recently-added' +export type VideoRedundancyStrategyWithManual = VideoRedundancyStrategy | 'manual' + +export type MostViewsRedundancyStrategy = { + strategy: 'most-views' + size: number + minLifetime: number +} + +export type TrendingRedundancyStrategy = { + strategy: 'trending' + size: number + minLifetime: number +} + +export type RecentlyAddedStrategy = { + strategy: 'recently-added' + size: number + minViews: number + minLifetime: number +} + +export type VideosRedundancyStrategy = MostViewsRedundancyStrategy | TrendingRedundancyStrategy | RecentlyAddedStrategy diff --git a/shared/models/redundancy/videos-redundancy.model.ts b/shared/models/redundancy/videos-redundancy.model.ts deleted file mode 100644 index a8c2743c1..000000000 --- a/shared/models/redundancy/videos-redundancy.model.ts +++ /dev/null @@ -1,22 +0,0 @@ -export type VideoRedundancyStrategy = 'most-views' | 'trending' | 'recently-added' - -export type MostViewsRedundancyStrategy = { - strategy: 'most-views' - size: number - minLifetime: number -} - -export type TrendingRedundancyStrategy = { - strategy: 'trending' - size: number - minLifetime: number -} - -export type RecentlyAddedStrategy = { - strategy: 'recently-added' - size: number - minViews: number - minLifetime: number -} - -export type VideosRedundancy = MostViewsRedundancyStrategy | TrendingRedundancyStrategy | RecentlyAddedStrategy diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index b82a633b2..19fd4c659 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts @@ -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 diff --git a/shared/models/server/server-stats.model.ts b/shared/models/server/server-stats.model.ts index 74f3de5d3..11778e6ed 100644 --- a/shared/models/server/server-stats.model.ts +++ b/shared/models/server/server-stats.model.ts @@ -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 } diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts index 4a28a229d..2f88a65de 100644 --- a/shared/models/users/user-right.enum.ts +++ b/shared/models/users/user-right.enum.ts @@ -33,5 +33,7 @@ export enum UserRight { SEE_ALL_VIDEOS, CHANGE_VIDEO_OWNERSHIP, - MANAGE_PLUGINS + MANAGE_PLUGINS, + + MANAGE_VIDEOS_REDUNDANCIES } diff --git a/shared/models/videos/video.model.ts b/shared/models/videos/video.model.ts index 7576439fe..a69152759 100644 --- a/shared/models/videos/video.model.ts +++ b/shared/models/videos/video.model.ts @@ -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' -- cgit v1.2.3