Explorar el Código

Username support

Jake hace 10 años
padre
commit
f95ce50abc
Se han modificado 4 ficheros con 22 adiciones y 6 borrados
  1. 1 1
      README.md
  2. 15 4
      modules/helpers.js
  3. 4 0
      modules/networking.js
  4. 2 1
      routes/avatars.js

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
-# Crafatar [![travis](https://api.travis-ci.org/Jake0oo0/Spongy.svg)](https://travis-ci.org/Jake0oo0/Spongy/)
+# Crafatar [![travis](https://api.travis-ci.org/Jake0oo0/Crafatar.svg)](https://travis-ci.org/Jake0oo0/Crafatar/)
 
 https://crafatar.com
 

+ 15 - 4
modules/helpers.js

@@ -4,7 +4,7 @@ var cache = require('./cache');
 var skins = require('./skins');
 
 var valid_uuid = /^[0-9a-f]{32}$/;
-var hash_pattern = /[0-9a-f]+$/;
+var hash_pattern = /[A-za-z0-9_-]{1,16}$|((?:[A-za-z][A-za-z]*[0-9]+[A-za-z0-9]*))/;
 
 function get_hash(url) {
   return hash_pattern.exec(url)[0].toLowerCase();
@@ -22,7 +22,15 @@ function store_images(uuid, details, callback) {
     } else if (err) {
       callback(err, null);
     } else {
-      var skinurl = skin_url(profile);
+      var skinurl = null;
+
+      // Username handling
+      if (uuid.length <= 16) {
+        skinurl = "https://skins.minecraft.net/MinecraftSkins/" + uuid + ".png"
+        console.log('is username')
+      } else {
+        skinurl = skin_url(profile);
+      }
       if (skinurl) {
         console.log(uuid + " " + skinurl);
         // set file paths
@@ -107,7 +115,11 @@ var exp = {};
 // returns true if the +uuid+ is a valid uuid
 // the uuid may be not exist, however
 exp.uuid_valid = function(uuid) {
-  return valid_uuid.test(uuid);
+  var valid = valid_uuid.test(uuid);
+  if (!valid && uuid.length <= 16) {
+    valid = true;
+  }
+  return valid;
 };
 
 // handles requests for +uuid+ images with +size+
@@ -133,7 +145,6 @@ exp.get_avatar = function(uuid, helm, size, callback) {
       callback(err, status, null);
     }
   });
-
 };
 
 module.exports = exp;

+ 4 - 0
modules/networking.js

@@ -9,6 +9,10 @@ var exp = {};
 // download the Mojang profile for +uuid+
 // callback contains error, profile object
 exp.get_profile = function(uuid, callback) {
+  if (uuid.length <= 16) {
+    callback(null, null);
+    return;
+  }
   request.get({
     url: session_url + uuid,
     timeout: config.http_timeout // ms

+ 2 - 1
routes/avatars.js

@@ -2,6 +2,7 @@ var helpers = require('../modules/helpers');
 var router = require('express').Router();
 var config = require('../modules/config');
 var skins = require('../modules/skins');
+var networking = require('../modules/networking')
 
 /* GET avatar request. */
 router.get('/:uuid.:ext?', function(req, res) {
@@ -10,7 +11,7 @@ router.get('/:uuid.:ext?', function(req, res) {
   var def = req.query.default;
   var helm = req.query.hasOwnProperty('helm');
   var start = new Date();
-
+  
   // Prevent app from crashing/freezing
   if (size < config.min_size || size > config.max_size) {
     // "Unprocessable Entity", valid request, but semantically erroneous: