Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function Config(config) {
'.sinopia-db.json'
)
)
self.localList.on('data', function(data) {
if (data && data.secret) {
self.secret = data.secret
}
})
if (!self.secret) {
self.secret = self.localList.data.secret

Expand Down Expand Up @@ -195,4 +200,3 @@ module.exports.parse_interval = function(interval) {
})
return result
}

29 changes: 24 additions & 5 deletions lib/local-data.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
var fs = require('fs')
var Path = require('path')
var util = require("util")
var events = require("events")
var Logger = require('./logger')

module.exports = LocalData

function LocalData(path) {
var self = Object.create(LocalData.prototype)
events.EventEmitter.call(self);
self.logger = Logger.logger.child()
self.path = path
self.parseData()
// Refreshes package list.
// Necessary in case of running Sinopia*
// in shared FS based 'cluster'.
fs.watchFile(self.path, function (curr, prev) {
self.parseData()
})
return self
}

util.inherits(LocalData, events.EventEmitter)

LocalData.prototype.parseData = function() {
try {
self.data = JSON.parse(fs.readFileSync(self.path, 'utf8'))
} catch(_) {
self.data = { list: [] }
this.data = JSON.parse(fs.readFileSync(this.path, 'utf8'))
this.logger.warn('The LocalData config has been updated.')
this.emit("data", this.data)
} catch(err) {
this.logger.error({ err: err }, 'The LocalData config parse error: @{err.message}')
this.data = { list: [] }
}
return self
}

LocalData.prototype.add = function(name) {
Expand Down Expand Up @@ -41,4 +61,3 @@ LocalData.prototype.sync = function() {
} catch(err) {}
fs.writeFileSync(this.path, JSON.stringify(this.data))
}

5 changes: 4 additions & 1 deletion lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ Search.prototype.reindex = function() {
Search.prototype.configureStorage = function(storage) {
this.storage = storage
this.reindex()
var self = this
this.storage.config.localList.on('data', function(data) {
self.reindex()
})
}

module.exports = Search()