Skip to content

Commit

Permalink
refactor: remove machine-info for good
Browse files Browse the repository at this point in the history
  • Loading branch information
siiky committed Oct 17, 2024
1 parent 944ff10 commit 32650cc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 83 deletions.
25 changes: 0 additions & 25 deletions lib/machine-info.js

This file was deleted.

4 changes: 0 additions & 4 deletions lib/trader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const version = require('../package.json').version

const request = require('./request')
const logs = require('./logs')
const machineInfo = require('./machine-info')
const { gql, GraphQLClient } = require('./graphql-client')
const lssettings = require('./lssettings')

Expand Down Expand Up @@ -743,9 +742,6 @@ Trader.prototype.pollHandler = function pollHandler (data) {
{ active: false }

return Promise.resolve(true)
machineInfo.save(this.dataPath, data.machineInfo)
.catch(err => console.log('failure saving machine info', err))

}

const handleDynamicConfig = data => {
Expand Down
105 changes: 51 additions & 54 deletions lib/update/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ var util = require('util')
var path = require('path')
var _ = require('lodash/fp')

var machineInfoLoader = require('../machine-info')
var watchdogInfoLoader = require('../watchdog-info')
var log = console.log;
var error = console.error;
const lssettings = require('../lssettings')

console.log = function(){
var date = (new Date).toISOString()
Expand Down Expand Up @@ -163,66 +163,63 @@ Updater.prototype._httpsOptions = function _httpsOptions () {

function noop () {}

Updater.prototype.updateHeaders = function updateHeaders (options) {
var dataPath = path.resolve(__dirname, '..', '..', this.config.dataPath)
var machineInfo = machineInfoLoader.load(dataPath)
var watchdogInfo = watchdogInfoLoader.load(dataPath)
Updater.prototype.updateHeaders = function updateHeaders (headers) {
return lssettings.loadMachineInfo().catch(() => ({ active: false }))
.then(machineInfo => {
var dataPath = path.resolve(__dirname, '..', '..', this.config.dataPath)
var watchdogInfo = watchdogInfoLoader.load(dataPath)

var connectionInfoPath = path.resolve(dataPath, 'connection_info.json')
const connectionInfo = JSON.parse(fs.readFileSync(connectionInfoPath))
var connectionInfoPath = path.resolve(dataPath, 'connection_info.json')
const connectionInfo = JSON.parse(fs.readFileSync(connectionInfoPath))

if (connectionInfo.host) {
options = _.assign(options, {
'device-host': crypto.createHash('sha256').update(connectionInfo.host).digest('hex')
})
}
if (machineInfo.active) {
if (machineInfo.deviceId) {
options = _.assign(options, {
'device-machine-id': machineInfo.deviceId
})
}
if (machineInfo.deviceName) {
options = _.assign(options, {
'device-machine-name': machineInfo.deviceName
})
}
}
if (watchdogInfo.model) {
options = _.assign(options, {
'device-machine-model': watchdogInfo.model
})
}
if (watchdogInfo.platform) {
options = _.assign(options, {
'device-machine-platform': watchdogInfo.platform
if (connectionInfo.host) {
headers = _.assign(headers, {
'device-host': crypto.createHash('sha256').update(connectionInfo.host).digest('hex')
})
}
if (machineInfo.active && machineInfo.deviceName) {
headers = _.assign(headers, {
'device-machine-name': machineInfo.deviceName
})
}
if (watchdogInfo.model) {
headers = _.assign(headers, {
'device-machine-model': watchdogInfo.model
})
}
if (watchdogInfo.platform) {
headers = _.assign(headers, {
'device-machine-platform': watchdogInfo.platform
})
}
return headers
})
}
return options
}

Updater.prototype._update = function _update () {
if (this.downloading) return
var self = this
this.httpsOptions.headers = this.updateHeaders(this.httpsOptions.headers)
https.get(this.httpsOptions, function (res) {
var code = res.statusCode
switch (code) {
case 304:
res.resume()
break
case 412:
res.resume()
self.emit('error', new Error('Server has lower version!'))
break
case 200:
self._downloadFile(res)
break
default:
res.resume()
this.emit('error', new Error('Unknown response code: ' + code))
}
}).on('error', noop)
return this.updateHeaders(this.httpsOptions.headers)
.then(headers => {
this.httpsOptions.headers = headers
return https.get(this.httpsOptions, res => {
var code = res.statusCode
switch (code) {
case 304:
res.resume()
break
case 412:
res.resume()
this.emit('error', new Error('Server has lower version!'))
break
case 200:
this._downloadFile(res)
break
default:
res.resume()
this.emit('error', new Error('Unknown response code: ' + code))
}
}).on('error', noop)
})
}

Updater.prototype._downloadFile = function _downloadFile (res) {
Expand Down

0 comments on commit 32650cc

Please sign in to comment.