Skip to content

Node.js based forum software built for the modern web

implement proper file sorting by mtime in ACP uploads

Julian Lam777d9aeee672
diff --git a/public/language/en-GB/admin/manage/uploads.json b/public/language/en-GB/admin/manage/uploads.json
index 33d9914403..21bc8201fc 100644
--- a/public/language/en-GB/admin/manage/uploads.json
+++ b/public/language/en-GB/admin/manage/uploads.json
@@ -2,6 +2,7 @@
"upload-file": "Upload File",
"filename": "Filename",
"usage": "Post Usage",
+ "orphaned": "Orphaned",
"size/filecount": "Size / Filecount",
"confirm-delete": "Do you really want to delete this file?",
"filecount": "%1 files"
diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js
index 7a71ccf617..1722be48f6 100644
--- a/src/controllers/admin/uploads.js
+++ b/src/controllers/admin/uploads.js
@@ -43,12 +43,16 @@ uploadsController.get = function (req, res, next) {
filesToData(currentFolder, files, next);
},
function (files, next) {
+ // Float directories to the top
files.sort(function (a, b) {
if (a.isDirectory && !b.isDirectory) {
return -1;
} else if (!a.isDirectory && b.isDirectory) {
return 1;
+ } else if (!a.isDirectory && !b.isDirectory) {
+ return a.mtime < b.mtime ? -1 : 1;
}
+
return 0;
});
@@ -122,6 +126,7 @@ function filesToData(currentDir, files, callback) {
sizeHumanReadable: (stat.size / 1024).toFixed(1) + 'KiB',
isDirectory: stat.isDirectory(),
isFile: stat.isFile(),
+ mtime: stat.mtimeMs,
});
},
], next);