0.2.1: fix job spawn (CLI php), transitional states, zfs hold release before destroy, API error logging
This commit is contained in:
1 parent
485a267ffe
commit
364ab42ffe
6 files changed
+233
-69
No files matched your search
+20
-2
@@ -11,7 +11,25 @@
|
||||
credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
|
||||
body: new URLSearchParams(data).toString()
|
||||
}).then(function (r) { return r.json(); });
|
||||
}).then(function (r) { return readJson(r); });
|
||||
}
|
||||
|
||||
function readJson(r) {
|
||||
// a redirected request means the XigmaNAS session expired; the final
|
||||
// response is usually an empty login page, not JSON
|
||||
if (r.redirected || r.status === 0) {
|
||||
return {ok: false, error: 'session expired - please reload the page and log in again'};
|
||||
}
|
||||
return r.text().then(function (t) {
|
||||
if (!t) {
|
||||
return {ok: false, error: 'empty response (HTTP ' + r.status + ')'};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(t);
|
||||
} catch (e) {
|
||||
return {ok: false, error: 'HTTP ' + r.status + ': ' + t.slice(0, 300)};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function poll(id, box) {
|
||||
@@ -20,7 +38,7 @@
|
||||
var logEl = box.querySelector('pre');
|
||||
var timer = setInterval(function () {
|
||||
fetch('vmmngr_api.php?action=job&id=' + encodeURIComponent(id), {credentials: 'same-origin'})
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (r) { return readJson(r); })
|
||||
.then(function (d) {
|
||||
if (!d.ok) { return; }
|
||||
var j = d.job;
|
||||
|
||||
Reference in new issue
Block a user