Pārlūkot izejas kodu

Bugfix Avatare für Benutzer mit diakritischen Zeichen

Alexander Vornam 3 gadi atpakaļ
vecāks
revīzija
57470c5381
2 mainītis faili ar 11 papildinājumiem un 3 dzēšanām
  1. 11 3
      index.js
  2. 0 0
      www/img/ava/Andre.png

+ 11 - 3
index.js

@@ -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;
     }

+ 0 - 0
www/img/ava/André.png → www/img/ava/Andre.png