mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Fix optional privacy in upload endpoint
This commit is contained in:
parent
47f6409bb8
commit
2b4dd7e26d
6 changed files with 130 additions and 145 deletions
|
@ -3,51 +3,83 @@ const netrc = require('netrc-parser').default
|
|||
|
||||
const version = require('../../../package.json').version
|
||||
|
||||
let settings = {
|
||||
remotes: [],
|
||||
default: 0
|
||||
}
|
||||
|
||||
interface Settings {
|
||||
remotes: any[],
|
||||
default: number
|
||||
}
|
||||
|
||||
async function getSettings () {
|
||||
function getSettings () {
|
||||
return new Promise<Settings>((res, rej) => {
|
||||
let settings = {
|
||||
const defaultSettings = {
|
||||
remotes: [],
|
||||
default: 0
|
||||
} as Settings
|
||||
}
|
||||
|
||||
config.read((err, data) => {
|
||||
if (err) {
|
||||
return rej(err)
|
||||
}
|
||||
return res(Object.keys(data).length === 0 ? settings : 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) => {
|
||||
config.write(settings, function (err) {
|
||||
if (err) {
|
||||
return rej(err)
|
||||
}
|
||||
if (err) return rej(err)
|
||||
|
||||
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 {
|
||||
version,
|
||||
config,
|
||||
settings,
|
||||
getSettings,
|
||||
writeSettings,
|
||||
netrc
|
||||
getNetrc,
|
||||
getRemoteObjectOrDie,
|
||||
writeSettings
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue