]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tools/peertube-upload.ts
Translated using Weblate (Hungarian)
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-upload.ts
1 import { registerTSPaths } from '../helpers/register-ts-paths'
2 registerTSPaths()
3
4 import * as program from 'commander'
5 import { access, constants } from 'fs-extra'
6 import { isAbsolute } from 'path'
7 import { getAccessToken } from '../../shared/extra-utils'
8 import { uploadVideo } from '../../shared/extra-utils/'
9 import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
10
11 let command = program
12 .name('upload')
13
14 command = buildCommonVideoOptions(command)
15
16 command
17 .option('-u, --url <url>', 'Server url')
18 .option('-U, --username <username>', 'Username')
19 .option('-p, --password <token>', 'Password')
20 .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
21 .option('-v, --preview <previewPath>', 'Preview path')
22 .option('-f, --file <file>', 'Video absolute file path')
23 .parse(process.argv)
24
25 getServerCredentials(command)
26 .then(({ url, username, password }) => {
27 if (!program['videoName'] || !program['file']) {
28 if (!program['videoName']) console.error('--video-name is required.')
29 if (!program['file']) console.error('--file is required.')
30
31 process.exit(-1)
32 }
33
34 if (isAbsolute(program['file']) === false) {
35 console.error('File path should be absolute.')
36 process.exit(-1)
37 }
38
39 run(url, username, password).catch(err => {
40 console.error(err)
41 process.exit(-1)
42 })
43 })
44 .catch(err => console.error(err))
45
46 async function run (url: string, username: string, password: string) {
47 const accessToken = await getAccessToken(url, username, password)
48
49 await access(program['file'], constants.F_OK)
50
51 console.log('Uploading %s video...', program['videoName'])
52
53 const videoAttributes = await buildVideoAttributesFromCommander(url, program)
54
55 Object.assign(videoAttributes, {
56 fixture: program['file'],
57 thumbnailfile: program['thumbnail'],
58 previewfile: program['preview']
59 })
60
61 try {
62 await uploadVideo(url, accessToken, videoAttributes)
63 console.log(`Video ${program['videoName']} uploaded.`)
64 process.exit(0)
65 } catch (err) {
66 console.error(require('util').inspect(err))
67 process.exit(-1)
68 }
69 }
70
71 // ----------------------------------------------------------------------------