mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 04:21:17 +01:00
implement proper file sorting by mtime in ACP uploads
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user