mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-17 10:20:25 +00:00
43 lines
1.1 KiB
CoffeeScript
43 lines
1.1 KiB
CoffeeScript
_ = require('lodash')
|
|
async = require('async')
|
|
path = require('path')
|
|
mkdirp = require('mkdirp')
|
|
url = require('url')
|
|
resin = require('../resin')
|
|
connection = require('../connection/connection')
|
|
|
|
exports.download = (id) ->
|
|
params =
|
|
network: resin.cli.getArgument('network')
|
|
wifiSsid: resin.cli.getArgument('wifiSsid')
|
|
wifiKey: resin.cli.getArgument('wifiKey')
|
|
|
|
fileName = resin.os.generateCacheName(id, params)
|
|
outputFile = resin.cli.getArgument('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(params, callback)
|
|
|
|
(parameters, callback) ->
|
|
parameters.appId = id
|
|
|
|
query = url.format(query: parameters)
|
|
downloadUrl = url.resolve(resin.settings.get('urls.download'), query)
|
|
|
|
return callback(null, downloadUrl)
|
|
|
|
(downloadUrl, callback) ->
|
|
resin.ui.patterns.downloadFile(downloadUrl, outputFile, callback)
|
|
|
|
], (error) ->
|
|
resin.errors.handle(error) if error?
|
|
resin.log.info("\nFinished downloading #{outputFile}")
|