Rework the disk usage code

This commit is contained in:
Johannes Zellner
2022-10-12 16:26:09 +02:00
parent 51ecb708c7
commit 82f915ac1c
3 changed files with 73 additions and 34 deletions

View File

@@ -1300,6 +1300,21 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.waitForTask = function (taskId, callback) {
var that = this;
function checkTask() {
that.getTask(taskId, function (error, result) {
if (error) return callback(error);
if (result.pending || result.active) return setTimeout(checkTask, 1000);
callback(result.error, result.result);
});
}
checkTask();
};
Client.prototype.getTask = function (taskId, callback) {
get('/api/v1/tasks/' + taskId, null, function (error, data, status) {
if (error) return callback(error);
@@ -1930,6 +1945,26 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.diskUsage = function (callback) {
get('/api/v1/cloudron/disk_usage', null, function (error, data, status) {
if (error) return callback(error);
if (status !== 200) return callback(new ClientError(status, data));
callback(null, data);
});
};
Client.prototype.refreshDiskUsage = function (callback) {
var that = this;
post('/api/v1/cloudron/disk_usage', {}, null, function (error, data, status) {
if (error) return callback(error);
if (status !== 201) return callback(new ClientError(status, data));
that.waitForTask(data.taskId, callback);
});
};
Client.prototype.memory = function (callback) {
get('/api/v1/cloudron/memory', null, function (error, data, status) {
if (error) return callback(error);