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