aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-import-videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/peertube-import-videos.ts')
-rw-r--r--server/tools/peertube-import-videos.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts
index a546a8dbe..0a4d6fa6e 100644
--- a/server/tools/peertube-import-videos.ts
+++ b/server/tools/peertube-import-videos.ts
@@ -14,10 +14,10 @@ import { sha256 } from '../helpers/core-utils'
14import { doRequestAndSaveToFile } from '../helpers/requests' 14import { doRequestAndSaveToFile } from '../helpers/requests'
15import { CONSTRAINTS_FIELDS } from '../initializers/constants' 15import { CONSTRAINTS_FIELDS } from '../initializers/constants'
16import { 16import {
17 assignToken,
17 buildCommonVideoOptions, 18 buildCommonVideoOptions,
18 buildServer, 19 buildServer,
19 buildVideoAttributesFromCommander, 20 buildVideoAttributesFromCommander,
20 getAccessTokenOrDie,
21 getLogger, 21 getLogger,
22 getServerCredentials 22 getServerCredentials
23} from './cli' 23} from './cli'
@@ -232,8 +232,8 @@ async function uploadVideoOnPeerTube (parameters: {
232 tags 232 tags
233 } 233 }
234 234
235 let accessToken = await getAccessTokenOrDie(url, username, password) 235 const server = buildServer(url)
236 const server = buildServer(url, accessToken) 236 await assignToken(server, username, password)
237 237
238 const videoAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes) 238 const videoAttributes = await buildVideoAttributesFromCommander(server, program, defaultAttributes)
239 239
@@ -247,14 +247,14 @@ async function uploadVideoOnPeerTube (parameters: {
247 log.info('\nUploading on PeerTube video "%s".', videoAttributes.name) 247 log.info('\nUploading on PeerTube video "%s".', videoAttributes.name)
248 248
249 try { 249 try {
250 await uploadVideo(url, accessToken, videoAttributes) 250 await uploadVideo(url, server.accessToken, videoAttributes)
251 } catch (err) { 251 } catch (err) {
252 if (err.message.indexOf('401') !== -1) { 252 if (err.message.indexOf('401') !== -1) {
253 log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.') 253 log.info('Got 401 Unauthorized, token may have expired, renewing token and retry.')
254 254
255 accessToken = await getAccessTokenOrDie(url, username, password) 255 server.accessToken = await server.loginCommand.getAccessToken(username, password)
256 256
257 await uploadVideo(url, accessToken, videoAttributes) 257 await uploadVideo(url, server.accessToken, videoAttributes)
258 } else { 258 } else {
259 exitError(err.message) 259 exitError(err.message)
260 } 260 }