aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-upload.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-25 13:55:28 +0200
committerChocobozzz <me@florianbigard.com>2019-04-25 13:55:28 +0200
commit2b4dd7e26d93c2d9bef4f365cb03c511eff4ca8f (patch)
tree5fe2982e0db8c1ccb661d5aa9c25b02c12590401 /server/tools/peertube-upload.ts
parent47f6409bb8bc49a50027b9579bb651c0506b6912 (diff)
downloadPeerTube-2b4dd7e26d93c2d9bef4f365cb03c511eff4ca8f.tar.gz
PeerTube-2b4dd7e26d93c2d9bef4f365cb03c511eff4ca8f.tar.zst
PeerTube-2b4dd7e26d93c2d9bef4f365cb03c511eff4ca8f.zip
Fix optional privacy in upload endpoint
Diffstat (limited to 'server/tools/peertube-upload.ts')
-rw-r--r--server/tools/peertube-upload.ts96
1 files changed, 32 insertions, 64 deletions
diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts
index 13ca94e51..687f2e60b 100644
--- a/server/tools/peertube-upload.ts
+++ b/server/tools/peertube-upload.ts
@@ -4,7 +4,7 @@ import { isAbsolute } from 'path'
4import { getClient, login } from '../../shared/extra-utils' 4import { getClient, login } from '../../shared/extra-utils'
5import { uploadVideo } from '../../shared/extra-utils/' 5import { uploadVideo } from '../../shared/extra-utils/'
6import { VideoPrivacy } from '../../shared/models/videos' 6import { VideoPrivacy } from '../../shared/models/videos'
7import { netrc, getSettings } from './cli' 7import { getRemoteObjectOrDie, getSettings } from './cli'
8 8
9program 9program
10 .name('upload') 10 .name('upload')
@@ -26,49 +26,15 @@ program
26 .option('-f, --file <file>', 'Video absolute file path') 26 .option('-f, --file <file>', 'Video absolute file path')
27 .parse(process.argv) 27 .parse(process.argv)
28 28
29if (!program['tags']) program['tags'] = []
30if (!program['nsfw']) program['nsfw'] = false
31if (!program['privacy']) program['privacy'] = VideoPrivacy.PUBLIC
32if (!program['commentsEnabled']) program['commentsEnabled'] = false
33if (!program['downloadEnabled']) program['downloadEnabled'] = true
34
35getSettings() 29getSettings()
36 .then(settings => { 30 .then(settings => {
37 if ( 31 const { url, username, password } = getRemoteObjectOrDie(program, settings)
38 (!program['url'] ||
39 !program['username'] ||
40 !program['password']) &&
41 (settings.remotes.length === 0)
42 ) {
43 if (!program['url']) console.error('--url field is required.')
44 if (!program['username']) console.error('--username field is required.')
45 if (!program['password']) console.error('--password field is required.')
46 if (!program['videoName']) console.error('--video-name field is required.')
47 if (!program['file']) console.error('--file field is required.')
48 process.exit(-1)
49 }
50 32
51 if ( 33 if (!program['videoName'] || !program['file'] || !program['channelId']) {
52 (!program['url'] || 34 if (!program['videoName']) console.error('--video-name is required.')
53 !program['username'] || 35 if (!program['file']) console.error('--file is required.')
54 !program['password']) && 36 if (!program['channelId']) console.error('--channel-id is required.')
55 (settings.remotes.length > 0)
56 ) {
57 if (!program['url']) {
58 program['url'] = (settings.default !== -1) ?
59 settings.remotes[settings.default] :
60 settings.remotes[0]
61 }
62 if (!program['username']) program['username'] = netrc.machines[program['url']].login
63 if (!program['password']) program['password'] = netrc.machines[program['url']].password
64 }
65 37
66 if (
67 !program['videoName'] ||
68 !program['file']
69 ) {
70 if (!program['videoName']) console.error('--video-name field is required.')
71 if (!program['file']) console.error('--file field is required.')
72 process.exit(-1) 38 process.exit(-1)
73 } 39 }
74 40
@@ -77,28 +43,25 @@ getSettings()
77 process.exit(-1) 43 process.exit(-1)
78 } 44 }
79 45
80 run().catch(err => { 46 run(url, username, password).catch(err => {
81 console.error(err) 47 console.error(err)
82 process.exit(-1) 48 process.exit(-1)
83 }) 49 })
84 }) 50 })
85 51
86async function run () { 52async function run (url: string, username: string, password: string) {
87 const res = await getClient(program[ 'url' ]) 53 const resClient = await getClient(program[ 'url' ])
88 const client = { 54 const client = {
89 id: res.body.client_id, 55 id: resClient.body.client_id,
90 secret: res.body.client_secret 56 secret: resClient.body.client_secret
91 } 57 }
92 58
93 const user = { 59 const user = { username, password }
94 username: program[ 'username' ],
95 password: program[ 'password' ]
96 }
97 60
98 let accessToken: string 61 let accessToken: string
99 try { 62 try {
100 const res2 = await login(program[ 'url' ], client, user) 63 const res = await login(url, client, user)
101 accessToken = res2.body.access_token 64 accessToken = res.body.access_token
102 } catch (err) { 65 } catch (err) {
103 throw new Error('Cannot authenticate. Please check your username/password.') 66 throw new Error('Cannot authenticate. Please check your username/password.')
104 } 67 }
@@ -109,27 +72,32 @@ async function run () {
109 72
110 const videoAttributes = { 73 const videoAttributes = {
111 name: program['videoName'], 74 name: program['videoName'],
112 category: program['category'], 75 category: program['category'] || undefined,
113 channelId: program['channelId'], 76 channelId: program['channelId'],
114 licence: program['licence'], 77 licence: program['licence'] || undefined,
115 language: program['language'], 78 language: program['language'] || undefined,
116 nsfw: program['nsfw'], 79 nsfw: program['nsfw'] !== undefined ? program['nsfw'] : false,
117 description: program['videoDescription'], 80 description: program['videoDescription'] || '',
118 tags: program['tags'], 81 tags: program['tags'] || [],
119 commentsEnabled: program['commentsEnabled'], 82 commentsEnabled: program['commentsEnabled'] !== undefined ? program['commentsEnabled'] : true,
120 downloadEnabled: program['downloadEnabled'], 83 downloadEnabled: program['downloadEnabled'] !== undefined ? program['downloadEnabled'] : true,
121 fixture: program['file'], 84 fixture: program['file'],
122 thumbnailfile: program['thumbnail'], 85 thumbnailfile: program['thumbnail'],
123 previewfile: program['preview'], 86 previewfile: program['preview'],
124 waitTranscoding: true, 87 waitTranscoding: true,
125 privacy: program['privacy'], 88 privacy: program['privacy'] || VideoPrivacy.PUBLIC,
126 support: undefined 89 support: undefined
127 } 90 }
128 91
129 await uploadVideo(program[ 'url' ], accessToken, videoAttributes) 92 try {
130 93 await uploadVideo(url, accessToken, videoAttributes)
131 console.log(`Video ${program['videoName']} uploaded.`) 94 console.log(`Video ${program['videoName']} uploaded.`)
132 process.exit(0) 95 process.exit(0)
96 } catch (err) {
97 console.log('coucou')
98 console.error(require('util').inspect(err))
99 process.exit(-1)
100 }
133} 101}
134 102
135// ---------------------------------------------------------------------------- 103// ----------------------------------------------------------------------------