Directly determine file download URL in js client
We don't need an extra round trip here
This commit is contained in:
parent
53c0ad0889
commit
d017e507aa
1 changed files with 10 additions and 15 deletions
|
|
@ -9,11 +9,20 @@
|
|||
}
|
||||
})(function(OctoPrint, $, _) {
|
||||
var url = "api/files";
|
||||
var downloadUrl = "downloads/files";
|
||||
|
||||
var resourceForLocation = function(location) {
|
||||
return url + "/" + location;
|
||||
};
|
||||
|
||||
var downloadForLocation = function(location) {
|
||||
return downloadUrl + "/" + location;
|
||||
};
|
||||
|
||||
var downloadForEntry = function(location, filename) {
|
||||
return downloadForLocation(location) + "/" + filename;
|
||||
};
|
||||
|
||||
var resourceForEntry = function(location, filename) {
|
||||
return resourceForLocation(location) + "/" + filename;
|
||||
};
|
||||
|
|
@ -119,21 +128,7 @@
|
|||
},
|
||||
|
||||
download: function (location, path, opts) {
|
||||
var deferred = $.Deferred();
|
||||
getEntry(location, path, opts)
|
||||
.done(function (response) {
|
||||
OctoPrint.download(response.refs.download, opts)
|
||||
.done(function () {
|
||||
deferred.resolve.apply(null, arguments);
|
||||
})
|
||||
.fail(function () {
|
||||
deferred.reject.apply(null, arguments);
|
||||
});
|
||||
})
|
||||
.fail(function () {
|
||||
deferred.reject.apply(null, arguments);
|
||||
});
|
||||
return deferred.promise();
|
||||
return OctoPrint.download(downloadForEntry(location, path), opts);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue