I have set up a websocket that reads all e-mail addresses as a backend and sends them to the client. Now I want the used memory space to be sent along with the quota. The mysql-Query results in an array with several JSON strings (results):
{ id: 10,
domain_id: 6,
email: 'mailadress',
password: 'password',
quota: 5368709120,
crypt: 2,
wsplx: 'customer',
quota_used: undefined }
As a further value I want to enter “quota_used.” That’s why I wrote the following code:
for (value of results) {
console.log(get_used_quota(value.email))
value.quota_used = get_used_quota(value.email);
}
socket.emit("response_get_update_mails", (results));
function get_used_quota(email) {
var mailadress_arr = email.split("@");
var cmd = "du -sb /var/vmail/" + mailadress_arr[1] + "/" + mailadress_arr[0] + "/Maildir/";
exec(cmd, (error, stdout, stderr) => {
if (error) {
showtoaster("\"" + `${error.message}` + "\"", "Ein Fehler ist aufgetreten!", "warning", true, true, 3000)
return;
}
if (stderr) {
showtoaster("\"" + `${stderr}` + "\"", "Ein Fehler ist aufgetreten!", "warning", true, true, 3000)
return;
}
var output = `${stdout}`;
var size_arr = output.split("\t");
size = parseInt(size_arr[0]);
return size
})
}
The problem is that I can’t get the value “size” out of the arrow function. The return value of the function remains undefined. Can someone help me to fix this problem, this would be very nice? Let my know, if you need more information.