Modify client to support config file

master
Garrett Mills 3 years ago
parent 120dbe0b0a
commit 722db76086
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -1,6 +1,7 @@
const WebSocketStream = require('websocket-stream')
const CombinedStream = require('combined-stream')
const { Buffer } = require('buffer')
const config = require('./config')
class Streamer {
constructor(socket_uuid, node_uuid, length = 4096, position = 0, descriptor = undefined) {
@ -12,7 +13,7 @@ class Streamer {
}
write(buffer) {
const write_stream = WebSocketStream(`ws://localhost:5746/?socket_uuid=${this.socket_uuid}&node_uuid=${this.node_uuid}&length=${this.length}&position=${this.position}&writing_file=true&descriptor=${this.descriptor}`, {
const write_stream = WebSocketStream(`ws://${config.config.data_server}/?socket_uuid=${this.socket_uuid}&node_uuid=${this.node_uuid}&length=${this.length}&position=${this.position}&writing_file=true&descriptor=${this.descriptor}`, {
perMessageDeflate: false,
binary: true,
})
@ -29,7 +30,7 @@ class Streamer {
}
stream() {
this.ws = WebSocketStream(`ws://localhost:5746/?socket_uuid=${this.socket_uuid}&node_uuid=${this.node_uuid}&length=${this.length}&position=${this.position}`, {
this.ws = WebSocketStream(`ws://${config.config.data_server}/?socket_uuid=${this.socket_uuid}&node_uuid=${this.node_uuid}&length=${this.length}&position=${this.position}`, {
perMessageDeflate: false,
binary: true,
})

@ -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()

@ -1,10 +1,11 @@
const Message = require('../shared/Message')
const WebSocket = require('ws')
const Errors = require('../shared/Errors')
const config = require('./config')
class Connector {
constructor() {
this.client = new WebSocket('ws://localhost:8100')
initialize() {
this.client = new WebSocket(`ws://${config.config.data_server}`)
this.messages = []
this.token;

@ -1,9 +1,7 @@
const uuid = require('uuid').v4
const Fuse = require('fuse-native')
const fs = require('fs').promises
const fs = require('fs')
const conn = require('./connector')
const token = '0257387b959a4cbfa7b3a36fea7d8cfb97e435e2d6454a96992470e5ba107d29b35bed8c21dc4272b4d8d6eebc9a0f5f17b707c37e57442db9ab56775f449128'
const config = require('./config')
const ops = {
readdir: require('./ops/readdir'),
@ -29,12 +27,13 @@ const ops = {
}
;(async () => {
await conn.open()
await conn.authenticate(token)
const mnt = '/tmp/piedev-' + uuid()
await config.initialize()
await fs.mkdir(mnt)
conn.initialize()
await conn.open()
await conn.authenticate(config.config.token)
const mnt = config.config.mountpoint
const fuse = new Fuse(mnt, ops, {debug: true, displayFolder: true})
await new Promise((res, rej) => {

Loading…
Cancel
Save