mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 17:59:37 +02:00
Fix redundancy CLI
This commit is contained in:
parent
8912ad0667
commit
40ac4ce3da
1 changed files with 7 additions and 11 deletions
|
@ -1,9 +1,9 @@
|
||||||
import bytes from 'bytes'
|
|
||||||
import CliTable3 from 'cli-table3'
|
|
||||||
import { URL } from 'url'
|
|
||||||
import { Command } from '@commander-js/extra-typings'
|
import { Command } from '@commander-js/extra-typings'
|
||||||
import { forceNumber, uniqify } from '@peertube/peertube-core-utils'
|
import { forceNumber, uniqify } from '@peertube/peertube-core-utils'
|
||||||
import { HttpStatusCode, VideoRedundanciesTarget } from '@peertube/peertube-models'
|
import { HttpStatusCode, VideoRedundanciesTarget } from '@peertube/peertube-models'
|
||||||
|
import bytes from 'bytes'
|
||||||
|
import CliTable3 from 'cli-table3'
|
||||||
|
import { URL } from 'url'
|
||||||
import { assignToken, buildServer, CommonProgramOptions, getServerCredentials } from './shared/index.js'
|
import { assignToken, buildServer, CommonProgramOptions, getServerCredentials } from './shared/index.js'
|
||||||
|
|
||||||
export function defineRedundancyProgram () {
|
export function defineRedundancyProgram () {
|
||||||
|
@ -89,24 +89,22 @@ async function listRedundanciesCLI (options: CommonProgramOptions & { target: Vi
|
||||||
const { data } = await server.redundancy.listVideos({ start: 0, count: 100, sort: 'name', target })
|
const { data } = await server.redundancy.listVideos({ start: 0, count: 100, sort: 'name', target })
|
||||||
|
|
||||||
const table = new CliTable3({
|
const table = new CliTable3({
|
||||||
head: [ 'video id', 'video name', 'video url', 'files', 'playlists', 'by instances', 'total size' ]
|
head: [ 'video id', 'video name', 'video url', 'playlists', 'by instances', 'total size' ]
|
||||||
}) as any
|
}) as any
|
||||||
|
|
||||||
for (const redundancy of data) {
|
for (const redundancy of data) {
|
||||||
const webVideoFiles = redundancy.redundancies.files
|
|
||||||
const streamingPlaylists = redundancy.redundancies.streamingPlaylists
|
const streamingPlaylists = redundancy.redundancies.streamingPlaylists
|
||||||
|
|
||||||
let totalSize = ''
|
let totalSize = ''
|
||||||
if (target === 'remote-videos') {
|
if (target === 'remote-videos') {
|
||||||
const tmp = webVideoFiles.concat(streamingPlaylists)
|
const tmp = streamingPlaylists.reduce((a, b) => a + b.size, 0)
|
||||||
.reduce((a, b) => a + b.size, 0)
|
|
||||||
|
|
||||||
// FIXME: don't use external dependency to stringify bytes: we already have the functions in the client
|
// FIXME: don't use external dependency to stringify bytes: we already have the functions in the client
|
||||||
totalSize = bytes(tmp)
|
totalSize = bytes(tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
const instances = uniqify(
|
const instances = uniqify(
|
||||||
webVideoFiles.concat(streamingPlaylists)
|
streamingPlaylists
|
||||||
.map(r => r.fileUrl)
|
.map(r => r.fileUrl)
|
||||||
.map(u => new URL(u).host)
|
.map(u => new URL(u).host)
|
||||||
)
|
)
|
||||||
|
@ -115,7 +113,6 @@ async function listRedundanciesCLI (options: CommonProgramOptions & { target: Vi
|
||||||
redundancy.id.toString(),
|
redundancy.id.toString(),
|
||||||
redundancy.name,
|
redundancy.name,
|
||||||
redundancy.url,
|
redundancy.url,
|
||||||
webVideoFiles.length,
|
|
||||||
streamingPlaylists.length,
|
streamingPlaylists.length,
|
||||||
instances.join('\n'),
|
instances.join('\n'),
|
||||||
totalSize
|
totalSize
|
||||||
|
@ -174,8 +171,7 @@ async function removeRedundancyCLI (options: CommonProgramOptions & { video: num
|
||||||
throw new Error('Video redundancy not found.')
|
throw new Error('Video redundancy not found.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const ids = videoRedundancy.redundancies.files
|
const ids = videoRedundancy.redundancies.streamingPlaylists
|
||||||
.concat(videoRedundancy.redundancies.streamingPlaylists)
|
|
||||||
.map(r => r.id)
|
.map(r => r.id)
|
||||||
|
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue