aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/real-world
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/real-world')
-rw-r--r--server/tests/real-world/tools/get-access-token.ts48
-rw-r--r--server/tests/real-world/tools/upload-directory.ts82
-rw-r--r--server/tests/real-world/tools/upload.ts85
3 files changed, 0 insertions, 215 deletions
diff --git a/server/tests/real-world/tools/get-access-token.ts b/server/tests/real-world/tools/get-access-token.ts
deleted file mode 100644
index ee14733e3..000000000
--- a/server/tests/real-world/tools/get-access-token.ts
+++ /dev/null
@@ -1,48 +0,0 @@
1import * as program from 'commander'
2
3import {
4 getClient,
5 serverLogin
6} from '../../utils'
7
8program
9 .option('-u, --url <url>', 'Server url')
10 .option('-n, --username <username>', 'Username')
11 .option('-p, --password <token>', 'Password')
12 .parse(process.argv)
13
14if (
15 !program['url'] ||
16 !program['username'] ||
17 !program['password']
18) {
19 throw new Error('All arguments are required.')
20}
21
22const server = {
23 url: program['url'],
24 user: {
25 username: program['username'],
26 password: program['password']
27 },
28 client: {
29 id: null,
30 secret: null
31 }
32}
33
34getClient(program.url)
35 .then(res => {
36 server.client.id = res.body.client_id
37 server.client.secret = res.body.client_secret
38
39 return serverLogin(server)
40 })
41 .then(accessToken => {
42 console.log(accessToken)
43 process.exit(0)
44 })
45 .catch(err => {
46 console.error(err)
47 process.exit(-1)
48 })
diff --git a/server/tests/real-world/tools/upload-directory.ts b/server/tests/real-world/tools/upload-directory.ts
deleted file mode 100644
index fdd56857a..000000000
--- a/server/tests/real-world/tools/upload-directory.ts
+++ /dev/null
@@ -1,82 +0,0 @@
1import * as program from 'commander'
2import * as Promise from 'bluebird'
3import { isAbsolute, join } from 'path'
4
5import { readdirPromise } from '../../../helpers/core-utils'
6import { execCLI } from '../../utils'
7
8program
9 .option('-u, --url <url>', 'Server url')
10 .option('-U, --username <username>', 'Username')
11 .option('-p, --password <token>', 'Password')
12 .option('-i, --input <directory>', 'Videos directory absolute path')
13 .option('-d, --description <description>', 'Video descriptions')
14 .option('-c, --category <category>', 'Video categories')
15 .option('-l, --licence <licence>', 'Video licences')
16 .option('-t, --tags <tags>', 'Video tags', list)
17 .parse(process.argv)
18
19if (
20 !program['url'] ||
21 !program['username'] ||
22 !program['password'] ||
23 !program['input'] ||
24 !program['description'] ||
25 !program['category'] ||
26 !program['licence'] ||
27 !program['tags']
28) {
29 throw new Error('All arguments are required.')
30}
31
32if (isAbsolute(program['input']) === false) {
33 throw new Error('Input path should be absolute.')
34}
35
36let command = `npm run ts-node -- ${__dirname}/get-access-token.ts`
37command += ` -u "${program['url']}"`
38command += ` -n "${program['username']}"`
39command += ` -p "${program['password']}"`
40
41execCLI(command)
42 .then(stdout => {
43 const accessToken = stdout.replace('\n', '')
44
45 console.log(accessToken)
46
47 return readdirPromise(program['input']).then(files => ({ accessToken, files }))
48 })
49 .then(({ accessToken, files }) => {
50 return Promise.each(files, file => {
51 const video = {
52 tags: program['tags'],
53 name: file,
54 description: program['description'],
55 category: program['category'],
56 licence: program['licence']
57 }
58
59 let command = `npm run ts-node -- ${__dirname}/upload.ts`
60 command += ` -u "${program['url']}"`
61 command += ` -a "${accessToken}"`
62 command += ` -n "${video.name}"`
63 command += ` -d "${video.description}"`
64 command += ` -c "${video.category}"`
65 command += ` -l "${video.licence}"`
66 command += ` -t "${video.tags.join(',')}"`
67 command += ` -f "${join(program['input'], file)}"`
68
69 return execCLI(command).then(stdout => console.log(stdout))
70 })
71 })
72 .then(() => process.exit(0))
73 .catch(err => {
74 console.error(err)
75 process.exit(-1)
76 })
77
78// ----------------------------------------------------------------------------
79
80function list (val) {
81 return val.split(',')
82}
diff --git a/server/tests/real-world/tools/upload.ts b/server/tests/real-world/tools/upload.ts
deleted file mode 100644
index 81bc0d415..000000000
--- a/server/tests/real-world/tools/upload.ts
+++ /dev/null
@@ -1,85 +0,0 @@
1import * as program from 'commander'
2import { access, constants } from 'fs'
3import { isAbsolute } from 'path'
4import { promisify } from 'util'
5
6const accessPromise = promisify(access)
7
8import { uploadVideo } from '../../utils'
9
10program
11 .option('-u, --url <url>', 'Server url')
12 .option('-a, --access-token <token>', 'Access token')
13 .option('-n, --name <name>', 'Video name')
14 .option('-N, --nsfw', 'Video is Not Safe For Work')
15 .option('-c, --category <category number>', 'Category number')
16 .option('-l, --licence <licence number>', 'Licence number')
17 .option('-L, --language <language number>', 'Language number')
18 .option('-d, --description <description>', 'Video description')
19 .option('-t, --tags <tags>', 'Video tags', list)
20 .option('-f, --file <file>', 'Video absolute file path')
21 .parse(process.argv)
22
23if (!program['tags']) program['tags'] = []
24if (!program['nsfw']) program['nsfw'] = false
25
26if (
27 !program['url'] ||
28 !program['accessToken'] ||
29 !program['name'] ||
30 !program['category'] ||
31 !program['licence'] ||
32 !program['description'] ||
33 !program['file']
34) {
35 throw new Error('All arguments but tags, language and nsfw are required.')
36}
37
38if (isAbsolute(program['file']) === false) {
39 throw new Error('File path should be absolute.')
40}
41
42accessPromise(program['file'], constants.F_OK)
43 .then(() => {
44 return upload(
45 program['url'],
46 program['accessToken'],
47 program['name'],
48 program['category'],
49 program['licence'],
50 program['language'],
51 program['nsfw'],
52 program['description'],
53 program['tags'],
54 program['file']
55 )
56 })
57 .then(() => process.exit(0))
58 .catch(err => {
59 console.error(err)
60 process.exit(-1)
61 })
62
63// ----------------------------------------------------------------------------
64
65function list (val) {
66 return val.split(',')
67}
68
69function upload (url, accessToken, name, category, licence, language, nsfw, description, tags, fixture) {
70 console.log('Uploading %s video...', program['name'])
71
72 const videoAttributes = {
73 name,
74 category,
75 licence,
76 language,
77 nsfw,
78 description,
79 tags,
80 fixture
81 }
82 return uploadVideo(url, accessToken, videoAttributes).then(() => {
83 console.log(`Video ${name} uploaded.`)
84 })
85}