mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-25 18:20:31 -06:00
Server: Add some cli tools to make it easy to upload a lot of videos
This commit is contained in:
parent
2bd3f17127
commit
677618d4a6
@ -11,6 +11,7 @@ const testUtils = {
|
||||
dateIsValid: dateIsValid,
|
||||
flushTests: flushTests,
|
||||
getAllVideosListBy: getAllVideosListBy,
|
||||
getClient: getClient,
|
||||
getFriendsList: getFriendsList,
|
||||
getVideo: getVideo,
|
||||
getVideosList: getVideosList,
|
||||
@ -60,6 +61,17 @@ function getAllVideosListBy (url, end) {
|
||||
.end(end)
|
||||
}
|
||||
|
||||
function getClient (url, end) {
|
||||
const path = '/api/v1/users/client'
|
||||
|
||||
request(url)
|
||||
.get(path)
|
||||
.set('Accept', 'application/json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.end(end)
|
||||
}
|
||||
|
||||
function getFriendsList (url, end) {
|
||||
const path = '/api/v1/pods/'
|
||||
|
||||
@ -390,7 +402,14 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
|
||||
req.field('tags[' + i + ']', tags[i])
|
||||
}
|
||||
|
||||
req.attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture))
|
||||
let filepath = ''
|
||||
if (pathUtils.isAbsolute(fixture)) {
|
||||
filepath = fixture
|
||||
} else {
|
||||
filepath = pathUtils.join(__dirname, 'fixtures', fixture)
|
||||
}
|
||||
|
||||
req.attach('videofile', filepath)
|
||||
.expect(specialStatus)
|
||||
.end(end)
|
||||
}
|
||||
|
44
server/tests/real-world/tools/get-access-token.js
Normal file
44
server/tests/real-world/tools/get-access-token.js
Normal file
@ -0,0 +1,44 @@
|
||||
'use strict'
|
||||
|
||||
const program = require('commander')
|
||||
|
||||
const utils = require('../../api/utils')
|
||||
|
||||
program
|
||||
.option('-u, --url <url>', 'Server url')
|
||||
.option('-n, --username <username>', 'Username')
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.parse(process.argv)
|
||||
|
||||
if (
|
||||
!program.url ||
|
||||
!program.username ||
|
||||
!program.password
|
||||
) {
|
||||
throw new Error('All arguments are required.')
|
||||
}
|
||||
|
||||
const server = {
|
||||
url: program.url,
|
||||
user: {
|
||||
username: program.username,
|
||||
password: program.password
|
||||
},
|
||||
client: {
|
||||
id: null,
|
||||
secret: null
|
||||
}
|
||||
}
|
||||
|
||||
utils.getClient(program.url, function (err, res) {
|
||||
if (err) throw err
|
||||
|
||||
server.client.id = res.body.client_id
|
||||
server.client.secret = res.body.client_secret
|
||||
|
||||
utils.loginAndGetAccessToken(server, function (err, accessToken) {
|
||||
if (err) throw err
|
||||
|
||||
console.log(accessToken)
|
||||
})
|
||||
})
|
67
server/tests/real-world/tools/upload-directory.js
Normal file
67
server/tests/real-world/tools/upload-directory.js
Normal file
@ -0,0 +1,67 @@
|
||||
'use strict'
|
||||
|
||||
const program = require('commander')
|
||||
const eachSeries = require('async/eachSeries')
|
||||
const exec = require('child_process').exec
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
program
|
||||
.option('-u, --url <url>', 'Server url')
|
||||
.option('-n, --username <username>', 'Username')
|
||||
.option('-p, --password <token>', 'Password')
|
||||
.option('-i, --directory <directory>', 'Videos directory absolute path')
|
||||
.option('-d, --description <description>', 'Video description')
|
||||
.option('-t, --tags <tags>', 'Video tags', list)
|
||||
.parse(process.argv)
|
||||
|
||||
if (
|
||||
!program.url ||
|
||||
!program.username ||
|
||||
!program.password ||
|
||||
!program.directory ||
|
||||
!program.description ||
|
||||
!program.tags
|
||||
) {
|
||||
throw new Error('All arguments are required.')
|
||||
}
|
||||
|
||||
exec('node ./get-access-token -u "' + program.url + '" -n "' + program.username + '" -p "' + program.password + '"', function (err, stdout) {
|
||||
if (err) throw err
|
||||
|
||||
const accessToken = stdout.replace('\n', '')
|
||||
|
||||
fs.readdir(program.directory, function (err, files) {
|
||||
if (err) throw err
|
||||
|
||||
eachSeries(files, function (file, callbackEach) {
|
||||
const video = {
|
||||
tags: program.tags,
|
||||
name: file,
|
||||
description: program.description
|
||||
}
|
||||
|
||||
let command = 'node ./upload'
|
||||
command += ' -u "' + program.url + '"'
|
||||
command += ' -a "' + accessToken + '"'
|
||||
command += ' -n "' + video.name + '"'
|
||||
command += ' -d "' + video.description + '"'
|
||||
command += ' -t "' + video.tags.join(',') + '"'
|
||||
command += ' -f "' + path.join(program.directory, file) + '"'
|
||||
|
||||
exec(command, function (err, stdout) {
|
||||
if (err) console.log(err)
|
||||
|
||||
console.log(stdout)
|
||||
|
||||
return callbackEach()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function list (val) {
|
||||
return val.split(',')
|
||||
}
|
57
server/tests/real-world/tools/upload.js
Normal file
57
server/tests/real-world/tools/upload.js
Normal file
@ -0,0 +1,57 @@
|
||||
'use strict'
|
||||
|
||||
const program = require('commander')
|
||||
const fs = require('fs')
|
||||
|
||||
const utils = require('../../api/utils')
|
||||
|
||||
program
|
||||
.option('-u, --url <url>', 'Server url')
|
||||
.option('-a, --access-token <token>', 'Access token')
|
||||
.option('-n, --name <name>', 'Video name')
|
||||
.option('-d, --description <description>', 'Video description')
|
||||
.option('-t, --tags <tags>', 'Video tags', list)
|
||||
.option('-f, --file <file>', 'Video absolute file path')
|
||||
.parse(process.argv)
|
||||
|
||||
if (
|
||||
!program.url ||
|
||||
!program.accessToken ||
|
||||
!program.name ||
|
||||
!program.description ||
|
||||
!program.tags ||
|
||||
!Array.isArray(program.tags) ||
|
||||
program.tags.length === 0 ||
|
||||
!program.file
|
||||
) {
|
||||
throw new Error('All arguments are required.')
|
||||
}
|
||||
|
||||
fs.access(program.file, fs.F_OK, function (err) {
|
||||
if (err) throw err
|
||||
|
||||
upload(
|
||||
program.url,
|
||||
program.accessToken,
|
||||
program.name,
|
||||
program.description,
|
||||
program.tags,
|
||||
program.file
|
||||
)
|
||||
})
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function list (val) {
|
||||
return val.split(',')
|
||||
}
|
||||
|
||||
function upload (url, accessToken, name, description, tags, file) {
|
||||
console.log('Uploading %s video...', program.name)
|
||||
|
||||
utils.uploadVideo(url, accessToken, name, description, tags, file, function (err) {
|
||||
if (err) throw err
|
||||
|
||||
console.log('Video uploaded.')
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user