forked from asztalosdani/substance-painter-to-deadline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deadline.js
62 lines (54 loc) · 1.82 KB
/
deadline.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function getPools(readyCallback, errorCallback) {
sendRequest("/api/pools", readyCallback, errorCallback)
}
function getGroups(readyCallback, errorCallback) {
sendRequest("/api/groups", readyCallback, errorCallback)
}
function getUser(username, readyCallback, errorCallback) {
sendRequest("/api/users?Name=" + username, readyCallback, errorCallback)
}
function submitJob(jobInfo, pluginInfo, readyCallback, errorCallback) {
var body = {JobInfo: jobInfo, PluginInfo: pluginInfo, AuxFiles: []}
sendRequest("/api/jobs", readyCallback, errorCallback, "POST", body)
}
function sendRequest(path, readyCallback, errorCallback, method, body) {
if (method === undefined) {
method = "GET"
}
if (body == undefined) {
body = null
}
if (errorCallback == undefined) {
errorCallback = onError
}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
var data = JSON.parse(xhttp.responseText);
readyCallback(data)
} else {
errorCallback(xhttp.status, xhttp.responseText)
}
}
};
var host = alg.settings.value("Host")
var port = alg.settings.value("Port")
if (host.indexOf("http://") != 0) {
host = "http://" + host
}
var url = host + ":" + port + path
alg.log.info(url)
xhttp.open(method, url, true);
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.send(JSON.stringify(body));
var timeout = setTimeout(onTimeout, 5000);
function onTimeout() {
xhttp.abort()
}
}
function onError(status, response) {
alg.log.error("Error occurred")
alg.log.error("Status: " + status)
alg.log.error("Response: " + response)
}