]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tools/peertube-upload.ts
Force video updatedAt update on update
[github/Chocobozzz/PeerTube.git] / server / tools / peertube-upload.ts
CommitLineData
2aaa1a3f
C
1import { registerTSPaths } from '../helpers/register-ts-paths'
2registerTSPaths()
3
12152aa0 4import { program } from 'commander'
c9d5c64f 5import { access, constants } from 'fs-extra'
8df87ce7 6import { isAbsolute } from 'path'
d0a0fa42 7import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli'
8df87ce7 8
1205823f 9let command = program
8704acf4 10 .name('upload')
1205823f
C
11
12command = buildCommonVideoOptions(command)
13
14command
8df87ce7 15 .option('-u, --url <url>', 'Server url')
a87d467a
C
16 .option('-U, --username <username>', 'Username')
17 .option('-p, --password <token>', 'Password')
2422c46b 18 .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
02988fdc 19 .option('-v, --preview <previewPath>', 'Preview path')
8df87ce7
C
20 .option('-f, --file <file>', 'Video absolute file path')
21 .parse(process.argv)
22
ba5a8d89
C
23const options = command.opts()
24
8d2be0ed
C
25getServerCredentials(command)
26 .then(({ url, username, password }) => {
ba5a8d89
C
27 if (!options.videoName || !options.file) {
28 if (!options.videoName) console.error('--video-name is required.')
29 if (!options.file) console.error('--file is required.')
8704acf4 30
8d2be0ed
C
31 process.exit(-1)
32 }
8704acf4 33
ba5a8d89 34 if (isAbsolute(options.file) === false) {
8d2be0ed
C
35 console.error('File path should be absolute.')
36 process.exit(-1)
37 }
8704acf4 38
8d2be0ed
C
39 run(url, username, password).catch(err => {
40 console.error(err)
41 process.exit(-1)
42 })
43 })
a1587156 44 .catch(err => console.error(err))
8df87ce7 45
2b4dd7e2 46async function run (url: string, username: string, password: string) {
d0a0fa42
C
47 const server = buildServer(url)
48 await assignToken(server, username, password)
8df87ce7 49
ba5a8d89 50 await access(options.file, constants.F_OK)
a87d467a 51
ba5a8d89 52 console.log('Uploading %s video...', options.videoName)
8df87ce7 53
d23dd9fb
C
54 const baseAttributes = await buildVideoAttributesFromCommander(server, program)
55
56 const attributes = {
57 ...baseAttributes,
1205823f 58
ba5a8d89
C
59 fixture: options.file,
60 thumbnailfile: options.thumbnail,
61 previewfile: options.preview
d23dd9fb 62 }
a87d467a 63
2b4dd7e2 64 try {
89d241a7 65 await server.videos.upload({ attributes })
ba5a8d89 66 console.log(`Video ${options.videoName} uploaded.`)
2b4dd7e2
C
67 process.exit(0)
68 } catch (err) {
2b4dd7e2
C
69 console.error(require('util').inspect(err))
70 process.exit(-1)
71 }
a87d467a
C
72}
73
74// ----------------------------------------------------------------------------