Skip to content
Snippets Groups Projects
Commit c5724e57 authored by vkovtun's avatar vkovtun
Browse files

BIS-753: Fixing the issue with incorrect binary data processing by the new DSS.

parent d95bb31d
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -48,12 +48,29 @@ _DataStoreServerInternal.prototype.jsonRequestData = function(params) {
_DataStoreServerInternal.prototype.sendHttpRequest = function(httpMethod, contentType, url, data, callback) {
const xhr = new XMLHttpRequest();
xhr.open(httpMethod, url);
xhr.setRequestHeader("content-type", contentType);
xhr.responseType = "blob";
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
const status = xhr.status;
if (xhr.readyState === XMLHttpRequest.DONE) {
const status = xhr.status;
if (status >= 200 && status < 300) {
callback(xhr.responseText);
const response = xhr.response
const contentType = this.getResponseHeader('content-type');
switch (contentType) {
case 'text/plain':
response.text().then((blobResponse) => callback(blobResponse))
.catch((error) => alert(error));
break;
case 'application/octet-stream':
callback(response);
break;
case 'application/json':
response.text().then((blobResponse) => callback(blobResponse))
.catch((error) => alert(error));
break;
}
} else if(status >= 400 && status < 500) {
let response = JSON.parse(xhr.responseText);
alert(response.error[1].message);
......@@ -63,12 +80,10 @@ _DataStoreServerInternal.prototype.sendHttpRequest = function(httpMethod, conten
} else {
alert("ERROR: " + xhr.responseText);
}
}
}
};
xhr.send(data);
}
}
......@@ -281,7 +296,7 @@ DataStoreServer.prototype.login = function(userId, userPassword, action) {
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
function(loginResponse) {
......@@ -303,7 +318,7 @@ DataStoreServer.prototype.isSessionValid = function(action) {
const data = this.fillCommonParameters({"method":"isSessionValid"});
this._internal.sendHttpRequest(
"GET",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => parseJsonResponse(response, action)
......@@ -338,7 +353,7 @@ DataStoreServer.prototype.logout = function(action) {
const data = this.fillCommonParameters({"method":"logout"});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => parseJsonResponse(response, action)
......@@ -367,7 +382,7 @@ DataStoreServer.prototype.list = function(owner, source, recursively, action){
});
this._internal.sendHttpRequest(
"GET",
"text/plain",
"application/octet-stream",
this._internal.buildGetUrl(data),
{},
(response) => parseJsonResponse(response, action)
......@@ -392,7 +407,7 @@ DataStoreServer.prototype.read = function(owner, source, offset, limit, action){
});
this._internal.sendHttpRequest(
"GET",
"text",
"application/octet-stream",
this._internal.buildGetUrl(data),
{},
(response) => action(response)
......@@ -428,7 +443,7 @@ DataStoreServer.prototype.write = function(owner, source, offset, data, action){
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(params),
(response) => action(response)
......@@ -449,7 +464,7 @@ DataStoreServer.prototype.delete = function(owner, source, action){
});
this._internal.sendHttpRequest(
"DELETE",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -469,7 +484,7 @@ DataStoreServer.prototype.copy = function(sourceOwner, source, targetOwner, targ
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -489,7 +504,7 @@ DataStoreServer.prototype.move = function(sourceOwner, source, targetOwner, targ
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -509,7 +524,7 @@ DataStoreServer.prototype.create = function(owner, source, directory, action){
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -530,7 +545,7 @@ DataStoreServer.prototype.begin = function(transactionId, action){
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -544,7 +559,7 @@ DataStoreServer.prototype.prepare = function(action){
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -558,7 +573,7 @@ DataStoreServer.prototype.commit = function(action){
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -573,7 +588,7 @@ DataStoreServer.prototype.rollback = function(action){
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......@@ -586,7 +601,7 @@ DataStoreServer.prototype.recover = function(action){
});
this._internal.sendHttpRequest(
"POST",
"text/plain",
"application/octet-stream",
this._internal.datastoreUrl,
encodeParams(data),
(response) => action(response)
......
......@@ -17,11 +17,11 @@ function createOpenButton(row, filePath, fileSize) {
readButton.dataset.filesize = fileSize;
readButton.onclick = (function() {
datastoreServer.read(owner, this.dataset.filepath, 0, this.dataset.filesize, (responseData => {
var win = window.open("", "_blank");
var doc = win.document;
doc.open("text/html");
doc.write(responseData);
doc.close();
const blob = responseData
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = filePath.substring(filePath.lastIndexOf('/') + 1)
link.click()
}));
});
row.appendChild(readButton);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment