]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tools/peertube-redundancy.ts
Prevent invalid end watch section warnings
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-redundancy.ts
index 0f6b3086c9b7e8423597769618d2cb9c94176cf0..fd6c760b23de6fb212047b22d72076a5468a20da 100644 (file)
@@ -1,19 +1,14 @@
-import { registerTSPaths } from '../helpers/register-ts-paths'
-registerTSPaths()
-
-import * as CliTable3 from 'cli-table3'
+import CliTable3 from 'cli-table3'
 import { Command, program } from 'commander'
-import { uniq } from 'lodash'
 import { URL } from 'url'
 import validator from 'validator'
-import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
-import { VideoRedundanciesTarget } from '@shared/models'
-import { assignToken, buildServer, getServerCredentials } from './cli'
+import { forceNumber, uniqify } from '@shared/core-utils'
+import { HttpStatusCode, VideoRedundanciesTarget } from '@shared/models'
+import { assignToken, buildServer, getServerCredentials } from './shared'
 
 import bytes = require('bytes')
-
 program
-  .name('plugins')
+  .name('redundancy')
   .usage('[command] [options]')
 
 program
@@ -63,7 +58,7 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) {
   const server = buildServer(url)
   await assignToken(server, username, password)
 
-  const { data } = await server.redundancyCommand.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({
     head: [ 'video id', 'video name', 'video url', 'files', 'playlists', 'by instances', 'total size' ]
@@ -81,7 +76,7 @@ async function listRedundanciesCLI (target: VideoRedundanciesTarget) {
       totalSize = bytes(tmp)
     }
 
-    const instances = uniq(
+    const instances = uniqify(
       webtorrentFiles.concat(streamingPlaylists)
                      .map(r => r.fileUrl)
                      .map(u => new URL(u).host)
@@ -114,7 +109,7 @@ async function addRedundancyCLI (options: { video: number }, command: Command) {
   }
 
   try {
-    await server.redundancyCommand.addVideo({ videoId: options.video })
+    await server.redundancy.addVideo({ videoId: options.video })
 
     console.log('Video will be duplicated by your instance!')
 
@@ -143,13 +138,13 @@ async function removeRedundancyCLI (options: { video: number }, command: Command
     process.exit(-1)
   }
 
-  const videoId = parseInt(options.video + '', 10)
+  const videoId = forceNumber(options.video)
 
-  const myVideoRedundancies = await server.redundancyCommand.listVideos({ target: 'my-videos' })
+  const myVideoRedundancies = await server.redundancy.listVideos({ target: 'my-videos' })
   let videoRedundancy = myVideoRedundancies.data.find(r => videoId === r.id)
 
   if (!videoRedundancy) {
-    const remoteVideoRedundancies = await server.redundancyCommand.listVideos({ target: 'remote-videos' })
+    const remoteVideoRedundancies = await server.redundancy.listVideos({ target: 'remote-videos' })
     videoRedundancy = remoteVideoRedundancies.data.find(r => videoId === r.id)
   }
 
@@ -164,7 +159,7 @@ async function removeRedundancyCLI (options: { video: number }, command: Command
                                .map(r => r.id)
 
     for (const id of ids) {
-      await server.redundancyCommand.removeVideo({ redundancyId: id })
+      await server.redundancy.removeVideo({ redundancyId: id })
     }
 
     console.log('Video redundancy removed!')