0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-26 02:23:48 +01:00

added fetch and fetchHeader in ServerAPI

This commit is contained in:
Rick Companje 2017-07-11 12:33:28 +02:00
parent 0f8e84016e
commit f8084b59d9

View File

@ -27,12 +27,56 @@ function ServerAPI() {
if (completeHandler) completeHandler(response); if (completeHandler) completeHandler(response);
} }
}).fail(function(response) { }).fail(function(response) {
console.log("fail"); if (failedHandler) failedHandler(response.responseJSON);
if (failedHandler) failedHandler();
}); });
}; };
// '/fetch/'+uid.value+'/'+line.value; this.fetch = function(uuid, chunk, completeHandler, failedHandler) {
console.log("ServerAPI:fetch",uuid,chunk);
if (!uuid) {
console.log("Server.fetch failed: no uuid");
if (failedHandler) failedHandler();
return;
}
if (!chunk) {
chunk = 0;
}
$.ajax({
url: _apiURL + "/fetch/" + uuid + "/" + chunk,
type: "GET",
dataType: 'text', //no json but text
timeout: _timeoutTime,
cache: false,
success: function(response) {
if (completeHandler) completeHandler(response);
}
}).fail(function(response) {
console.log("ServerAPI:fetch fail response:",response);
if (failedHandler) failedHandler(response.responseJSON);
});
};
this.fetchHeader = function(uuid,completeHandler,failedHandler) {
this.fetch(uuid,0,function(successData) {
console.log("_serverAPI fetchHeader");
if (successData) {
var items = successData.split("\n");
try {
var headerText = items[0].substr(1);
var headerJSON = JSON.parse(headerText);
// console.log("fetchHeader",headerJSON)
if (completeHandler) completeHandler(headerJSON);
} catch (e) {
console.log("fetchHeader failed to parse JSON",e);
if (failedHandler) failedHandler();
}
}
}, function(failData) {
console.log("_serverAPI fetchHeader failed",failData);
});
};
} }