Skip to content

Commit

Permalink
Handle blocking all but simple CORS request
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolan Woods committed Mar 8, 2021
1 parent 6bb0497 commit 2200614
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,39 @@ $(document).ready(function() {
// Allow specifying full src path in query or fall back to galaxy dataset path
const src = (injected_data && atob(injected_data)) || query.get('src') || (dataset_id && `/datasets/${dataset_id}/display`);

if (src) loadVis(src);
else {
$("#loading").hide();
$("#upload_box").show().on('change', function(event){
loadVis((event.dataTransfer ? event.dataTransfer.files : event.target.files)[0]);
$("#upload_box").hide();
});
if (!injected_data && query.has('src')) {
// Papaparse fails CORS, check preflight and compensate
fetch(query.get('src'), {
method: 'OPTIONS',
}).then(response=>{
if (response.ok) {
loadVis(src);
} else {
// Do 'simple' CORS request and pass result to papaparse
fetch(src).then(response=>response.blob().then(loadVis));
}
}).catch(reason => {
fetch(src).then(response=>response.blob().then(loadVis));
})
} else {
if (src) loadVis(src);
else {
$("#loading").hide();
$("#upload_box").show().on('change', function(event){
loadVis((event.dataTransfer ? event.dataTransfer.files : event.target.files)[0]);
$("#upload_box").hide();
});
}
}
});

function loadVis(src) {
var container = new MultiVis("#visualization-body");

var treeOrder;

var parser = Papa.parse(src, {
download: true,
download: typeof src == 'string',
delimiter: "\t",
worker: false,
skipEmptyLines: true,
Expand Down

0 comments on commit 2200614

Please sign in to comment.