Skip to content

Commit

Permalink
fix: hack uploader to handle a response from v3 write api
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Dec 9, 2020
1 parent 340387c commit 41379e2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion public/src/modules/uploader.js
Expand Up @@ -65,7 +65,9 @@ define('uploader', ['jquery-form'], function () {
}

module.ajaxSubmit = function (uploadModal, callback) {
uploadModal.find('#uploadForm').ajaxSubmit({
const uploadForm = uploadModal.find('#uploadForm');
const v3 = uploadForm.attr('action').startsWith(config.relative_path + '/api/v3/');
uploadForm.ajaxSubmit({
headers: {
'x-csrf-token': config.csrf_token,
},
Expand All @@ -79,6 +81,17 @@ define('uploader', ['jquery-form'], function () {
success: function (response) {
response = maybeParse(response);

// Appropriately handle v3 API responses
if (v3) {
if (response.status.code === 'ok') {
response = response.response.images;
} else {
response = {
error: response.status.code,
};
}
}

if (response.error) {
return showAlert(uploadModal, 'error', response.error);
}
Expand Down

0 comments on commit 41379e2

Please sign in to comment.