Added sending default image when agent uses getUserImage command.
Ylian Saint-Hilaire committed
Dec 10, 2021 at 14:11 UTC
cb2970f31e1d5883418ae1a0f30a2e5f26153269
1 file changed
+9
-1
meshagent.js
+9
-1
@@ -1641,7 +1641,15 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1641
// An agent can only request images of accounts with rights to the device.
1642
if (parent.GetNodeRights(command.userid, obj.dbMeshKey, obj.dbNodeKey) != 0) {
1643
parent.db.Get('im' + command.userid, function (err, images) {
1644
- if ((err == null) && (images != null) && (images.length == 1)) { command.image = images[0].image; }
1644
+ if ((err == null) && (images != null) && (images.length == 1)) {
1645
+ // Send back the account image
1646
+ command.image = images[0].image;
1647
+ } else {
1648
+ // Send back the default image if required
1649
+ if (command.default) {
1650
+ 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) { }
1651
+ }
1652
+ }
1653
obj.send(JSON.stringify(command));
1654
});
1655
}