From 3a4cefa67a43dcf3a79154d87193e2dbdb2c8c3b Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Wed, 24 Apr 2024 13:03:53 +0200 Subject: [PATCH] Optimize portions from directory listing function --- svr.js | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/svr.js b/svr.js index 9f88fce..bc2c380 100644 --- a/svr.js +++ b/svr.js @@ -3860,28 +3860,15 @@ if (!cluster.isPrimary) { fs.stat((prefix + "/" + fileList[index]).replace(/\/+/g, "/"), function (err, stats) { if (err) { fs.lstat((prefix + "/" + fileList[index]).replace(/\/+/g, "/"), function (err, stats) { - if (err) { - pushArray.push({ - name: fileList[index], - stats: null, - errored: true - }); - if (index < fileList.length - 1) { - getStatsForAllFilesI(fileList, callback, prefix, pushArray, index + 1); - } else { - callback(pushArray); - } + pushArray.push({ + name: fileList[index], + stats: err ? null : stats, + errored: true + }); + if (index < fileList.length - 1) { + getStatsForAllFilesI(fileList, callback, prefix, pushArray, index + 1); } else { - pushArray.push({ - name: fileList[index], - stats: stats, - errored: true - }); - if (index < fileList.length - 1) { - getStatsForAllFilesI(fileList, callback, prefix, pushArray, index + 1); - } else { - callback(pushArray); - } + callback(pushArray); } }); } else { @@ -3913,8 +3900,7 @@ if (!cluster.isPrimary) { var estats = filelist[i].stats; var ename = filelist[i].name; var eext = ename.match(/\.([^.]+)$/); - if (eext) eext = eext[1]; - else eext = ""; + eext = eext ? eext[1] : ""; var emime = eext ? mime.contentType(eext) : false; if (filelist[i].errored) { directoryListingRows.push(