2018-09-13 08:27:44 -04:00
|
|
|
const config = require('application-config')('PeerTube/CLI')
|
|
|
|
const netrc = require('netrc-parser').default
|
|
|
|
|
2018-10-03 08:35:35 -04:00
|
|
|
const version = require('../../../package.json').version
|
2018-09-13 08:27:44 -04:00
|
|
|
|
|
|
|
let settings = {
|
|
|
|
remotes: [],
|
|
|
|
default: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Settings {
|
|
|
|
remotes: any[],
|
|
|
|
default: number
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getSettings () {
|
|
|
|
return new Promise<Settings>((res, rej) => {
|
|
|
|
let settings = {
|
|
|
|
remotes: [],
|
|
|
|
default: 0
|
|
|
|
} as Settings
|
|
|
|
config.read((err, data) => {
|
|
|
|
if (err) {
|
|
|
|
return rej(err)
|
|
|
|
}
|
2018-10-24 06:28:25 -04:00
|
|
|
return res(Object.keys(data).length === 0 ? settings : data)
|
2018-09-13 08:27:44 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function writeSettings (settings) {
|
|
|
|
return new Promise((res, rej) => {
|
|
|
|
config.write(settings, function (err) {
|
|
|
|
if (err) {
|
|
|
|
return rej(err)
|
|
|
|
}
|
|
|
|
return res()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
netrc.loadSync()
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
version,
|
|
|
|
config,
|
|
|
|
settings,
|
|
|
|
getSettings,
|
|
|
|
writeSettings,
|
|
|
|
netrc
|
|
|
|
}
|