mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 14:13:07 +00:00
45 lines
1.2 KiB
CoffeeScript
45 lines
1.2 KiB
CoffeeScript
_ = require('lodash')
|
|
async = require('async')
|
|
path = require('path')
|
|
mkdirp = require('mkdirp')
|
|
url = require('url')
|
|
resin = require('../resin')
|
|
connection = require('../connection/connection')
|
|
ui = require('../ui')
|
|
permissions = require('../permissions/permissions')
|
|
|
|
exports.download = (params, options) ->
|
|
networkParams =
|
|
network: options.network
|
|
wifiSsid: options.ssid
|
|
wifiKey: options.key
|
|
|
|
fileName = resin.os.generateCacheName(params.id, networkParams)
|
|
outputFile = options.output or path.join(resin.settings.get('directories.os'), fileName)
|
|
|
|
async.waterfall [
|
|
|
|
(callback) ->
|
|
|
|
# We need to ensure this directory exists
|
|
mkdirp path.dirname(outputFile), (error) ->
|
|
return callback(error)
|
|
|
|
(callback) ->
|
|
connection.parseConnectionParameters(networkParams, callback)
|
|
|
|
(parameters, callback) ->
|
|
parameters.appId = params.id
|
|
|
|
query = url.format(query: parameters)
|
|
downloadUrl = url.resolve(resin.settings.get('urls.download'), query)
|
|
|
|
return callback(null, downloadUrl)
|
|
|
|
(downloadUrl, callback) ->
|
|
ui.patterns.downloadFile(downloadUrl, outputFile, callback)
|
|
|
|
], (error) ->
|
|
resin.errors.handle(error) if error?
|
|
resin.log.info("\nFinished downloading #{outputFile}")
|