mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 22:23:07 +00:00
47 lines
1.2 KiB
CoffeeScript
47 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')
|
|
log = require('../log/log')
|
|
permissions = require('../permissions/permissions')
|
|
errors = require('../errors/errors')
|
|
|
|
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) ->
|
|
errors.handle(error) if error?
|
|
log.info("\nFinished downloading #{outputFile}")
|