X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftools%2Fcli.ts;h=58e2445ac47f0c40e9f1e4f2cafa1ff8c860ca26;hb=c3700e0ff9e174e7bad7e72d1d5a4e2e02627ef9;hp=4aa3d9ce84fec0ff02f223d58bca3f9be14bc3dc;hpb=1205823fece15f249e0dbad42e096cf9b81c3ba5;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 4aa3d9ce8..58e2445ac 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts @@ -1,9 +1,11 @@ import { Netrc } from 'netrc-parser' import { getAppNumber, isTestInstance } from '../helpers/core-utils' import { join } from 'path' -import { getVideoChannel, root } from '../../shared/extra-utils' +import { root } from '../../shared/extra-utils/miscs/miscs' +import { getVideoChannel } from '../../shared/extra-utils/videos/video-channels' import { Command } from 'commander' import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' +import { createLogger, format, transports } from 'winston' let configName = 'PeerTube/CLI' if (isTestInstance()) configName += `-${getAppNumber()}` @@ -64,7 +66,11 @@ function deleteSettings () { }) } -function getRemoteObjectOrDie (program: any, settings: Settings, netrc: Netrc) { +function getRemoteObjectOrDie ( + program: any, + settings: Settings, + netrc: Netrc +): { url: string, username: string, password: string } { if (!program['url'] || !program['username'] || !program['password']) { // No remote and we don't have program parameters: quit if (settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) { @@ -114,18 +120,26 @@ function buildCommonVideoOptions (command: Command) { .option('-m, --comments-enabled', 'Enable comments') .option('-s, --support ', 'Video support text') .option('-w, --wait-transcoding', 'Wait transcoding before publishing the video') + .option('-v, --verbose ', 'Verbosity, from 0/\'error\' to 4/\'debug\'', 'info') } -async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any) { - const booleanAttributes: { [id: string]: boolean } = {} +async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any = {}) { + const defaultBooleanAttributes = { + nsfw: false, + commentsEnabled: true, + downloadEnabled: true, + waitTranscoding: true + } + + const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } | {} = {} - for (const key of [ 'nsfw', 'commentsEnabled', 'downloadEnabled', 'waitTranscoding' ]) { + for (const key of Object.keys(defaultBooleanAttributes)) { if (command[ key ] !== undefined) { booleanAttributes[key] = command[ key ] } else if (defaultAttributes[key] !== undefined) { booleanAttributes[key] = defaultAttributes[key] } else { - booleanAttributes[key] = false + booleanAttributes[key] = defaultBooleanAttributes[key] } } @@ -135,7 +149,9 @@ async function buildVideoAttributesFromCommander (url: string, command: Command, licence: command[ 'licence' ] || defaultAttributes.licence || undefined, language: command[ 'language' ] || defaultAttributes.language || undefined, privacy: command[ 'privacy' ] || defaultAttributes.privacy || VideoPrivacy.PUBLIC, - support: command[ 'support' ] || defaultAttributes.support || undefined + support: command[ 'support' ] || defaultAttributes.support || undefined, + description: command[ 'videoDescription' ] || defaultAttributes.description || undefined, + tags: command[ 'tags' ] || defaultAttributes.tags || undefined } Object.assign(videoAttributes, booleanAttributes) @@ -154,17 +170,57 @@ async function buildVideoAttributesFromCommander (url: string, command: Command, return videoAttributes } +function getServerCredentials (program: any) { + return Promise.all([ getSettings(), getNetrc() ]) + .then(([ settings, netrc ]) => { + return getRemoteObjectOrDie(program, settings, netrc) + }) +} + +function getLogger (logLevel = 'info') { + const logLevels = { + 0: 0, + error: 0, + 1: 1, + warn: 1, + 2: 2, + info: 2, + 3: 3, + verbose: 3, + 4: 4, + debug: 4 + } + + const logger = createLogger({ + levels: logLevels, + format: format.combine( + format.splat(), + format.simple() + ), + transports: [ + new (transports.Console)({ + level: logLevel + }) + ] + }) + + return logger +} + // --------------------------------------------------------------------------- export { version, config, + getLogger, getSettings, getNetrc, getRemoteObjectOrDie, writeSettings, deleteSettings, + getServerCredentials, + buildCommonVideoOptions, buildVideoAttributesFromCommander }