Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #12014 from NejcZdovc/hotfix/#11394-run
Browse files Browse the repository at this point in the history
Fixes broken fake synopsis visits
  • Loading branch information
bsclifton committed Nov 17, 2017
1 parent 5ab40ba commit 9c77f59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
17 changes: 10 additions & 7 deletions tools/lib/synopsisHelpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const fs = require('fs')

const randomHostname = require('./randomHostname')

const Synopsis = require('bat-publisher').Synopsis
Expand All @@ -22,14 +20,19 @@ const generateSynopsisVisits = function (synopsis, numPublishers) {
return synopsis
}

const updateExistingSynopsisFile = function (synopsisPath, numPublishers) {
let synopsis = new Synopsis(JSON.parse(fs.readFileSync(synopsisPath).toString()))
const addSynopsisVisits = function (sessionData, numPublishers) {
let synopsis = new Synopsis(sessionData.ledger.synopsis)
const generated = generateSynopsisVisits(synopsis, numPublishers)

synopsis = generateSynopsisVisits(synopsis, numPublishers)
try {
sessionData.ledger.synopsis = generated
} catch (e) {
console.log('Please create empty profile first')
}

fs.writeFileSync(synopsisPath, JSON.stringify(synopsis, null, 2))
return sessionData
}

module.exports = {
updateExistingSynopsisFile: updateExistingSynopsisFile
addSynopsisVisits
}
14 changes: 11 additions & 3 deletions tools/lib/utilApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ function addSimulatedLedgerTransactions (numTx) {
}
}

const updateExistingSynopsisFile = require('../synopsisHelpers').updateExistingSynopsisFile
const {addSynopsisVisits} = require('../synopsisHelpers')
function addSimulatedSynopsisVisits (numPublishers) {
let userDataPath = app.getPath('userData')
let ledgerSynopsisPath = path.join(userDataPath, 'ledger-synopsis.json')
const sessionFile = path.join(userDataPath, `session-store-1`)

updateExistingSynopsisFile(ledgerSynopsisPath, numPublishers)
try {
let sessionData = fs.readFileSync(sessionFile)
sessionData = JSON.parse(sessionData)

sessionData = addSynopsisVisits(sessionData, numPublishers)
fs.writeFileSync(sessionFile, JSON.stringify(sessionData, null, 2))
} catch (err) {
console.error('ERROR in addSimulatedSynopsisVisits: ', err.toString())
}
}

app.on('ready', () => {
Expand Down

0 comments on commit 9c77f59

Please sign in to comment.