X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fpeertube-upload.ts;h=114fe8a290da599583d91fdb760b1e32d378a7b8;hb=c5b28f63367ac373bfa38d4b21791a0a5f1d78c1;hp=02edbd809296e3ec7d4d875e3957b573af22eefc;hpb=cf21b2cbef61929177b9c09b5e017c3b7eb8535d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/peertube-upload.ts b/server/tools/peertube-upload.ts index 02edbd809..114fe8a29 100644 --- a/server/tools/peertube-upload.ts +++ b/server/tools/peertube-upload.ts @@ -1,12 +1,7 @@ -import { registerTSPaths } from '../helpers/register-ts-paths' -registerTSPaths() - import { program } from 'commander' import { access, constants } from 'fs-extra' import { isAbsolute } from 'path' -import { getAccessToken } from '../../shared/extra-utils' -import { uploadVideo } from '../../shared/extra-utils/' -import { buildCommonVideoOptions, buildVideoAttributesFromCommander, getServerCredentials } from './cli' +import { assignToken, buildCommonVideoOptions, buildServer, buildVideoAttributesFromCommander, getServerCredentials } from './cli' let command = program .name('upload') @@ -46,26 +41,35 @@ getServerCredentials(command) .catch(err => console.error(err)) async function run (url: string, username: string, password: string) { - const accessToken = await getAccessToken(url, username, password) + const server = buildServer(url) + await assignToken(server, username, password) await access(options.file, constants.F_OK) console.log('Uploading %s video...', options.videoName) - const videoAttributes = await buildVideoAttributesFromCommander(url, program) + const baseAttributes = await buildVideoAttributesFromCommander(server, program) + + const attributes = { + ...baseAttributes, - Object.assign(videoAttributes, { fixture: options.file, thumbnailfile: options.thumbnail, previewfile: options.preview - }) + } try { - await uploadVideo(url, accessToken, videoAttributes) + await server.videos.upload({ attributes }) console.log(`Video ${options.videoName} uploaded.`) process.exit(0) } catch (err) { - console.error(require('util').inspect(err)) + const message = err.message || '' + if (message.includes('413')) { + console.error('Aborted: user quota is exceeded or video file is too big for this PeerTube instance.') + } else { + console.error(require('util').inspect(err)) + } + process.exit(-1) } }