فهرست منبع

update to node 12

jomo 5 سال پیش
والد
کامیت
168457dfd9
7فایلهای تغییر یافته به همراه505 افزوده شده و 413 حذف شده
  1. 1 1
      lib/networking.js
  2. 9 14
      lib/renders.js
  3. 1 1
      lib/routes/skins.js
  4. 1 1
      lib/skins.js
  5. 467 370
      package-lock.json
  6. 11 11
      package.json
  7. 15 15
      test/test.js

+ 1 - 1
lib/networking.js

@@ -91,7 +91,7 @@ exp.get_uuid_info = function(profile, type, callback) {
   var properties = Object.get(profile, "properties") || [];
   properties.forEach(function(prop) {
     if (prop.name === "textures") {
-      var json = new Buffer(prop.value, "base64").toString();
+      var json = new Buffer.from(prop.value, "base64").toString();
       profile = JSON.parse(json);
     }
   });

+ 9 - 14
lib/renders.js

@@ -4,8 +4,7 @@
 
 var logging = require("./logging");
 var fs = require("fs");
-var Canvas = require("canvas");
-var Image = Canvas.Image;
+var cvs = require("canvas");
 var exp = {};
 
 // set alpha values to 255
@@ -43,7 +42,7 @@ function hasTransparency(canvas) {
 // resize the +src+ canvas by +scale+
 // returns a new canvas
 function resize(src, scale) {
-  var dst = new Canvas();
+  var dst = cvs.createCanvas();
   dst.width = scale * src.width;
   dst.height = scale * src.height;
   var context = dst.getContext("2d");
@@ -58,7 +57,7 @@ function resize(src, scale) {
 // get a rectangular part of the +src+ canvas
 // the returned canvas is scaled by factor +scale+
 function getPart(src, x, y, width, height, scale) {
-  var dst = new Canvas();
+  var dst = cvs.createCanvas();
   dst.width = scale * width;
   dst.height = scale * height;
   var context = dst.getContext("2d");
@@ -72,7 +71,7 @@ function getPart(src, x, y, width, height, scale) {
 
 // flip the +src+ canvas horizontally
 function flip(src) {
-  var dst = new Canvas();
+  var dst = cvs.createCanvas();
   dst.width = src.width;
   dst.height = src.height;
   var context = dst.getContext("2d");
@@ -91,14 +90,12 @@ var skew_b = skew_a * 2; // 1.15555555
 // +slim+ - wether the player has a slim skin model
 // callback: error, image buffer
 exp.draw_model = function(rid, img, scale, overlay, is_body, slim, callback) {
-  var canvas = new Canvas();
+  var canvas = cvs.createCanvas();
   canvas.width = scale * 20;
   canvas.height = scale * (is_body ? 45.1 : 18.5);
 
   var ctx = canvas.getContext("2d");
-  var skin = new Image();
-
-  skin.onload = function() {
+  cvs.loadImage(img).then((skin) => {
     var old_skin = skin.height === 32;
     var arm_width = slim ? 3 : 4;
 
@@ -182,7 +179,7 @@ exp.draw_model = function(rid, img, scale, overlay, is_body, slim, callback) {
 
     if (is_body) {
       // pre-render front onto separate canvas
-      var front = new Canvas();
+      var front = cvs.createCanvas();
       front.width = scale * 16;
       front.height = scale * 24;
       var frontc = front.getContext("2d");
@@ -243,7 +240,7 @@ exp.draw_model = function(rid, img, scale, overlay, is_body, slim, callback) {
     y = 0;
     z = z_offset;
     ctx.setTransform(1, skew_a, 0, skew_b, 0, 0);
-    ctx.drawImage(head_right, x + y, z - y - 0.5, head_right.width, head_right.height + 1);
+    ctx.drawImage(head_right, x + y, z - y - 0.5, head_right.width + 0.5, head_right.height + 1);
 
     canvas.toBuffer(function(err, buf) {
       if (err) {
@@ -251,9 +248,7 @@ exp.draw_model = function(rid, img, scale, overlay, is_body, slim, callback) {
       }
       callback(err, buf);
     });
-  };
-
-  skin.src = img;
+  });
 };
 
 // helper method to open a render from +renderpath+

+ 1 - 1
lib/routes/skins.js

@@ -2,7 +2,7 @@ var helpers = require("../helpers");
 var skins = require("../skins");
 var cache = require("../cache");
 var path = require("path");
-var lwip = require("pajk-lwip");
+var lwip = require("@randy.tarampi/lwip");
 var url = require("url");
 
 // handle the appropriate 'default=' response

+ 1 - 1
lib/skins.js

@@ -1,5 +1,5 @@
 var logging = require("./logging");
-var lwip = require("pajk-lwip");
+var lwip = require("@randy.tarampi/lwip");
 var fs = require("fs");
 
 var exp = {};

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 467 - 370
package-lock.json


+ 11 - 11
package.json

@@ -1,6 +1,6 @@
 {
   "name": "crafatar",
-  "version": "2.0.0",
+  "version": "2.0.1",
   "private": true,
   "description": "A blazing fast API for Minecraft faces!",
   "contributors": [
@@ -31,23 +31,23 @@
     "test-travis": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
   },
   "engines": {
-    "node": "8.9.4"
+    "node": "10.19.0"
   },
   "dependencies": {
-    "canvas": "^1.6.2",
-    "crc": "^3.5.0",
-    "ejs": "^2.5.2",
-    "pajk-lwip": "^0.2.0",
-    "mime": "^2.2.0",
+    "canvas": "^2.6.1",
+    "crc": "^3.8.0",
+    "ejs": "^3.0.1",
+    "@randy.tarampi/lwip": "^1.1.0",
+    "mime": "^2.4.4",
     "node-df": "crafatar/node-df",
-    "redis": "^2.8.0",
-    "request": "^2.83.0",
+    "redis": "^3.0.2",
+    "request": "^2.88.2",
     "toobusy-js": "^0.5.1"
   },
   "devDependencies": {
-    "coveralls": "^3.0.0",
+    "coveralls": "^3.0.11",
     "istanbul": "^0.4.5",
-    "mocha": "^5.0.1",
+    "mocha": "^7.1.1",
     "mocha-lcov-reporter": "^1.3.0"
   }
 }

+ 15 - 15
test/test.js

@@ -204,7 +204,7 @@ describe("Crafatar", function() {
         },
       }, function(error, res, body) {
         assert.ifError(error);
-        assert.ifError(body);
+        assert.strictEqual(body, '');
         assert.equal(res.statusCode, 304);
         assert_headers(res);
         callback();
@@ -346,7 +346,7 @@ describe("Crafatar", function() {
         redirect: "http://example.com/CaseSensitive",
       },
       "cape with existing uuid": {
-        url: "http://localhost:3000/capes/069a79f444e94726a5befca90e38aaf5",
+        url: "http://localhost:3000/capes/853c80ef3c3749fdaa49938b674adae6",
         crc32: [2556702429],
       },
       "cape with non-existent uuid": {
@@ -382,15 +382,15 @@ describe("Crafatar", function() {
       },
       "head render with existing uuid": {
         url: "http://localhost:3000/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2",
-        crc32: [3487896679, 3001090792],
+        crc32: [1168786201],
       },
       "head render with non-existent uuid": {
         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2",
-        crc32: [3257141069, 214248305],
+        crc32: [3800926063],
       },
       "head render with non-existent uuid defaulting to mhf_alex": {
         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&default=mhf_alex",
-        crc32: [263450586, 3116770561],
+        crc32: [4027858557],
       },
       "head render with non-existent uuid defaulting to uuid": {
         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&default=853c80ef3c3749fdaa49938b674adae6",
@@ -404,15 +404,15 @@ describe("Crafatar", function() {
       },
       "overlay head render with existing uuid": {
         url: "http://localhost:3000/renders/head/853c80ef3c3749fdaa49938b674adae6?scale=2&overlay",
-        crc32: [762377383, 1726474987],
+        crc32: [2880579826],
       },
       "overlay head render with non-existent uuid": {
         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&overlay",
-        crc32: [3257141069, 214248305],
+        crc32: [3800926063],
       },
       "overlay head render with non-existent uuid defaulting to mhf_alex": {
         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&overlay&default=mhf_alex",
-        crc32: [263450586, 3116770561],
+        crc32: [4027858557],
       },
       "overlay head with non-existent uuid defaulting to uuid": {
         url: "http://localhost:3000/renders/head/00000000000000000000000000000000?scale=2&overlay&default=853c80ef3c3749fdaa49938b674adae6",
@@ -426,15 +426,15 @@ describe("Crafatar", function() {
       },
       "body render with existing uuid": {
         url: "http://localhost:3000/renders/body/853c80ef3c3749fdaa49938b674adae6?scale=2",
-        crc32: [3127075871, 2595192206],
+        crc32: [2745192436],
       },
       "body render with non-existent uuid": {
         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2",
-        crc32: [1046655221, 1620063267],
+        crc32: [996962526],
       },
       "body render with non-existent uuid defaulting to mhf_alex": {
         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&default=mhf_alex",
-        crc32: [549240598, 3952648540],
+        crc32: [1255106465],
       },
       "body render with non-existent uuid defaulting to uuid": {
         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&default=853c80ef3c3749fdaa49938b674adae6",
@@ -448,15 +448,15 @@ describe("Crafatar", function() {
       },
       "overlay body render with existing uuid": {
         url: "http://localhost:3000/renders/body/853c80ef3c3749fdaa49938b674adae6?scale=2&overlay",
-        crc32: [699892097, 2732138694],
+        crc32: [2441671793],
       },
       "overlay body render with non-existent uuid": {
         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&overlay",
-        crc32: [1046655221, 1620063267],
+        crc32: [996962526],
       },
       "overlay body render with non-existent uuid defaulting to mhf_alex": {
         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&overlay&default=mhf_alex",
-        crc32: [549240598, 3952648540],
+        crc32: [1255106465],
       },
       "overlay body render with non-existent uuid defaulting to url": {
         url: "http://localhost:3000/renders/body/00000000000000000000000000000000?scale=2&overlay&default=http%3A%2F%2Fexample.com%2FCaseSensitive",
@@ -513,7 +513,7 @@ describe("Crafatar", function() {
       config.server.http_timeout = 1;
       request.get({url: "http://localhost:3000/avatars/0000000000000000000000000000000f", headers: {"If-None-Match": '"some-etag"'}}, function(error, res, body) {
         assert.ifError(error);
-        assert.ifError(body);
+        assert.strictEqual(body, '');
         assert.strictEqual(res.statusCode, 304);
         config.server.debug_enabled = original_debug;
         config.server.http_timeout = original_timeout;

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است