]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add more CLI tests
authorChocobozzz <me@florianbigard.com>
Thu, 13 Jun 2019 09:09:38 +0000 (11:09 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 13 Jun 2019 09:09:38 +0000 (11:09 +0200)
16 files changed:
package.json
scripts/clean/server/test.sh
scripts/setup/cli.sh
server/helpers/core-utils.ts
server/tests/cli/peertube.ts
server/tools/cli.ts
server/tools/package.json
server/tools/peertube-auth.ts
server/tools/peertube-get-access-token.ts
server/tools/peertube-import-videos.ts
server/tools/peertube-repl.ts
server/tools/peertube-upload.ts
server/tools/peertube.ts
server/tools/yarn.lock
shared/extra-utils/miscs/miscs.ts
yarn.lock

index 3871cec349263b059c9ac7d6c7d61a4d45922dcc..c44ae12b09a6fa34d85e37d65d8af99087402491 100644 (file)
     "body-parser": "^1.12.4",
     "bull": "^3.4.2",
     "bytes": "^3.0.0",
-    "cli-table": "^0.3.1",
     "commander": "^2.13.0",
     "config": "^3.0.0",
     "cookie-parser": "^1.4.3",
     "memoizee": "^0.4.14",
     "morgan": "^1.5.3",
     "multer": "^1.1.0",
-    "netrc-parser": "^3.1.6",
     "nodemailer": "^6.0.0",
     "parse-torrent": "^6.0.0",
     "password-generator": "^2.0.2",
index 34afd6a9d0b2f4ef0b715b91438a5ed250b4a83f..20745170dc3e0ebc47aae7ca6395eb15a7065b48 100755 (executable)
@@ -13,7 +13,7 @@ recreateDB () {
 }
 
 removeFiles () {
-  rm -rf "./test$1" "./config/local-test.json" "./config/local-test-$1.json"
+  rm -rf "./test$1" "./config/local-test.json" "./config/local-test-$1.json" ~/.config/PeerTube/CLI-$1
 }
 
 dropRedis () {
index 9808868d3267abb6a74df3836df317a4c6fb3dd8..f761d7f8a92a0be9f0d976eb33fca790872d6d1b 100755 (executable)
@@ -12,5 +12,4 @@ rm -rf ./dist/server/tools/
 )
 
 npm run tsc -- --build ./server/tools/tsconfig.json
-
-mv "./server/tools/node_modules" "./dist/server/tools"
+cp -r "./server/tools/node_modules" "./dist/server/tools"
index 305d3b71e0143e5d79736b4c6fafac80f700301b..b1e9af0a17a61325b7d8241814ad294498692799 100644 (file)
@@ -134,6 +134,10 @@ function isProdInstance () {
   return process.env.NODE_ENV === 'production'
 }
 
+function getAppNumber () {
+  return process.env.NODE_APP_INSTANCE
+}
+
 function root () {
   // We are in /helpers/utils.js
   const paths = [ __dirname, '..', '..' ]
@@ -256,6 +260,7 @@ const execPromise = promisify1<string, string>(exec)
 export {
   isTestInstance,
   isProdInstance,
+  getAppNumber,
 
   objectConverter,
   root,
index 80bbc98d57382a0bd1b58a48a4ccc41d88663da1..6e7bf0843ee1bd45c7ee5b9721bad8f7436542b9 100644 (file)
@@ -1,28 +1,44 @@
+/* tslint:disable:no-unused-expression */
+
 import 'mocha'
+import { expect } from 'chai'
 import {
-  expect
-} from 'chai'
-import {
+  addVideoChannel,
+  buildAbsoluteFixturePath,
+  cleanupTests,
   createUser,
   execCLI,
-  flushTests,
-  getEnvCli,
-  killallServers,
   flushAndRunServer,
+  getEnvCli,
+  getMyUserInformation,
+  getVideosList,
   ServerInfo,
-  setAccessTokensToServers, cleanupTests
+  setAccessTokensToServers,
+  userLogin, waitJobs
 } from '../../../shared/extra-utils'
+import { User, Video } from '../../../shared'
+import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
 
 describe('Test CLI wrapper', function () {
   let server: ServerInfo
+  let channelId: number
+
   const cmd = 'node ./dist/server/tools/peertube.js'
 
   before(async function () {
     this.timeout(30000)
+
     server = await flushAndRunServer(1)
     await setAccessTokensToServers([ server ])
 
-    await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' })
+    await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
+
+    const userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
+
+    {
+      const res = await addVideoChannel(server.url, userAccessToken, { name: 'user_channel', displayName: 'User channel' })
+      channelId = res.body.videoChannel.id
+    }
   })
 
   it('Should display no selected instance', async function () {
@@ -31,21 +47,95 @@ describe('Test CLI wrapper', function () {
     const env = getEnvCli(server)
     const stdout = await execCLI(`${env} ${cmd} --help`)
 
-    expect(stdout).to.contain('selected')
+    expect(stdout).to.contain('no instance selected')
+  })
+
+  it('Should add a user', async function () {
+    this.timeout(60000)
+
+    const env = getEnvCli(server)
+    await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
+  })
+
+  it('Should default to this user', async function () {
+    this.timeout(60000)
+
+    const env = getEnvCli(server)
+    const stdout = await execCLI(`${env} ${cmd} --help`)
+
+    expect(stdout).to.contain(`instance ${server.url} selected`)
+  })
+
+  it('Should remember the user', async function () {
+    this.timeout(60000)
+
+    const env = getEnvCli(server)
+    const stdout = await execCLI(`${env} ${cmd} auth list`)
+
+    expect(stdout).to.contain(server.url)
+  })
+
+  it('Should upload a video', async function () {
+    this.timeout(60000)
+
+    const env = getEnvCli(server)
+
+    const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
+
+    const params = `-f ${fixture} --video-name 'test upload' --channel-id ${channelId}`
+
+    await execCLI(`${env} ${cmd} upload ${params}`)
+  })
+
+  it('Should have the video uploaded', async function () {
+    const res = await getVideosList(server.url)
+
+    expect(res.body.total).to.equal(1)
+
+    const videos: Video[] = res.body.data
+    expect(videos[0].name).to.equal('test upload')
+    expect(videos[0].channel.name).to.equal('user_channel')
+  })
+
+  it('Should import a video', async function () {
+    this.timeout(60000)
+
+    const env = getEnvCli(server)
+
+    const params = `--target-url ${getYoutubeVideoUrl()} --channel-id ${channelId}`
+
+    await execCLI(`${env} ${cmd} import ${params}`)
   })
 
-  it('Should remember the authentifying material of the user', async function () {
+  it('Should have imported the video', async function () {
     this.timeout(60000)
 
+    await waitJobs([ server ])
+
+    const res = await getVideosList(server.url)
+
+    expect(res.body.total).to.equal(2)
+
+    const videos: Video[] = res.body.data
+    const video = videos.find(v => v.name === 'small video - youtube')
+
+    expect(video).to.not.be.undefined
+    expect(video.channel.name).to.equal('user_channel')
+  })
+
+  it('Should remove the auth user', async function () {
     const env = getEnvCli(server)
-    await execCLI(`${env} ` + cmd + ` auth add --url ${server.url} -U user_1 -p "super password"`)
+
+    await execCLI(`${env} ${cmd} auth del ${server.url}`)
+
+    const stdout = await execCLI(`${env} ${cmd} --help`)
+
+    expect(stdout).to.contain('no instance selected')
   })
 
   after(async function () {
     this.timeout(10000)
 
-    await execCLI(cmd + ` auth del ${server.url}`)
-
     await cleanupTests([ server ])
   })
 })
index e83a8a63c64fb0640b0bd811f3d6996738f2d73f..6be558d7bb4a1db4c21b9a7be3ab86440803bdf6 100644 (file)
@@ -1,5 +1,12 @@
-const config = require('application-config')('PeerTube/CLI')
-const netrc = require('netrc-parser').default
+import { Netrc } from 'netrc-parser'
+import { isTestInstance, getAppNumber } from '../helpers/core-utils'
+import { join } from 'path'
+import { root } from '../../shared/extra-utils'
+
+let configName = 'PeerTube/CLI'
+if (isTestInstance()) configName += `-${getAppNumber()}`
+
+const config = require('application-config')(configName)
 
 const version = require('../../../package.json').version
 
@@ -12,7 +19,7 @@ function getSettings () {
   return new Promise<Settings>((res, rej) => {
     const defaultSettings = {
       remotes: [],
-      default: 0
+      default: -1
     }
 
     config.read((err, data) => {
@@ -24,6 +31,12 @@ function getSettings () {
 }
 
 async function getNetrc () {
+  const Netrc = require('netrc-parser').Netrc
+
+  const netrc = isTestInstance()
+    ? new Netrc(join(root(), 'test' + getAppNumber(), 'netrc'))
+    : new Netrc()
+
   await netrc.load()
 
   return netrc
@@ -31,7 +44,17 @@ async function getNetrc () {
 
 function writeSettings (settings) {
   return new Promise((res, rej) => {
-    config.write(settings, function (err) {
+    config.write(settings, err => {
+      if (err) return rej(err)
+
+      return res()
+    })
+  })
+}
+
+function deleteSettings () {
+  return new Promise((res, rej) => {
+    config.trash((err) => {
       if (err) return rej(err)
 
       return res()
@@ -39,9 +62,9 @@ function writeSettings (settings) {
   })
 }
 
-function getRemoteObjectOrDie (program: any, settings: Settings) {
+function getRemoteObjectOrDie (program: any, settings: Settings, netrc: Netrc) {
   if (!program['url'] || !program['username'] || !program['password']) {
-    // No remote and we don't have program parameters: throw
+    // No remote and we don't have program parameters: quit
     if (settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) {
       if (!program[ 'url' ]) console.error('--url field is required.')
       if (!program[ 'username' ]) console.error('--username field is required.')
@@ -54,15 +77,12 @@ function getRemoteObjectOrDie (program: any, settings: Settings) {
     let username: string = program['username']
     let password: string = program['password']
 
-    if (!url) {
-      url = settings.default !== -1
-        ? settings.remotes[settings.default]
-        : settings.remotes[0]
-    }
+    if (!url && settings.default !== -1) url = settings.remotes[settings.default]
 
     const machine = netrc.machines[url]
-    if (!username) username = machine.login
-    if (!password) password = machine.password
+
+    if (!username && machine) username = machine.login
+    if (!password && machine) password = machine.password
 
     return { url, username, password }
   }
@@ -82,5 +102,6 @@ export {
   getSettings,
   getNetrc,
   getRemoteObjectOrDie,
-  writeSettings
+  writeSettings,
+  deleteSettings
 }
index 2d13d41cc506b491cf82a2a1333d95b90024621a..22fb8d24cbc032d0e5f16ce302e8d3a5c8021680 100644 (file)
@@ -4,6 +4,8 @@
   "private": true,
   "dependencies": {
     "application-config": "^1.0.1",
+    "cli-table": "^0.3.1",
+    "netrc-parser": "^3.1.6",
     "webtorrent-hybrid": "^2.1.0"
   },
   "summon": {
index e53283fbe7805c6928c279518bd1dad1772917fe..ff5ffb60e90a36a56009df2359df7d0c2c52bec0 100644 (file)
@@ -9,7 +9,11 @@ const Table = require('cli-table')
 async function delInstance (url: string) {
   const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
 
-  settings.remotes.splice(settings.remotes.indexOf(url))
+  const index = settings.remotes.indexOf(url)
+  settings.remotes.splice(index)
+
+  if (settings.default === index) settings.default = -1
+
   await writeSettings(settings)
 
   delete netrc.machines[url]
@@ -17,12 +21,17 @@ async function delInstance (url: string) {
   await netrc.save()
 }
 
-async function setInstance (url: string, username: string, password: string) {
+async function setInstance (url: string, username: string, password: string, isDefault: boolean) {
   const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
 
   if (settings.remotes.indexOf(url) === -1) {
     settings.remotes.push(url)
   }
+
+  if (isDefault || settings.remotes.length === 1) {
+    settings.default = settings.remotes.length - 1
+  }
+
   await writeSettings(settings)
 
   netrc.machines[url] = { login: username, password }
@@ -66,7 +75,7 @@ program
         }
       }
     }, async (_, result) => {
-      await setInstance(result.url, result.username, result.password)
+      await setInstance(result.url, result.username, result.password, program['default'])
 
       process.exit(0)
     })
index 85660de2c9c0716b268f570c28f146a872d1ab09..103495347c7ca6025d3a23ba365ecb51749e7c08 100644 (file)
@@ -1,12 +1,5 @@
 import * as program from 'commander'
-
-import {
-  getClient,
-  serverLogin,
-  Server,
-  Client,
-  User
-} from '../../shared/extra-utils'
+import { getClient, Server, serverLogin } from '../../shared/extra-utils'
 
 program
   .option('-u, --url <url>', 'Server url')
@@ -22,6 +15,7 @@ if (
   if (!program['url']) console.error('--url field is required.')
   if (!program['username']) console.error('--username field is required.')
   if (!program['password']) console.error('--password field is required.')
+
   process.exit(-1)
 }
 
@@ -32,11 +26,11 @@ getClient(program.url)
       user: {
         username: program['username'],
         password: program['password']
-      } as User,
+      },
       client: {
-        id: res.body.client_id as string,
-        secret: res.body.client_secret as string
-      } as Client
+        id: res.body.client_id,
+        secret: res.body.client_secret
+      }
     } as Server
 
     return serverLogin(server)
index 9a366dbbda3bca26376bb11f3f577a8a5eeafe87..f9cd3106af3e2042f7f8e4dc22a37f4ebc56e318 100644 (file)
@@ -14,8 +14,10 @@ import { sha256 } from '../helpers/core-utils'
 import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl'
 import { getNetrc, getRemoteObjectOrDie, getSettings } from './cli'
 
-let accessToken: string
-let client: { id: string, secret: string }
+type UserInfo = {
+  username: string
+  password: string
+}
 
 const processOptions = {
   cwd: __dirname,
@@ -28,13 +30,14 @@ program
   .option('-U, --username <username>', 'Username')
   .option('-p, --password <token>', 'Password')
   .option('-t, --target-url <targetUrl>', 'Video target URL')
+  .option('-C, --channel-id <channel_id>', 'Channel ID')
   .option('-l, --language <languageCode>', 'Language ISO 639 code (fr or en...)')
   .option('-v, --verbose', 'Verbose mode')
   .parse(process.argv)
 
 Promise.all([ getSettings(), getNetrc() ])
        .then(([ settings, netrc ]) => {
-         const { url, username, password } = getRemoteObjectOrDie(program, settings)
+         const { url, username, password } = getRemoteObjectOrDie(program, settings, netrc)
 
          if (!program[ 'targetUrl' ]) {
            console.error('--targetUrl field is required.')
@@ -45,56 +48,20 @@ Promise.all([ getSettings(), getNetrc() ])
          removeEndSlashes(url)
          removeEndSlashes(program[ 'targetUrl' ])
 
-         const user = {
-           username: username,
-           password: password
-         }
+         const user = { username, password }
 
-         run(user, url)
+         run(url, user)
            .catch(err => {
              console.error(err)
              process.exit(-1)
            })
        })
 
-async function promptPassword () {
-  return new Promise((res, rej) => {
-    prompt.start()
-    const schema = {
-      properties: {
-        password: {
-          hidden: true,
-          required: true
-        }
-      }
-    }
-    prompt.get(schema, function (err, result) {
-      if (err) {
-        return rej(err)
-      }
-      return res(result.password)
-    })
-  })
-}
-
-async function run (user, url: string) {
+async function run (url: string, user: UserInfo) {
   if (!user.password) {
     user.password = await promptPassword()
   }
 
-  const res = await getClient(url)
-  client = {
-    id: res.body.client_id,
-    secret: res.body.client_secret
-  }
-
-  try {
-    const res = await login(program[ 'url' ], client, user)
-    accessToken = res.body.access_token
-  } catch (err) {
-    throw new Error('Cannot authenticate. Please check your username/password.')
-  }
-
   const youtubeDL = await safeGetYoutubeDL()
 
   const options = [ '-j', '--flat-playlist', '--playlist-reverse' ]
@@ -115,7 +82,12 @@ async function run (user, url: string) {
     console.log('Will download and upload %d videos.\n', infoArray.length)
 
     for (const info of infoArray) {
-      await processVideo(info, program[ 'language' ], processOptions.cwd, url, user)
+      await processVideo({
+        cwd: processOptions.cwd,
+        url,
+        user,
+        youtubeInfo: info
+      })
     }
 
     console.log('Video/s for user %s imported: %s', program[ 'username' ], program[ 'targetUrl' ])
@@ -123,11 +95,18 @@ async function run (user, url: string) {
   })
 }
 
-function processVideo (info: any, languageCode: string, cwd: string, url: string, user) {
+function processVideo (parameters: {
+  cwd: string,
+  url: string,
+  user: { username: string, password: string },
+  youtubeInfo: any
+}) {
+  const { youtubeInfo, cwd, url, user } = parameters
+
   return new Promise(async res => {
-    if (program[ 'verbose' ]) console.log('Fetching object.', info)
+    if (program[ 'verbose' ]) console.log('Fetching object.', youtubeInfo)
 
-    const videoInfo = await fetchObject(info)
+    const videoInfo = await fetchObject(youtubeInfo)
     if (program[ 'verbose' ]) console.log('Fetched object.', videoInfo)
 
     const result = await searchVideoWithSort(url, videoInfo.title, '-match')
@@ -153,7 +132,13 @@ function processVideo (info: any, languageCode: string, cwd: string, url: string
         }
 
         console.log(output.join('\n'))
-        await uploadVideoOnPeerTube(normalizeObject(videoInfo), path, cwd, url, user, languageCode)
+        await uploadVideoOnPeerTube({
+          cwd,
+          url,
+          user,
+          videoInfo: normalizeObject(videoInfo),
+          videoPath: path
+        })
         return res()
       })
     } catch (err) {
@@ -163,7 +148,15 @@ function processVideo (info: any, languageCode: string, cwd: string, url: string
   })
 }
 
-async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: string, url: string, user, language?: string) {
+async function uploadVideoOnPeerTube (parameters: {
+  videoInfo: any,
+  videoPath: string,
+  cwd: string,
+  url: string,
+  user: { username: string; password: string }
+}) {
+  const { videoInfo, videoPath, cwd, url, user } = parameters
+
   const category = await getCategory(videoInfo.categories, url)
   const licence = getLicence(videoInfo.license)
   let tags = []
@@ -194,7 +187,7 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: st
     }),
     category,
     licence,
-    language,
+    language: program[ 'language' ],
     nsfw: isNSFW(videoInfo),
     waitTranscoding: true,
     commentsEnabled: true,
@@ -209,15 +202,21 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: st
     originallyPublishedAt: originallyPublishedAt ? originallyPublishedAt.toISOString() : null
   }
 
+  if (program[ 'channelId' ]) {
+    Object.assign(videoAttributes, { channelId: program['channelId'] })
+  }
+
   console.log('\nUploading on PeerTube video "%s".', videoAttributes.name)
+
+  let accessToken = await getAccessTokenOrDie(url, user)
+
   try {
     await uploadVideo(url, accessToken, videoAttributes)
   } catch (err) {
     if (err.message.indexOf('401') !== -1) {
       console.log('Got 401 Unauthorized, token may have expired, renewing token and retry.')
 
-      const res = await login(url, client, user)
-      accessToken = res.body.access_token
+      accessToken = await getAccessTokenOrDie(url, user)
 
       await uploadVideo(url, accessToken, videoAttributes)
     } else {
@@ -232,6 +231,8 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, cwd: st
   console.log('Uploaded video "%s"!\n', videoAttributes.name)
 }
 
+/* ---------------------------------------------------------- */
+
 async function getCategory (categories: string[], url: string) {
   if (!categories) return undefined
 
@@ -250,8 +251,6 @@ async function getCategory (categories: string[], url: string) {
   return undefined
 }
 
-/* ---------------------------------------------------------- */
-
 function getLicence (licence: string) {
   if (!licence) return undefined
 
@@ -305,9 +304,7 @@ function buildUrl (info: any) {
 }
 
 function isNSFW (info: any) {
-  if (info.age_limit && info.age_limit >= 16) return true
-
-  return false
+  return info.age_limit && info.age_limit >= 16
 }
 
 function removeEndSlashes (url: string) {
@@ -315,3 +312,39 @@ function removeEndSlashes (url: string) {
     url.slice(0, -1)
   }
 }
+
+async function promptPassword () {
+  return new Promise<string>((res, rej) => {
+    prompt.start()
+    const schema = {
+      properties: {
+        password: {
+          hidden: true,
+          required: true
+        }
+      }
+    }
+    prompt.get(schema, function (err, result) {
+      if (err) {
+        return rej(err)
+      }
+      return res(result.password)
+    })
+  })
+}
+
+async function getAccessTokenOrDie (url: string, user: UserInfo) {
+  const resClient = await getClient(url)
+  const client = {
+    id: resClient.body.client_id,
+    secret: resClient.body.client_secret
+  }
+
+  try {
+    const res = await login(url, client, user)
+    return res.body.access_token
+  } catch (err) {
+    console.error('Cannot authenticate. Please check your username/password.')
+    process.exit(-1)
+  }
+}
index 04d8b95a3076b4736bb1b76a23727f650ecc4561..fbdec16132ad0580ae500a9b15be6cdf47eae3b3 100644 (file)
@@ -43,7 +43,7 @@ const start = async () => {
         Object.defineProperty(context, prop, {
           configurable: false,
           enumerable: true,
-          value: properties[prop]
+          value: properties[ prop ]
         })
       }
     }
@@ -69,8 +69,7 @@ const start = async () => {
 
 }
 
-start().then((data) => {
-  // do nothing
-}).catch((err) => {
-  console.error(err)
-})
+start()
+  .catch((err) => {
+    console.error(err)
+  })
index bfce10e541a538ad9a7b0450f4b61360629adfff..1da52da310c4f804b48a332b2ecf1e3da93e1b8c 100644 (file)
@@ -4,7 +4,7 @@ import { isAbsolute } from 'path'
 import { getClient, login } from '../../shared/extra-utils'
 import { uploadVideo } from '../../shared/extra-utils/'
 import { VideoPrivacy } from '../../shared/models/videos'
-import { getRemoteObjectOrDie, getSettings } from './cli'
+import { getNetrc, getRemoteObjectOrDie, getSettings } from './cli'
 
 program
   .name('upload')
@@ -26,31 +26,31 @@ program
   .option('-f, --file <file>', 'Video absolute file path')
   .parse(process.argv)
 
-getSettings()
-  .then(settings => {
-    const { url, username, password } = getRemoteObjectOrDie(program, settings)
+Promise.all([ getSettings(), getNetrc() ])
+       .then(([ settings, netrc ]) => {
+         const { url, username, password } = getRemoteObjectOrDie(program, settings, netrc)
 
-    if (!program['videoName'] || !program['file'] || !program['channelId']) {
-      if (!program['videoName']) console.error('--video-name is required.')
-      if (!program['file']) console.error('--file is required.')
-      if (!program['channelId']) console.error('--channel-id is required.')
+         if (!program[ 'videoName' ] || !program[ 'file' ] || !program[ 'channelId' ]) {
+           if (!program[ 'videoName' ]) console.error('--video-name is required.')
+           if (!program[ 'file' ]) console.error('--file is required.')
+           if (!program[ 'channelId' ]) console.error('--channel-id is required.')
 
-      process.exit(-1)
-    }
+           process.exit(-1)
+         }
 
-    if (isAbsolute(program['file']) === false) {
-      console.error('File path should be absolute.')
-      process.exit(-1)
-    }
+         if (isAbsolute(program[ 'file' ]) === false) {
+           console.error('File path should be absolute.')
+           process.exit(-1)
+         }
 
-    run(url, username, password).catch(err => {
-      console.error(err)
-      process.exit(-1)
-    })
-  })
+         run(url, username, password).catch(err => {
+           console.error(err)
+           process.exit(-1)
+         })
+       })
 
 async function run (url: string, username: string, password: string) {
-  const resClient = await getClient(program[ 'url' ])
+  const resClient = await getClient(url)
   const client = {
     id: resClient.body.client_id,
     secret: resClient.body.client_secret
@@ -71,27 +71,27 @@ async function run (url: string, username: string, password: string) {
   console.log('Uploading %s video...', program[ 'videoName' ])
 
   const videoAttributes = {
-    name: program['videoName'],
-    category: program['category'] || undefined,
-    channelId: program['channelId'],
-    licence: program['licence'] || undefined,
-    language: program['language'] || undefined,
-    nsfw: program['nsfw'] !== undefined ? program['nsfw'] : false,
-    description: program['videoDescription'] || undefined,
-    tags: program['tags'] || [],
-    commentsEnabled: program['commentsEnabled'] !== undefined ? program['commentsEnabled'] : true,
-    downloadEnabled: program['downloadEnabled'] !== undefined ? program['downloadEnabled'] : true,
-    fixture: program['file'],
-    thumbnailfile: program['thumbnail'],
-    previewfile: program['preview'],
+    name: program[ 'videoName' ],
+    category: program[ 'category' ] || undefined,
+    channelId: program[ 'channelId' ],
+    licence: program[ 'licence' ] || undefined,
+    language: program[ 'language' ] || undefined,
+    nsfw: program[ 'nsfw' ] !== undefined ? program[ 'nsfw' ] : false,
+    description: program[ 'videoDescription' ] || undefined,
+    tags: program[ 'tags' ] || [],
+    commentsEnabled: program[ 'commentsEnabled' ] !== undefined ? program[ 'commentsEnabled' ] : true,
+    downloadEnabled: program[ 'downloadEnabled' ] !== undefined ? program[ 'downloadEnabled' ] : true,
+    fixture: program[ 'file' ],
+    thumbnailfile: program[ 'thumbnail' ],
+    previewfile: program[ 'preview' ],
     waitTranscoding: true,
-    privacy: program['privacy'] || VideoPrivacy.PUBLIC,
+    privacy: program[ 'privacy' ] || VideoPrivacy.PUBLIC,
     support: undefined
   }
 
   try {
     await uploadVideo(url, accessToken, videoAttributes)
-    console.log(`Video ${program['videoName']} uploaded.`)
+    console.log(`Video ${program[ 'videoName' ]} uploaded.`)
     process.exit(0)
   } catch (err) {
     console.error(require('util').inspect(err))
index 5d3ab2815db44f1534415fc262849749917322c3..daa5586c313ef0602b3935fe13af465da3b05527 100644 (file)
@@ -63,9 +63,10 @@ if (!process.argv.slice(2).length) {
 
 getSettings()
   .then(settings => {
-    const state = (settings.default === undefined || settings.default === -1) ?
-      'no instance selected, commands will require explicit arguments' :
-      ('instance ' + settings.remotes[settings.default] + ' selected')
+    const state = (settings.default === undefined || settings.default === -1)
+      ? 'no instance selected, commands will require explicit arguments'
+      : 'instance ' + settings.remotes[settings.default] + ' selected'
+
     program
       .on('--help', function () {
         console.log()
index 3c3778d3f1a0a3a229bc12708aa336a9c3459590..7ef68fc71d986d69012c5a3e4ae4da0565e484ba 100644 (file)
@@ -293,6 +293,13 @@ chunk-store-stream@^3.0.1:
     block-stream2 "^1.0.0"
     readable-stream "^2.0.5"
 
+cli-table@^0.3.1:
+  version "0.3.1"
+  resolved "https://registry.yarnpkg.com/cli-table/-/cli-table-0.3.1.tgz#f53b05266a8b1a0b934b3d0821e6e2dc5914ae23"
+  integrity sha1-9TsFJmqLGguTSz0IIebi3FkUriM=
+  dependencies:
+    colors "1.0.3"
+
 cliui@^3.2.0:
   version "3.2.0"
   resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d"
@@ -317,6 +324,11 @@ code-point-at@^1.0.0:
   resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
   integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=
 
+colors@1.0.3:
+  version "1.0.3"
+  resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
+  integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=
+
 colour@latest:
   version "0.7.1"
   resolved "https://registry.yarnpkg.com/colour/-/colour-0.7.1.tgz#9cb169917ec5d12c0736d3e8685746df1cadf778"
@@ -373,6 +385,17 @@ create-torrent@^3.23.1, create-torrent@^3.33.0:
     run-parallel "^1.0.0"
     simple-sha1 "^2.0.0"
 
+cross-spawn@^6.0.0:
+  version "6.0.5"
+  resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
+  integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
+  dependencies:
+    nice-try "^1.0.4"
+    path-key "^2.0.1"
+    semver "^5.5.0"
+    shebang-command "^1.2.0"
+    which "^1.2.9"
+
 debug@^2.1.0, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0:
   version "2.6.9"
   resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@@ -493,6 +516,19 @@ error-ex@^1.2.0:
   dependencies:
     is-arrayish "^0.2.1"
 
+execa@^0.10.0:
+  version "0.10.0"
+  resolved "https://registry.yarnpkg.com/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50"
+  integrity sha512-7XOMnz8Ynx1gGo/3hyV9loYNPWM94jG3+3T3Y8tsfSstFmETmENCMU/A/zj8Lyaj1lkgEepKepvd6240tBRvlw==
+  dependencies:
+    cross-spawn "^6.0.0"
+    get-stream "^3.0.0"
+    is-stream "^1.1.0"
+    npm-run-path "^2.0.0"
+    p-finally "^1.0.0"
+    signal-exit "^3.0.0"
+    strip-eof "^1.0.0"
+
 executable@^4.0.0:
   version "4.1.1"
   resolved "https://registry.yarnpkg.com/executable/-/executable-4.1.1.tgz#41532bff361d3e57af4d763b70582db18f5d133c"
@@ -576,6 +612,11 @@ get-stdin@^6.0.0:
   resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
   integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
 
+get-stream@^3.0.0:
+  version "3.0.0"
+  resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14"
+  integrity sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=
+
 glob@^7.1.3:
   version "7.1.4"
   resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
@@ -694,6 +735,11 @@ is-fullwidth-code-point@^2.0.0:
   resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
   integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=
 
+is-stream@^1.1.0:
+  version "1.1.0"
+  resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
+  integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=
+
 is-typedarray@^1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
@@ -963,6 +1009,14 @@ netmask@^1.0.6:
   resolved "https://registry.yarnpkg.com/netmask/-/netmask-1.0.6.tgz#20297e89d86f6f6400f250d9f4f6b4c1945fcd35"
   integrity sha1-ICl+idhvb2QA8lDZ9Pa0wZRfzTU=
 
+netrc-parser@^3.1.6:
+  version "3.1.6"
+  resolved "https://registry.yarnpkg.com/netrc-parser/-/netrc-parser-3.1.6.tgz#7243c9ec850b8e805b9bdc7eae7b1450d4a96e72"
+  integrity sha512-lY+fmkqSwntAAjfP63jB4z5p5WbuZwyMCD3pInT7dpHU/Gc6Vv90SAC6A0aNiqaRGHiuZFBtiwu+pu8W/Eyotw==
+  dependencies:
+    debug "^3.1.0"
+    execa "^0.10.0"
+
 network-address@^1.0.0, network-address@^1.1.0:
   version "1.1.2"
   resolved "https://registry.yarnpkg.com/network-address/-/network-address-1.1.2.tgz#4aa7bfd43f03f0b81c9702b13d6a858ddb326f3e"
@@ -973,6 +1027,11 @@ next-event@^1.0.0:
   resolved "https://registry.yarnpkg.com/next-event/-/next-event-1.0.0.tgz#e7778acde2e55802e0ad1879c39cf6f75eda61d8"
   integrity sha1-53eKzeLlWALgrRh5w5z2917aYdg=
 
+nice-try@^1.0.4:
+  version "1.0.5"
+  resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
+  integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
+
 node-cmake@2.3.2:
   version "2.3.2"
   resolved "https://registry.yarnpkg.com/node-cmake/-/node-cmake-2.3.2.tgz#e0fbc54b11405b07705e4d6d41865ae95ad289d0"
@@ -1049,6 +1108,13 @@ npm-packlist@^1.1.6:
     ignore-walk "^3.0.1"
     npm-bundled "^1.0.1"
 
+npm-run-path@^2.0.0:
+  version "2.0.2"
+  resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
+  integrity sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=
+  dependencies:
+    path-key "^2.0.0"
+
 npmlog@^4.0.2:
   version "4.1.2"
   resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b"
@@ -1111,6 +1177,11 @@ osenv@^0.1.4:
     os-homedir "^1.0.0"
     os-tmpdir "^1.0.0"
 
+p-finally@^1.0.0:
+  version "1.0.0"
+  resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
+  integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=
+
 package-json-versionify@^1.0.2:
   version "1.0.4"
   resolved "https://registry.yarnpkg.com/package-json-versionify/-/package-json-versionify-1.0.4.tgz#5860587a944873a6b7e6d26e8e51ffb22315bf17"
@@ -1155,6 +1226,11 @@ path-is-absolute@^1.0.0:
   resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
   integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
 
+path-key@^2.0.0, path-key@^2.0.1:
+  version "2.0.1"
+  resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
+  integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
+
 path-parse@^1.0.6:
   version "1.0.6"
   resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
@@ -1400,7 +1476,7 @@ sax@>=0.6.0, sax@^1.2.4:
   resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
   integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
 
-"semver@2 || 3 || 4 || 5", semver@^5.3.0:
+"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.5.0:
   version "5.7.0"
   resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b"
   integrity sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==
@@ -1415,6 +1491,18 @@ set-blocking@^2.0.0, set-blocking@~2.0.0:
   resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
   integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc=
 
+shebang-command@^1.2.0:
+  version "1.2.0"
+  resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
+  integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=
+  dependencies:
+    shebang-regex "^1.0.0"
+
+shebang-regex@^1.0.0:
+  version "1.0.0"
+  resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
+  integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
+
 signal-exit@^3.0.0:
   version "3.0.2"
   resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
@@ -1591,6 +1679,11 @@ strip-bom@^2.0.0:
   dependencies:
     is-utf8 "^0.2.0"
 
+strip-eof@^1.0.0:
+  version "1.0.0"
+  resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
+  integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=
+
 strip-json-comments@~2.0.1:
   version "2.0.1"
   resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
@@ -1855,7 +1948,7 @@ which-module@^1.0.0:
   resolved "https://registry.yarnpkg.com/which-module/-/which-module-1.0.0.tgz#bba63ca861948994ff307736089e3b96026c2a4f"
   integrity sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=
 
-which@^1.2.14:
+which@^1.2.14, which@^1.2.9:
   version "1.3.1"
   resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
   integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==
index d1ffb7be426044ef940320d88acbbe48ff6dd3a8..fb6430e4f19a760aa33d4dcc8137573b5cdd2fd9 100644 (file)
@@ -1,7 +1,7 @@
 /* tslint:disable:no-unused-expression */
 
 import * as chai from 'chai'
-import { isAbsolute, join } from 'path'
+import { basename, isAbsolute, join, resolve } from 'path'
 import * as request from 'supertest'
 import * as WebTorrent from 'webtorrent'
 import { pathExists, readFile } from 'fs-extra'
@@ -34,7 +34,11 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
 
 function root () {
   // We are in /miscs
-  return join(__dirname, '..', '..', '..')
+  let root = join(__dirname, '..', '..', '..')
+
+  if (basename(root) === 'dist') root = resolve(root, '..')
+
+  return root
 }
 
 async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
index ce086c03cf3768211842356f6504420172bfd6d7..18a0f2611f28a88bf378f6fc2fde0ffba3203f87 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -1372,13 +1372,6 @@ cli-cursor@^2.0.0, cli-cursor@^2.1.0:
   dependencies:
     restore-cursor "^2.0.0"
 
-cli-table@^0.3.1:
-  version "0.3.1"
-  resolved "https://registry.yarnpkg.com/cli-table/-/cli-table-0.3.1.tgz#f53b05266a8b1a0b934b3d0821e6e2dc5914ae23"
-  integrity sha1-9TsFJmqLGguTSz0IIebi3FkUriM=
-  dependencies:
-    colors "1.0.3"
-
 cli-truncate@^0.2.1:
   version "0.2.1"
   resolved "https://registry.yarnpkg.com/cli-truncate/-/cli-truncate-0.2.1.tgz#9f15cfbb0705005369216c626ac7d05ab90dd574"
@@ -1505,7 +1498,7 @@ colornames@^1.1.1:
   resolved "https://registry.yarnpkg.com/colornames/-/colornames-1.1.1.tgz#f8889030685c7c4ff9e2a559f5077eb76a816f96"
   integrity sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y=
 
-colors@1.0.3, colors@1.0.x:
+colors@1.0.x:
   version "1.0.3"
   resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
   integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=
@@ -2435,19 +2428,6 @@ event-emitter@^0.3.5, event-emitter@~0.3.5:
     d "1"
     es5-ext "~0.10.14"
 
-execa@^0.10.0:
-  version "0.10.0"
-  resolved "https://registry.yarnpkg.com/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50"
-  integrity sha512-7XOMnz8Ynx1gGo/3hyV9loYNPWM94jG3+3T3Y8tsfSstFmETmENCMU/A/zj8Lyaj1lkgEepKepvd6240tBRvlw==
-  dependencies:
-    cross-spawn "^6.0.0"
-    get-stream "^3.0.0"
-    is-stream "^1.1.0"
-    npm-run-path "^2.0.0"
-    p-finally "^1.0.0"
-    signal-exit "^3.0.0"
-    strip-eof "^1.0.0"
-
 execa@^0.7.0:
   version "0.7.0"
   resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777"
@@ -4845,14 +4825,6 @@ netmask@^1.0.6:
   resolved "https://registry.yarnpkg.com/netmask/-/netmask-1.0.6.tgz#20297e89d86f6f6400f250d9f4f6b4c1945fcd35"
   integrity sha1-ICl+idhvb2QA8lDZ9Pa0wZRfzTU=
 
-netrc-parser@^3.1.6:
-  version "3.1.6"
-  resolved "https://registry.yarnpkg.com/netrc-parser/-/netrc-parser-3.1.6.tgz#7243c9ec850b8e805b9bdc7eae7b1450d4a96e72"
-  integrity sha512-lY+fmkqSwntAAjfP63jB4z5p5WbuZwyMCD3pInT7dpHU/Gc6Vv90SAC6A0aNiqaRGHiuZFBtiwu+pu8W/Eyotw==
-  dependencies:
-    debug "^3.1.0"
-    execa "^0.10.0"
-
 next-event@^1.0.0:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/next-event/-/next-event-1.0.0.tgz#e7778acde2e55802e0ad1879c39cf6f75eda61d8"