aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/upload-directory.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/upload-directory.ts')
-rw-r--r--server/tools/upload-directory.ts82
1 files changed, 82 insertions, 0 deletions
diff --git a/server/tools/upload-directory.ts b/server/tools/upload-directory.ts
new file mode 100644
index 000000000..c0094f852
--- /dev/null
+++ b/server/tools/upload-directory.ts
@@ -0,0 +1,82 @@
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 '../tests/utils/index'
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}