You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1019 B
31 lines
1019 B
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()
|