From 22006143a407f60fbbdb8189f33d780c68936227 Mon Sep 17 00:00:00 2001 From: Nolan Woods Date: Mon, 8 Mar 2021 08:56:16 -0800 Subject: [PATCH] Handle blocking all but simple CORS request --- src/js/main.js | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/js/main.js b/src/js/main.js index 087e0f2..0d742d6 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -13,13 +13,29 @@ $(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(); + }); + } } }); @@ -27,8 +43,9 @@ 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,