Skip to content

Commit

Permalink
Return response from Solr downloadWithCredentials
Browse files Browse the repository at this point in the history
Fixes SolrResult test
Fix a typo

Issue #1758
  • Loading branch information
robyngit committed Sep 18, 2024
1 parent cc43393 commit 9580676
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/js/models/SolrResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ define(["jquery", "underscore", "backbone"], ($, _, Backbone) => {
/**
* Download this object while sending the user's auth token in the
* request.
* @returns {Promise} A promise that resolves to the response object
* @since 0.0.0
*/
async downloadWithCredentials() {
// Call the new getBlob method and handle the response
this.fetchDataObjectWithCredentials()
.then((response) => this.downloadFromResposne(response))
return this.fetchDataObjectWithCredentials()
.then((response) => this.downloadFromResponse(response))
.catch((error) => this.handleDownloadError(error));
},

Expand Down Expand Up @@ -349,9 +351,10 @@ define(["jquery", "underscore", "backbone"], ($, _, Backbone) => {
/**
* Download data onto the user's computer from the response object
* @param {Response} response - The response object from the fetch request
* @returns {Response} The response object
* @since 0.0.0
*/
async downloadFromResposne(response) {
async downloadFromResponse(response) {
const model = this;
const blob = await response.blob();
const filename = this.getFileNameFromResponse(response);
Expand All @@ -377,6 +380,8 @@ define(["jquery", "underscore", "backbone"], ($, _, Backbone) => {
"Download DataONEObject",
model.get("id"),
);

return response;
},

/**
Expand Down Expand Up @@ -575,7 +580,7 @@ define(["jquery", "underscore", "backbone"], ($, _, Backbone) => {
model.set("size", $(data).find("size").text() || "");

//Get the entity name
model.set("filename", $(data).find("filename").text() || "");
model.set("fileName", $(data).find("filename").text() || "");

//Check if this is a metadata doc
var formatId = $(data).find("formatid").text() || "",
Expand Down
2 changes: 1 addition & 1 deletion src/js/views/DataObjectView.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ define([
downloadButton.onclick = (e) => {
e.preventDefault();
const response = view.response.clone();
view.model.downloadFromResposne(response);
view.model.downloadFromResponse(response);
};
this.buttonContainer.appendChild(downloadButton);
},
Expand Down

0 comments on commit 9580676

Please sign in to comment.