|
@@ -60,13 +60,21 @@ fs.readFile("config/config.json", "utf8", (err, data) => {
|
|
|
app.use(express.static(__dirname + '/www'));
|
|
|
app.use('/node_modules', express.static(__dirname + '/node_modules'));
|
|
|
app.get('/img/ava/:username', (req, res) => {
|
|
|
+ let username = req.params.username; //.toLowerCase();
|
|
|
+ username = username.normalize('NFD');
|
|
|
+ username = username.replace(/[\u0300-\u036f]/g, '');
|
|
|
+ username = username.replace(/ß/g, 'ss');
|
|
|
+ username = username.replace(/[^\x00-\x7F]/g, '');
|
|
|
+
|
|
|
+ const filePath = __dirname + '/www/img/ava/' + username + '.png';
|
|
|
+
|
|
|
var file = '';
|
|
|
- if (fs.existsSync(__dirname + '/www/img/ava/' + req.params.username + '.png')) {
|
|
|
- file = __dirname + '/www/img/ava/' + req.params.username + '.png';
|
|
|
+ if (fs.existsSync(filePath)) {
|
|
|
+ file = filePath;
|
|
|
} else {
|
|
|
const files = fs.readdirSync(__dirname + '/www/img/ava/random/').filter((f) => f.toLowerCase().endsWith('.png'));
|
|
|
|
|
|
- const seededRandom = seedrandom(req.params.username)();
|
|
|
+ const seededRandom = seedrandom(username)();
|
|
|
const randomFile = files[Math.floor(seededRandom * files.length)];
|
|
|
file = __dirname + '/www/img/ava/random/' + randomFile;
|
|
|
}
|