39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
// this takes the files is the records folder and sends the messages to the server one by one, this is for recovery when the server crashes
|
|
|
|
const dgram = require('dgram')
|
|
const fs = require('fs')
|
|
const cellularChunking = require('./cellularChunking')
|
|
|
|
function handleMessage(message, rinfo) {
|
|
console.log('store message: ', message)
|
|
fetch('http://localhost:8085/api/data/store2', {
|
|
method: "POST",
|
|
body: JSON.stringify({"data":message}),
|
|
headers: {"Content-Type": "application/json",'Connection': 'Close', 'x-authentication': '40ab7a89-dad8-45ac-a68e-4f64b3df6373'}
|
|
}).then(x => x.text()).then(theResp => {
|
|
console.log('got a response: ', theResp)
|
|
}).catch(e => console.log)
|
|
}
|
|
|
|
let lineInd = 0
|
|
let theLines = []
|
|
|
|
function storeNextLine() {
|
|
if(theLines[lineInd].startsWith('>')) {
|
|
const tmp = theLines[lineInd].split(' ')
|
|
const theMessage = Buffer.from(tmp[tmp.length-1], 'hex')
|
|
lineInd = lineInd + 1
|
|
cellularChunking.receive_chunk(theMessage, handleMessage, undefined)
|
|
} else {
|
|
lineInd = lineInd + 1
|
|
}
|
|
setTimeout(storeNextLine, 100)
|
|
}
|
|
|
|
if(!process.argv[2]) {
|
|
console.log("usage: node ./storeRecords.js <filename.dat>")
|
|
} else {
|
|
let fileData = fs.readFileSync(`./records/${process.argv[2]}`, {encoding: 'utf-8'})
|
|
theLines = fileData.split('\n')
|
|
storeNextLine()
|
|
} |