fix multiple file upload bug #7473
Signed-off-by: si458 <simonsmith5521@gmail.com>
si458 committed
Dec 6, 2025 at 16:14 UTC
585b9d5c1d6c0587cd4dbe16e9220a0523fcfc94
1 file changed
+10
-13
webserver.js
+10
-13
@@ -4499,15 +4499,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
4499
const nodeid = fields.attrib[0];
4500
obj.GetNodeWithRights(domain, user, nodeid, function (node, rights, visible) {
4501
if ((node == null) || (rights != 0xFFFFFFFF) || (visible == false)) { res.sendStatus(404); return; } // We don't have remote control rights to this device
4502
- for (var i in files.files) {
4503
- var file = files.files[i];
4502
+ files.files.forEach(function (file) {
4503
obj.fs.readFile(file.path, 'utf8', function (err, data) {
4504
if (err != null) return;
4505
data = obj.common.IntToStr(0) + data; // Add the 4 bytes encoding type & flags (Set to 0 for raw)
4506
obj.sendMeshAgentCore(user, domain, fields.attrib[0], 'custom', data); // Upload the core
4507
try { obj.fs.unlinkSync(file.path); } catch (e) { }
4508
});
4510
- }
4509
+ });
4510
res.send('');
4511
});
4512
});
@@ -4542,14 +4541,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
4541
const nodeid = fields.attrib[0];
4542
obj.GetNodeWithRights(domain, user, nodeid, function (node, rights, visible) {
4543
if ((node == null) || (rights != 0xFFFFFFFF) || (visible == false)) { res.sendStatus(404); return; } // We don't have remote control rights to this device
4545
- for (var i in files.files) {
4546
- var file = files.files[i];
4547
-
4544
+ files.files.forEach(function (file) {
4545
// Event Intel AMT One Click Recovery, this will cause Intel AMT wake operations on this and other servers.
4546
parent.DispatchEvent('*', obj, { action: 'oneclickrecovery', userid: user._id, username: user.name, nodeids: [node._id], domain: domain.id, nolog: 1, file: file.path });
4547
4548
//try { obj.fs.unlinkSync(file.path); } catch (e) { } // TODO: Remove this file after 30 minutes.
4552
- }
4549
+ });
4550
res.send('');
4551
});
4552
});
@@ -4617,8 +4614,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
4614
}
4615
} else {
4616
// More typical upload method, the file data is in a multipart mime post.
4620
- for (var i in files.files) {
4621
- var file = files.files[i], fpath = obj.path.join(xfile.fullpath, file.originalFilename);
4617
+ files.files.forEach(function (file) {
4618
+ var fpath = obj.path.join(xfile.fullpath, file.originalFilename);
4619
if (obj.common.IsFilenameValid(file.originalFilename) && ((xfile.quota == null) || ((totalsize + file.size) < xfile.quota))) { // Check if quota would not be broken if we add this file
4620
4621
// See if we need to create the folder
@@ -4646,7 +4643,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
4643
obj.parent.DispatchEvent([user._id], obj, { action: 'notify', title: "Disk quota exceed", value: file.originalFilename, nolog: 1, id: Math.random() });
4644
try { obj.fs.unlink(file.path, function (err) { }); } catch (e) { }
4645
}
4649
- }
4646
+ });
4647
}
4648
} else {
4649
// Send a notification
@@ -4698,8 +4695,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
4695
try { obj.fs.mkdirSync(serverpath); } catch (ex) { }
4696
4697
// More typical upload method, the file data is in a multipart mime post.
4701
- for (var i in files.files) {
4702
- var file = files.files[i], ftarget = getRandomPassword() + '-' + file.originalFilename, fpath = obj.path.join(serverpath, ftarget);
4698
+ files.files.forEach(function (file) {
4699
+ var ftarget = getRandomPassword() + '-' + file.originalFilename, fpath = obj.path.join(serverpath, ftarget);
4700
cmd.files.push({ name: file.originalFilename, target: ftarget });
4701
// Rename the file
4702
obj.fs.rename(file.path, fpath, function (err) {
@@ -4708,7 +4705,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
4705
obj.common.copyFile(file.path, fpath, function (err) { obj.fs.unlink(file.path, function (err) { }); });
4706
}
4707
});
4711
- }
4708
+ });
4709
4710
// Instruct one of more agents to download a URL to a given local drive location.
4711
var tlsCertHash = null;