Merge pull request #133 from rplatel/download-arbitrary-url
Allow downloads from arbitrary URLS
This commit is contained in:
commit
7606d25e4b
1 file changed
+34
-22
+34
-22
@@ -322,31 +322,43 @@ this.download = (task, methodResponse, callback) ->
|
|||||||
return
|
return
|
||||||
|
|
||||||
if methodResponse.type isnt 'DownloadResponse'
|
if methodResponse.type isnt 'DownloadResponse'
|
||||||
db.filesCollection.findOne({_id : mongodb.ObjectID(String(task.file))}, (err, file) ->
|
if task.url?
|
||||||
if not file?
|
methodRequest = {
|
||||||
callback('File not found')
|
type : 'Download',
|
||||||
return
|
fileType : task.fileType or '1 Firmware Upgrade Image',
|
||||||
else if err?
|
url : task.url,
|
||||||
callback(err)
|
username: task.username,
|
||||||
|
password: task.password,
|
||||||
|
successUrl : task.successUrl,
|
||||||
|
failureUrl : task.failureUrl
|
||||||
|
}
|
||||||
|
callback(null, STATUS_OK, methodRequest)
|
||||||
|
else
|
||||||
|
db.filesCollection.findOne({_id : mongodb.ObjectID(String(task.file))}, (err, file) ->
|
||||||
|
if not file?
|
||||||
|
callback('File not found')
|
||||||
|
return
|
||||||
|
else if err?
|
||||||
|
callback(err)
|
||||||
return
|
return
|
||||||
|
|
||||||
l = {
|
l = {
|
||||||
protocol : if config.get('FS_SSL') then 'https' else 'http',
|
protocol : if config.get('FS_SSL') then 'https' else 'http',
|
||||||
hostname : config.get('FS_IP'),
|
hostname : config.get('FS_IP'),
|
||||||
port : config.get('FS_PORT'),
|
port : config.get('FS_PORT'),
|
||||||
pathname : encodeURIComponent(file.filename)
|
pathname : encodeURIComponent(file.filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
methodRequest = {
|
methodRequest = {
|
||||||
type : 'Download',
|
type : 'Download',
|
||||||
fileType : file.metadata.fileType,
|
fileType : file.metadata.fileType,
|
||||||
fileSize : file.length,
|
fileSize : file.length,
|
||||||
url : url.format(l),
|
url : url.format(l),
|
||||||
successUrl : task.successUrl,
|
successUrl : task.successUrl,
|
||||||
failureUrl : task.failureUrl
|
failureUrl : task.failureUrl
|
||||||
}
|
}
|
||||||
callback(null, STATUS_OK, methodRequest)
|
callback(null, STATUS_OK, methodRequest)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
callback(null, STATUS_COMPLETED)
|
callback(null, STATUS_COMPLETED)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user