parent
120dbe0b0a
commit
722db76086
@ -0,0 +1,30 @@
|
|||||||
|
const fs = require('fs')
|
||||||
|
const home_dir = require('os').homedir()
|
||||||
|
const path = require('path')
|
||||||
|
|
||||||
|
const exists = async file => {
|
||||||
|
return new Promise(res => {
|
||||||
|
fs.promises.stat(file).then(() => res(true)).catch(() => res(false))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConfigManager {
|
||||||
|
config_path = path.resolve(home_dir, '.config', 'pied-vcs.json')
|
||||||
|
|
||||||
|
async initialize() {
|
||||||
|
if ( !(await exists(this.config_path)) ) {
|
||||||
|
console.error('Pied VCS configuration file does not exist!')
|
||||||
|
console.log(`Please create the file "${this.config_path}" with your authentication token and server information.`)
|
||||||
|
throw new Error('Missing pied-vcs.json file.')
|
||||||
|
}
|
||||||
|
|
||||||
|
this.config = require(this.config_path)
|
||||||
|
|
||||||
|
const required_fields = ['token', 'mountpoint', 'data_server', 'stream_server']
|
||||||
|
if ( !this.config || !required_fields.every(field => this.config[field]) ) {
|
||||||
|
throw new Error('Invalid config.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = new ConfigManager()
|
Loading…
Reference in new issue