Fix optional privacy in upload endpoint
This commit is contained in:
parent
47f6409bb8
commit
2b4dd7e26d
|
@ -182,7 +182,7 @@ async function addVideo (req: express.Request, res: express.Response) {
|
||||||
nsfw: videoInfo.nsfw || false,
|
nsfw: videoInfo.nsfw || false,
|
||||||
description: videoInfo.description,
|
description: videoInfo.description,
|
||||||
support: videoInfo.support,
|
support: videoInfo.support,
|
||||||
privacy: videoInfo.privacy,
|
privacy: videoInfo.privacy || VideoPrivacy.PRIVATE,
|
||||||
duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
|
duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
|
||||||
channelId: res.locals.videoChannel.id,
|
channelId: res.locals.videoChannel.id,
|
||||||
originallyPublishedAt: videoInfo.originallyPublishedAt
|
originallyPublishedAt: videoInfo.originallyPublishedAt
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import 'express-validator'
|
import 'express-validator'
|
||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { UserNotificationSettingValue, UserRole } from '../../../shared'
|
import { UserRole } from '../../../shared'
|
||||||
import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants'
|
import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants'
|
||||||
import { exists, isFileValid, isBooleanValid } from './misc'
|
import { exists, isBooleanValid, isFileValid } from './misc'
|
||||||
import { values } from 'lodash'
|
import { values } from 'lodash'
|
||||||
import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
|
|
||||||
|
|
||||||
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
|
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
|
||||||
|
|
||||||
|
|
|
@ -3,51 +3,83 @@ const netrc = require('netrc-parser').default
|
||||||
|
|
||||||
const version = require('../../../package.json').version
|
const version = require('../../../package.json').version
|
||||||
|
|
||||||
let settings = {
|
|
||||||
remotes: [],
|
|
||||||
default: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Settings {
|
interface Settings {
|
||||||
remotes: any[],
|
remotes: any[],
|
||||||
default: number
|
default: number
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSettings () {
|
function getSettings () {
|
||||||
return new Promise<Settings>((res, rej) => {
|
return new Promise<Settings>((res, rej) => {
|
||||||
let settings = {
|
const defaultSettings = {
|
||||||
remotes: [],
|
remotes: [],
|
||||||
default: 0
|
default: 0
|
||||||
} as Settings
|
|
||||||
config.read((err, data) => {
|
|
||||||
if (err) {
|
|
||||||
return rej(err)
|
|
||||||
}
|
}
|
||||||
return res(Object.keys(data).length === 0 ? settings : data)
|
|
||||||
|
config.read((err, data) => {
|
||||||
|
if (err) return rej(err)
|
||||||
|
|
||||||
|
return res(Object.keys(data).length === 0 ? defaultSettings : data)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeSettings (settings) {
|
async function getNetrc () {
|
||||||
|
await netrc.load()
|
||||||
|
|
||||||
|
return netrc
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeSettings (settings) {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
config.write(settings, function (err) {
|
config.write(settings, function (err) {
|
||||||
if (err) {
|
if (err) return rej(err)
|
||||||
return rej(err)
|
|
||||||
}
|
|
||||||
return res()
|
return res()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
netrc.loadSync()
|
function getRemoteObjectOrDie (program: any, settings: Settings) {
|
||||||
|
if (!program['url'] || !program['username'] || !program['password']) {
|
||||||
|
// No remote and we don't have program parameters: throw
|
||||||
|
if (settings.remotes.length === 0) {
|
||||||
|
if (!program[ 'url' ]) console.error('--url field is required.')
|
||||||
|
if (!program[ 'username' ]) console.error('--username field is required.')
|
||||||
|
if (!program[ 'password' ]) console.error('--password field is required.')
|
||||||
|
|
||||||
|
return process.exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
let url: string = program['url']
|
||||||
|
let username: string = program['username']
|
||||||
|
let password: string = program['password']
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
url = settings.default !== -1
|
||||||
|
? settings.remotes[settings.default]
|
||||||
|
: settings.remotes[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!username) username = netrc.machines[url].login
|
||||||
|
if (!password) password = netrc.machines[url].password
|
||||||
|
|
||||||
|
return { url, username, password }
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
url: program[ 'url' ],
|
||||||
|
username: program[ 'username' ],
|
||||||
|
password: program[ 'password' ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
version,
|
version,
|
||||||
config,
|
config,
|
||||||
settings,
|
|
||||||
getSettings,
|
getSettings,
|
||||||
writeSettings,
|
getNetrc,
|
||||||
netrc
|
getRemoteObjectOrDie,
|
||||||
|
writeSettings
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
import * as program from 'commander'
|
import * as program from 'commander'
|
||||||
import * as prompt from 'prompt'
|
import * as prompt from 'prompt'
|
||||||
const Table = require('cli-table')
|
import { getSettings, writeSettings, getNetrc } from './cli'
|
||||||
import { getSettings, writeSettings, netrc } from './cli'
|
|
||||||
import { isHostValid } from '../helpers/custom-validators/servers'
|
import { isHostValid } from '../helpers/custom-validators/servers'
|
||||||
import { isUserUsernameValid } from '../helpers/custom-validators/users'
|
import { isUserUsernameValid } from '../helpers/custom-validators/users'
|
||||||
|
|
||||||
|
const Table = require('cli-table')
|
||||||
|
|
||||||
async function delInstance (url: string) {
|
async function delInstance (url: string) {
|
||||||
const settings = await getSettings()
|
const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
|
||||||
|
|
||||||
settings.remotes.splice(settings.remotes.indexOf(url))
|
settings.remotes.splice(settings.remotes.indexOf(url))
|
||||||
await writeSettings(settings)
|
await writeSettings(settings)
|
||||||
|
|
||||||
delete netrc.machines[url]
|
delete netrc.machines[url]
|
||||||
|
|
||||||
await netrc.save()
|
await netrc.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setInstance (url: string, username: string, password: string) {
|
async function setInstance (url: string, username: string, password: string) {
|
||||||
const settings = await getSettings()
|
const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
|
||||||
|
|
||||||
if (settings.remotes.indexOf(url) === -1) {
|
if (settings.remotes.indexOf(url) === -1) {
|
||||||
settings.remotes.push(url)
|
settings.remotes.push(url)
|
||||||
}
|
}
|
||||||
|
@ -82,12 +85,13 @@ program
|
||||||
.command('list')
|
.command('list')
|
||||||
.description('lists registered remote instances')
|
.description('lists registered remote instances')
|
||||||
.action(async () => {
|
.action(async () => {
|
||||||
const settings = await getSettings()
|
const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ])
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
head: ['instance', 'login'],
|
head: ['instance', 'login'],
|
||||||
colWidths: [30, 30]
|
colWidths: [30, 30]
|
||||||
})
|
})
|
||||||
netrc.loadSync()
|
|
||||||
settings.remotes.forEach(element => {
|
settings.remotes.forEach(element => {
|
||||||
table.push([
|
table.push([
|
||||||
element,
|
element,
|
||||||
|
|
|
@ -12,7 +12,7 @@ import * as prompt from 'prompt'
|
||||||
import { remove } from 'fs-extra'
|
import { remove } from 'fs-extra'
|
||||||
import { sha256 } from '../helpers/core-utils'
|
import { sha256 } from '../helpers/core-utils'
|
||||||
import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl'
|
import { buildOriginallyPublishedAt, safeGetYoutubeDL } from '../helpers/youtube-dl'
|
||||||
import { getSettings, netrc } from './cli'
|
import { getNetrc, getRemoteObjectOrDie, getSettings } from './cli'
|
||||||
|
|
||||||
let accessToken: string
|
let accessToken: string
|
||||||
let client: { id: string, secret: string }
|
let client: { id: string, secret: string }
|
||||||
|
@ -32,43 +32,25 @@ program
|
||||||
.option('-v, --verbose', 'Verbose mode')
|
.option('-v, --verbose', 'Verbose mode')
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
getSettings()
|
Promise.all([ getSettings(), getNetrc() ])
|
||||||
.then(settings => {
|
.then(([ settings, netrc ]) => {
|
||||||
if ((!program['url'] || !program['username'] || !program['targetUrl']) && settings.remotes.length === 0) {
|
const { url, username, password } = getRemoteObjectOrDie(program, settings)
|
||||||
if (!program['url']) console.error('--url field is required.')
|
|
||||||
if (!program['username']) console.error('--username field is required.')
|
if (!program[ 'targetUrl' ]) {
|
||||||
if (!program['targetUrl']) console.error('--targetUrl field is required.')
|
console.error('--targetUrl field is required.')
|
||||||
|
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!program[ 'url' ] || !program[ 'username' ]) && settings.remotes.length > 0) {
|
removeEndSlashes(url)
|
||||||
if (!program[ 'url' ]) {
|
|
||||||
program[ 'url' ] = settings.default !== -1
|
|
||||||
? settings.remotes[ settings.default ]
|
|
||||||
: settings.remotes[ 0 ]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!program['username']) program['username'] = netrc.machines[program['url']].login
|
|
||||||
if (!program['password']) program['password'] = netrc.machines[program['url']].password
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!program['targetUrl']
|
|
||||||
) {
|
|
||||||
if (!program['targetUrl']) console.error('--targetUrl field is required.')
|
|
||||||
process.exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
removeEndSlashes(program['url'])
|
|
||||||
removeEndSlashes(program[ 'targetUrl' ])
|
removeEndSlashes(program[ 'targetUrl' ])
|
||||||
|
|
||||||
const user = {
|
const user = {
|
||||||
username: program['username'],
|
username: username,
|
||||||
password: program['password']
|
password: password
|
||||||
}
|
}
|
||||||
|
|
||||||
run(user, program['url'])
|
run(user, url)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { isAbsolute } from 'path'
|
||||||
import { getClient, login } from '../../shared/extra-utils'
|
import { getClient, login } from '../../shared/extra-utils'
|
||||||
import { uploadVideo } from '../../shared/extra-utils/'
|
import { uploadVideo } from '../../shared/extra-utils/'
|
||||||
import { VideoPrivacy } from '../../shared/models/videos'
|
import { VideoPrivacy } from '../../shared/models/videos'
|
||||||
import { netrc, getSettings } from './cli'
|
import { getRemoteObjectOrDie, getSettings } from './cli'
|
||||||
|
|
||||||
program
|
program
|
||||||
.name('upload')
|
.name('upload')
|
||||||
|
@ -26,49 +26,15 @@ program
|
||||||
.option('-f, --file <file>', 'Video absolute file path')
|
.option('-f, --file <file>', 'Video absolute file path')
|
||||||
.parse(process.argv)
|
.parse(process.argv)
|
||||||
|
|
||||||
if (!program['tags']) program['tags'] = []
|
|
||||||
if (!program['nsfw']) program['nsfw'] = false
|
|
||||||
if (!program['privacy']) program['privacy'] = VideoPrivacy.PUBLIC
|
|
||||||
if (!program['commentsEnabled']) program['commentsEnabled'] = false
|
|
||||||
if (!program['downloadEnabled']) program['downloadEnabled'] = true
|
|
||||||
|
|
||||||
getSettings()
|
getSettings()
|
||||||
.then(settings => {
|
.then(settings => {
|
||||||
if (
|
const { url, username, password } = getRemoteObjectOrDie(program, settings)
|
||||||
(!program['url'] ||
|
|
||||||
!program['username'] ||
|
|
||||||
!program['password']) &&
|
|
||||||
(settings.remotes.length === 0)
|
|
||||||
) {
|
|
||||||
if (!program['url']) console.error('--url field is required.')
|
|
||||||
if (!program['username']) console.error('--username field is required.')
|
|
||||||
if (!program['password']) console.error('--password field is required.')
|
|
||||||
if (!program['videoName']) console.error('--video-name field is required.')
|
|
||||||
if (!program['file']) console.error('--file field is required.')
|
|
||||||
process.exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (!program['videoName'] || !program['file'] || !program['channelId']) {
|
||||||
(!program['url'] ||
|
if (!program['videoName']) console.error('--video-name is required.')
|
||||||
!program['username'] ||
|
if (!program['file']) console.error('--file is required.')
|
||||||
!program['password']) &&
|
if (!program['channelId']) console.error('--channel-id is required.')
|
||||||
(settings.remotes.length > 0)
|
|
||||||
) {
|
|
||||||
if (!program['url']) {
|
|
||||||
program['url'] = (settings.default !== -1) ?
|
|
||||||
settings.remotes[settings.default] :
|
|
||||||
settings.remotes[0]
|
|
||||||
}
|
|
||||||
if (!program['username']) program['username'] = netrc.machines[program['url']].login
|
|
||||||
if (!program['password']) program['password'] = netrc.machines[program['url']].password
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!program['videoName'] ||
|
|
||||||
!program['file']
|
|
||||||
) {
|
|
||||||
if (!program['videoName']) console.error('--video-name field is required.')
|
|
||||||
if (!program['file']) console.error('--file field is required.')
|
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,28 +43,25 @@ getSettings()
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(err => {
|
run(url, username, password).catch(err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
async function run () {
|
async function run (url: string, username: string, password: string) {
|
||||||
const res = await getClient(program[ 'url' ])
|
const resClient = await getClient(program[ 'url' ])
|
||||||
const client = {
|
const client = {
|
||||||
id: res.body.client_id,
|
id: resClient.body.client_id,
|
||||||
secret: res.body.client_secret
|
secret: resClient.body.client_secret
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = {
|
const user = { username, password }
|
||||||
username: program[ 'username' ],
|
|
||||||
password: program[ 'password' ]
|
|
||||||
}
|
|
||||||
|
|
||||||
let accessToken: string
|
let accessToken: string
|
||||||
try {
|
try {
|
||||||
const res2 = await login(program[ 'url' ], client, user)
|
const res = await login(url, client, user)
|
||||||
accessToken = res2.body.access_token
|
accessToken = res.body.access_token
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error('Cannot authenticate. Please check your username/password.')
|
throw new Error('Cannot authenticate. Please check your username/password.')
|
||||||
}
|
}
|
||||||
|
@ -109,27 +72,32 @@ async function run () {
|
||||||
|
|
||||||
const videoAttributes = {
|
const videoAttributes = {
|
||||||
name: program['videoName'],
|
name: program['videoName'],
|
||||||
category: program['category'],
|
category: program['category'] || undefined,
|
||||||
channelId: program['channelId'],
|
channelId: program['channelId'],
|
||||||
licence: program['licence'],
|
licence: program['licence'] || undefined,
|
||||||
language: program['language'],
|
language: program['language'] || undefined,
|
||||||
nsfw: program['nsfw'],
|
nsfw: program['nsfw'] !== undefined ? program['nsfw'] : false,
|
||||||
description: program['videoDescription'],
|
description: program['videoDescription'] || '',
|
||||||
tags: program['tags'],
|
tags: program['tags'] || [],
|
||||||
commentsEnabled: program['commentsEnabled'],
|
commentsEnabled: program['commentsEnabled'] !== undefined ? program['commentsEnabled'] : true,
|
||||||
downloadEnabled: program['downloadEnabled'],
|
downloadEnabled: program['downloadEnabled'] !== undefined ? program['downloadEnabled'] : true,
|
||||||
fixture: program['file'],
|
fixture: program['file'],
|
||||||
thumbnailfile: program['thumbnail'],
|
thumbnailfile: program['thumbnail'],
|
||||||
previewfile: program['preview'],
|
previewfile: program['preview'],
|
||||||
waitTranscoding: true,
|
waitTranscoding: true,
|
||||||
privacy: program['privacy'],
|
privacy: program['privacy'] || VideoPrivacy.PUBLIC,
|
||||||
support: undefined
|
support: undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
await uploadVideo(program[ 'url' ], accessToken, videoAttributes)
|
try {
|
||||||
|
await uploadVideo(url, accessToken, videoAttributes)
|
||||||
console.log(`Video ${program['videoName']} uploaded.`)
|
console.log(`Video ${program['videoName']} uploaded.`)
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
|
} catch (err) {
|
||||||
|
console.log('coucou')
|
||||||
|
console.error(require('util').inspect(err))
|
||||||
|
process.exit(-1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue