Added mime filter

This commit is contained in:
SillyLossy
2023-03-21 15:10:58 +02:00
parent d6fbe65bbb
commit 624b843f79
3 changed files with 12 additions and 5 deletions

1
package-lock.json generated
View File

@ -14,6 +14,7 @@
"express": "^4.18.2",
"ipaddr.js": "^2.0.1",
"jimp": "^0.22.7",
"mime-types": "^2.1.35",
"multer": "^1.4.5-lts.1",
"node-rest-client": "^3.1.1",
"open": "^8.4.0",

View File

@ -6,6 +6,7 @@
"express": "^4.18.2",
"ipaddr.js": "^2.0.1",
"jimp": "^0.22.7",
"mime-types": "^2.1.35",
"multer": "^1.4.5-lts.1",
"node-rest-client": "^3.1.1",
"open": "^8.4.0",

View File

@ -15,6 +15,7 @@ const PNGtext = require('png-chunk-text');
const jimp = require('jimp');
const path = require('path');
const sanitize = require('sanitize-filename');
const mime = require('mime-types');
const cookieParser = require('cookie-parser');
const crypto = require('crypto');
@ -987,13 +988,17 @@ function getCharacterFile(directories, response, i) { //old need del
response.send(JSON.stringify(characters));
}
}
function getImages(path) {
return fs.readdirSync(path).sort(Intl.Collator().compare);
/* return fs.readdirSync(path).sort(function (a, b) {
return new Date(fs.statSync(path + '/' + a).mtime) - new Date(fs.statSync(path + '/' + b).mtime);
}).reverse(); */
function getImages(path) {
return fs
.readdirSync(path)
.filter(file => {
const type = mime.lookup(file);
return type && type.startsWith('image/');
})
.sort(Intl.Collator().compare);
}
function getKoboldSettingFiles(path) {
return fs.readdirSync(path).sort(function (a, b) {
return new Date(fs.statSync(path + '/' + a).mtime) - new Date(fs.statSync(path + '/' + b).mtime);