Skip to content

Commit ec090d2

Browse files
committed
Temporary fix that allows downloading (only) zip results
1 parent f1129a0 commit ec090d2

File tree

7 files changed

+189
-7
lines changed

7 files changed

+189
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
#!**/src/test/**/build/
77
#
88
#### Spring boot ###
9-
#**/application.properties
9+
**/application.properties
1010
#
1111
#### Gemma/python ###
1212
#/gemma
1313
#**/__pycache__
14+
**/output
1415
#
1516
#### STS ###
1617
#.apt_generated

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ configurations {
2525
}
2626
}
2727

28+
sourceCompatibility = 1.17
29+
targetCompatibility = 1.17
30+
2831
repositories {
2932
mavenLocal()
3033
mavenCentral()

src/main/java/edu/kit/datamanager/mappingservice/plugins/PluginLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public static Map<String, IMappingPlugin> loadPlugins(File plugDir) throws IOExc
6868
throw new MappingPluginException(MappingPluginState.NOT_FOUND, "No plugins found.");
6969
}
7070
cl = new URLClassLoader(PluginLoader.fileArrayToURLArray(plugJars));
71+
7172
List<Class<IMappingPlugin>> plugClasses = PluginLoader.extractClassesFromJARs(plugJars, cl);
7273

7374
List<IMappingPlugin> IMappingPluginList = PluginLoader.createPluggableObjects(plugClasses);

src/main/java/edu/kit/datamanager/mappingservice/rest/impl/MappingExecutionController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ public ResponseEntity mapDocument(MultipartFile document, String mappingID, Http
114114
}
115115

116116
LOG.trace("Successfully mapped document with mapping {}.", mappingID);
117-
return ResponseEntity.ok().header(HttpHeaders.CONTENT_LENGTH, String.valueOf(resultPath.toFile().length())).body(new FileSystemResource(resultPath.toFile()));
117+
return ResponseEntity.ok().
118+
header(HttpHeaders.CONTENT_LENGTH, String.valueOf(resultPath.toFile().length())).
119+
header(HttpHeaders.CONTENT_TYPE, String.valueOf("application/zip")).
120+
header(HttpHeaders.CONTENT_DISPOSITION, String.valueOf("attachment; " + "result.zip")).
121+
body(new FileSystemResource(resultPath.toFile()));
118122
}
119123
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
//download.js v4.2, by dandavis; 2008-2016. [CCBY2] see http://danml.com/download.html for tests/usage
2+
// v1 landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
3+
// v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs
4+
// v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support. 3.1 improved safari handling.
5+
// v4 adds AMD/UMD, commonJS, and plain browser support
6+
// v4.1 adds url download capability via solo URL argument (same domain/CORS only)
7+
// v4.2 adds semantic variable names, long (over 2MB) dataURL support, and hidden by default temp anchors
8+
// https://github.com/rndme/download
9+
10+
(function (root, factory) {
11+
if (typeof define === 'function' && define.amd) {
12+
// AMD. Register as an anonymous module.
13+
define([], factory);
14+
} else if (typeof exports === 'object') {
15+
// Node. Does not work with strict CommonJS, but
16+
// only CommonJS-like environments that support module.exports,
17+
// like Node.
18+
module.exports = factory();
19+
} else {
20+
// Browser globals (root is window)
21+
root.download = factory();
22+
}
23+
}(this, function () {
24+
25+
return function download(data, strFileName, strMimeType) {
26+
27+
var self = window, // this script is only for browsers anyway...
28+
defaultMime = "application/octet-stream", // this default mime also triggers iframe downloads
29+
mimeType = strMimeType || defaultMime,
30+
payload = data,
31+
url = !strFileName && !strMimeType && payload,
32+
anchor = document.createElement("a"),
33+
toString = function(a){return String(a);},
34+
myBlob = (self.Blob || self.MozBlob || self.WebKitBlob || toString),
35+
fileName = strFileName || "download",
36+
blob,
37+
reader;
38+
myBlob= myBlob.call ? myBlob.bind(self) : Blob ;
39+
40+
if(String(this)==="true"){ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
41+
payload=[payload, mimeType];
42+
mimeType=payload[0];
43+
payload=payload[1];
44+
}
45+
46+
47+
if(url && url.length< 2048){ // if no filename and no mime, assume a url was passed as the only argument
48+
fileName = url.split("/").pop().split("?")[0];
49+
anchor.href = url; // assign href prop to temp anchor
50+
if(anchor.href.indexOf(url) !== -1){ // if the browser determines that it's a potentially valid url path:
51+
var ajax=new XMLHttpRequest();
52+
ajax.open( "GET", url, true);
53+
ajax.responseType = 'blob';
54+
ajax.onload= function(e){
55+
download(e.target.response, fileName, defaultMime);
56+
};
57+
setTimeout(function(){ ajax.send();}, 0); // allows setting custom ajax headers using the return:
58+
return ajax;
59+
} // end if valid url?
60+
} // end if url?
61+
62+
63+
//go ahead and download dataURLs right away
64+
if(/^data\:[\w+\-]+\/[\w+\-]+[,;]/.test(payload)){
65+
66+
if(payload.length > (1024*1024*1.999) && myBlob !== toString ){
67+
payload=dataUrlToBlob(payload);
68+
mimeType=payload.type || defaultMime;
69+
}else{
70+
return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs:
71+
navigator.msSaveBlob(dataUrlToBlob(payload), fileName) :
72+
saver(payload) ; // everyone else can save dataURLs un-processed
73+
}
74+
75+
}//end if dataURL passed?
76+
77+
blob = payload instanceof myBlob ?
78+
payload :
79+
new myBlob([payload], {type: mimeType}) ;
80+
81+
82+
function dataUrlToBlob(strUrl) {
83+
var parts= strUrl.split(/[:;,]/),
84+
type= parts[1],
85+
decoder= parts[2] == "base64" ? atob : decodeURIComponent,
86+
binData= decoder( parts.pop() ),
87+
mx= binData.length,
88+
i= 0,
89+
uiArr= new Uint8Array(mx);
90+
91+
for(i;i<mx;++i) uiArr[i]= binData.charCodeAt(i);
92+
93+
return new myBlob([uiArr], {type: type});
94+
}
95+
96+
function saver(url, winMode){
97+
98+
if ('download' in anchor) { //html5 A[download]
99+
anchor.href = url;
100+
anchor.setAttribute("download", fileName);
101+
anchor.className = "download-js-link";
102+
anchor.innerHTML = "downloading...";
103+
anchor.style.display = "none";
104+
document.body.appendChild(anchor);
105+
setTimeout(function() {
106+
anchor.click();
107+
document.body.removeChild(anchor);
108+
if(winMode===true){setTimeout(function(){ self.URL.revokeObjectURL(anchor.href);}, 250 );}
109+
}, 66);
110+
return true;
111+
}
112+
113+
// handle non-a[download] safari as best we can:
114+
if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
115+
url=url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
116+
if(!window.open(url)){ // popup blocked, offer direct download:
117+
if(confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")){ location.href=url; }
118+
}
119+
return true;
120+
}
121+
122+
//do iframe dataURL download (old ch+FF):
123+
var f = document.createElement("iframe");
124+
document.body.appendChild(f);
125+
126+
if(!winMode){ // force a mime that will download:
127+
url="data:"+url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
128+
}
129+
f.src=url;
130+
setTimeout(function(){ document.body.removeChild(f); }, 333);
131+
132+
}//end saver
133+
134+
135+
136+
137+
if (navigator.msSaveBlob) { // IE10+ : (has Blob, but not a[download] or URL)
138+
return navigator.msSaveBlob(blob, fileName);
139+
}
140+
141+
if(self.URL){ // simple fast and modern way using Blob and URL:
142+
saver(self.URL.createObjectURL(blob), true);
143+
}else{
144+
// handle non-Blob()+non-URL browsers:
145+
if(typeof blob === "string" || blob.constructor===toString ){
146+
try{
147+
return saver( "data:" + mimeType + ";base64," + self.btoa(blob) );
148+
}catch(y){
149+
return saver( "data:" + mimeType + "," + encodeURIComponent(blob) );
150+
}
151+
}
152+
153+
// Blob but not URL support:
154+
reader=new FileReader();
155+
reader.onload=function(e){
156+
saver(this.result);
157+
};
158+
reader.readAsDataURL(blob);
159+
}
160+
return true;
161+
}; /* end download() */
162+
}));

