nanocyte-configuration-generator
Version:
Generate Nanocyte configuration from an Octoblu flow
56 lines (44 loc) • 1.44 kB
text/coffeescript
_ = require 'lodash'
s3 = require 's3'
CHANNEL_S3_BUCKET = 'octoblu-channels'
CHANNEL_S3_KEY = 'channels.json'
class ChannelDownloader
constructor: ->
= false
= null
= null
= _.throttle , 60*1000*5, leading: true, trailing: false
setOptions: (options) =>
return if _.isEmpty options.accessKeyId
?= s3.createClient
s3Options:
accessKeyId: options.accessKeyId
secretAccessKey: options.secretAccessKey
update: (callback) =>
return callback null, {} unless ?
()
return callback null, if
downloader = .downloadBuffer
Bucket: CHANNEL_S3_BUCKET
Key: CHANNEL_S3_KEY
downloader.on 'httpHeaders', (statusCode, headers) ->
= headers.etag
downloader.on 'error', callback
downloader.on 'end', (buffer) =>
try
= JSON.parse buffer
catch error
return callback error
= true
callback null,
_checkEtagImmediately: =>
list = .listObjects
s3Params:
Bucket: CHANNEL_S3_BUCKET
list.on 'data', (data) =>
entry = _.find data.Contents, {'Key': 'channels.json'}
return unless entry?
return if == entry.ETag
= entry.ETag
= false
module.exports = ChannelDownloader