diff --git a/package-lock.json b/package-lock.json index 26a035629..880805c1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index ed8d81d3f..eebd491a1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server.js b/server.js index 258ecdf75..c2c071726 100644 --- a/server.js +++ b/server.js @@ -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);