From cb2970f31e1d5883418ae1a0f30a2e5f26153269 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Fri, 10 Dec 2021 14:11:53 -0800 Subject: [PATCH] Added sending default image when agent uses getUserImage command. --- meshagent.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/meshagent.js b/meshagent.js index c84b1871..d0c838da 100644 --- a/meshagent.js +++ b/meshagent.js @@ -1641,7 +1641,15 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // An agent can only request images of accounts with rights to the device. if (parent.GetNodeRights(command.userid, obj.dbMeshKey, obj.dbNodeKey) != 0) { parent.db.Get('im' + command.userid, function (err, images) { - if ((err == null) && (images != null) && (images.length == 1)) { command.image = images[0].image; } + if ((err == null) && (images != null) && (images.length == 1)) { + // Send back the account image + command.image = images[0].image; + } else { + // Send back the default image if required + if (command.default) { + try { command.image = 'data:image/png;base64,' + Buffer.from(parent.fs.readFileSync(parent.parent.path.join(__dirname, 'public', 'images', 'user-128.png')), 'binary').toString('base64'); } catch (ex) { } + } + } obj.send(JSON.stringify(command)); }); }