balena-supervisor/src/api.coffee

36 lines
814 B
CoffeeScript
Raw Normal View History

2013-12-23 04:22:54 +00:00
Promise = require 'bluebird'
fs = Promise.promisifyAll require 'fs'
utils = require './utils'
express = require 'express'
application = require './application'
supervisor = require './supervisor-update'
api = express()
LED_FILE = '/sys/class/leds/led0/brightness'
2013-12-23 04:22:54 +00:00
blink = (ms = 200) ->
fs.writeFileAsync(LED_FILE, 1)
.delay(ms)
2014-03-19 19:54:39 +00:00
.then -> fs.writeFileAsync(LED_FILE, 0)
2014-03-19 19:54:39 +00:00
api.post '/v1/blink', (req, res) ->
2014-06-18 16:54:36 +00:00
utils.mixpanelTrack('Device blink')
interval = setInterval(blink, 400)
2013-12-17 06:04:53 +00:00
setTimeout(->
clearInterval(interval)
2014-04-27 21:22:06 +00:00
, 15000)
res.send(200)
2014-03-19 19:54:39 +00:00
api.post '/v1/update', (req, res) ->
2014-06-18 16:54:36 +00:00
utils.mixpanelTrack('Update notification')
application.update()
res.send(204)
api.post '/v1/update-supervisor', (req, res) ->
console.log('Got supervisor update')
supervisor.update()
res.send(204)
module.exports = api