src/main/resources/static/JS/mapDocument.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@ function map() {
3131
http.open("POST", execUrl + id)
3232
http.send(formData)
3333
http.onload = () => {
34+
let content_dispo = http.getResponseHeader("content-disposition");
35+
let filename = content_dispo.substr(content_dispo.lastIndexOf(";") + 1);
36+
download(http.responseText, filename, http.getResponseHeader("content-type"));
37+
document.getElementById("progress").hidden = true
38+
document.getElementById("downloadButton").hidden = false
39+
document.getElementById("submit").disabled = false
40+
41+
/* console.log(http.getAllResponseHeaders())
3442
console.log(http.responseText)
35-
document.getElementById("downloadButton").setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(http.responseText));
36-
document.getElementById("downloadButton").setAttribute('download', "result.json");
43+
44+
// document.getElementById("downloadButton").setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(http.responseText));
45+
//document.getElementById("downloadButton").setAttribute('download', "result.json");
3746
document.getElementById("progress").hidden = true
3847
document.getElementById("downloadButton").hidden = false
3948
document.getElementById("submit").disabled = false
@@ -42,14 +51,15 @@ function map() {
4251
downloadHTTP.send();
4352
downloadHTTP.onload = () => {
4453
const element = document.createElement('a');
45-
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(http.responseText));
46-
element.setAttribute('download', "result.json");
54+
//element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(http.responseText));
55+
element.setAttribute('href', encodeURIComponent(http.responseText));
56+
//element.setAttribute('download', "result.json");
4757
element.style.display = 'none';
4858
document.body.appendChild(element);
4959
element.click();
5060
document.body.removeChild(element);
5161
}
52-
62+
*/
5363
}
5464
http.onprogress = () => {
5565
document.getElementById("progress").hidden = false

src/main/resources/static/mapDocument.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
1717
crossorigin="anonymous"></script>
1818
<script defer src="JS/mapDocument.js"></script>
19+
<script defer src="JS/download.js"></script>
1920

2021
<header class="row align-items-center navbar">
2122
<h1 class="header col-auto">Mapping-Service GUI</h1>

0 commit comments

Comments
 (0)