Browse Source

replacing all single quotes with double quotes
Until now it was a big mess with some strings using single quotes and some others double quotes
We were using way more double quotes, so I chose to use them globally

jomo 10 năm trước cách đây
mục cha
commit
332330f68e
15 tập tin đã thay đổi với 111 bổ sung111 xóa
  1. 19 19
      app.js
  2. 1 1
      clean_images.sh
  3. 2 2
      modules/cache.js
  4. 2 2
      modules/config.example.js
  5. 2 2
      modules/config.js
  6. 10 10
      modules/helpers.js
  7. 6 6
      modules/networking.js
  8. 4 4
      modules/skins.js
  9. 20 20
      routes/avatars.js
  10. 5 5
      routes/index.js
  11. 19 19
      routes/skins.js
  12. 5 5
      server.js
  13. 1 1
      test/bulk.sh
  14. 14 14
      test/test.js
  15. 1 1
      views/layout.jade

+ 19 - 19
app.js

@@ -1,33 +1,33 @@
-var express = require('express');
-var path = require('path');
-var logger = require('morgan');
-var cookieParser = require('cookie-parser');
-var bodyParser = require('body-parser');
+var express = require("express");
+var path = require("path");
+var logger = require("morgan");
+var cookieParser = require("cookie-parser");
+var bodyParser = require("body-parser");
 
-var routes = require('./routes/index');
-var avatars = require('./routes/avatars');
-var skins = require('./routes/skins')
+var routes = require("./routes/index");
+var avatars = require("./routes/avatars");
+var skins = require("./routes/skins")
 
 var app = express();
 
 // view engine setup
-app.set('views', path.join(__dirname, 'views'));
-app.set('view engine', 'jade');
+app.set("views", path.join(__dirname, "views"));
+app.set("view engine", "jade");
 
-app.use(logger('dev'));
+app.use(logger("dev"));
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({ extended: false }));
 app.use(cookieParser());
-app.use(express.static(path.join(__dirname, 'public')));
+app.use(express.static(path.join(__dirname, "public")));
 
-app.use('/', routes);
-app.use('/avatars', avatars);
-app.use('/skins', skins)
+app.use("/", routes);
+app.use("/avatars", avatars);
+app.use("/skins", skins)
 
 
 // catch 404 and forward to error handler
 app.use(function(req, res, next) {
-  var err = new Error('Not Found');
+  var err = new Error("Not Found");
   err.status = 404;
   next(err);
 });
@@ -36,10 +36,10 @@ app.use(function(req, res, next) {
 
 // development error handler
 // will print stacktrace
-if (app.get('env') === 'development') {
+if (app.get("env") === "development") {
   app.use(function(err, req, res, next) {
     res.status(err.status || 500);
-    res.render('error', {
+    res.render("error", {
       message: err.message,
       error: err
     });
@@ -50,7 +50,7 @@ if (app.get('env') === 'development') {
 // no stacktraces leaked to user
 app.use(function(err, req, res, next) {
   res.status(err.status || 500);
-  res.render('error', {
+  res.render("error", {
     message: err.message,
     error: {}
   });

+ 1 - 1
clean_images.sh

@@ -9,7 +9,7 @@ amount="50000" # about 20MB
 # max free MB (on /) to trigger deletion
 trigger="50"
 
-available=`df -m / | awk 'NR==2 { print $4 }'` # MB available on /
+available=`df -m / | awk "NR==2 { print $4 }"` # MB available on /
 if [ "$available" -le "$trigger" ]; then
   echo "Deleting old images"
   for file in `ls -1tr "/app/skins/faces" | head -n $amount`; do

+ 2 - 2
modules/cache.js

@@ -1,4 +1,4 @@
-var logging = require('./logging');
+var logging = require("./logging");
 var config = require("./config");
 var redis = null;
 var fs = require("fs");
@@ -43,7 +43,7 @@ function update_file_date(hash) {
           }
         });
       } else {
-        logging.error("Tried to update " + path + " date, but it doesn't exist");
+        logging.error("Tried to update " + path + " date, but it does not exist");
       }
     });
   }

+ 2 - 2
modules/config.example.js

@@ -5,8 +5,8 @@ var config = {
   local_cache_time: 3600,    // seconds until we will check if the image changed. should be > 60 to prevent mojang 429 response
   browser_cache_time: 3600,  // seconds until browser will request image again
   http_timeout: 1000,        // ms until connection to mojang is dropped
-  faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
-  helms_dir: 'skins/helms/', // directory where helms are kept. should have trailing '/'
+  faces_dir: "skins/faces/", // directory where faces are kept. should have trailing "/"
+  helms_dir: "skins/helms/", // directory where helms are kept. should have trailing "/"
   debug_enabled: false       // enables logging.debug
 };
 

+ 2 - 2
modules/config.js

@@ -5,8 +5,8 @@ var config = {
   local_cache_time: 30,      // seconds until we will check if the image changed. should be > 60 to prevent mojang 429 response
   browser_cache_time: 30,    // seconds until browser will request image again
   http_timeout: 3000,        // ms until connection to mojang is dropped
-  faces_dir: 'skins/faces/', // directory where faces are kept. should have trailing '/'
-  helms_dir: 'skins/helms/', // directory where helms are kept. should have trailing '/'
+  faces_dir: "skins/faces/", // directory where faces are kept. should have trailing "/"
+  helms_dir: "skins/helms/", // directory where helms are kept. should have trailing "/"
   debug_enabled: true        // enables logging.debug
 };
 

+ 10 - 10
modules/helpers.js

@@ -1,9 +1,9 @@
-var networking = require('./networking');
-var logging = require('./logging');
-var config = require('./config');
-var cache = require('./cache');
-var skins = require('./skins');
-var fs = require('fs');
+var networking = require("./networking");
+var logging = require("./logging");
+var config = require("./config");
+var cache = require("./cache");
+var skins = require("./skins");
+var fs = require("fs");
 
 // 0098cb60-fa8e-427c-b299-793cbd302c9a
 var valid_uuid = /^([0-9a-f-]{32,36}|[a-zA-Z0-9_]{1,16})$/; // uuid|username
@@ -33,8 +33,8 @@ function store_images(uuid, details, callback) {
         } else {
           // hash has changed
           logging.log(uuid + " new hash: " + hash);
-          var facepath = __dirname + '/../' + config.faces_dir + hash + ".png";
-          var helmpath = __dirname + '/../' + config.helms_dir + hash + ".png";
+          var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
+          var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
 
           if (fs.existsSync(facepath)) {
             logging.log(uuid + " Avatar already exists, not downloading");
@@ -132,8 +132,8 @@ exp.get_avatar = function(uuid, helm, size, callback) {
   logging.log("\nrequest: " + uuid);
   exp.get_image_hash(uuid, function(err, status, hash) {
     if (hash) {
-      var facepath = __dirname + '/../' + config.faces_dir + hash + ".png";
-      var helmpath = __dirname + '/../' + config.helms_dir + hash + ".png";
+      var facepath = __dirname + "/../" + config.faces_dir + hash + ".png";
+      var helmpath = __dirname + "/../" + config.helms_dir + hash + ".png";
       var filepath = facepath;
       if (helm && fs.existsSync(helmpath)) {
         filepath = helmpath;

+ 6 - 6
modules/networking.js

@@ -1,7 +1,7 @@
-var logging = require('./logging');
-var request = require('request');
-var config = require('./config');
-var skins = require('./skins');
+var logging = require("./logging");
+var request = require("request");
+var config = require("./config");
+var skins = require("./skins");
 var fs = require("fs");
 
 var session_url = "https://sessionserver.mojang.com/session/minecraft/profile/";
@@ -13,8 +13,8 @@ function extract_skin_url(profile) {
   var url = null;
   if (profile && profile.properties) {
     profile.properties.forEach(function(prop) {
-      if (prop.name == 'textures') {
-        var json = Buffer(prop.value, 'base64').toString();
+      if (prop.name == "textures") {
+        var json = Buffer(prop.value, "base64").toString();
         var props = JSON.parse(json);
         url = props && props.textures && props.textures.SKIN && props.textures.SKIN.url || null;
       }

+ 4 - 4
modules/skins.js

@@ -1,6 +1,6 @@
-var logging = require('./logging');
-var lwip = require('lwip');
-var fs = require('fs');
+var logging = require("./logging");
+var lwip = require("lwip");
+var fs = require("fs");
 
 var exp = {};
 
@@ -77,7 +77,7 @@ exp.resize_img = function(inname, size, callback) {
     } else {
       image.batch()
       .resize(size, size, "nearest-neighbor") // nearest-neighbor doesn't blur
-      .toBuffer('png', function(err, buffer) {
+      .toBuffer("png", function(err, buffer) {
         callback(null, buffer);
       });
     }

+ 20 - 20
routes/avatars.js

@@ -1,9 +1,9 @@
-var router = require('express').Router();
-var networking = require('../modules/networking');
-var logging = require('../modules/logging');
-var helpers = require('../modules/helpers');
-var config = require('../modules/config');
-var skins = require('../modules/skins');
+var router = require("express").Router();
+var networking = require("../modules/networking");
+var logging = require("../modules/logging");
+var helpers = require("../modules/helpers");
+var config = require("../modules/config");
+var skins = require("../modules/skins");
 
 var human_status = {
   0: "none",
@@ -14,11 +14,11 @@ var human_status = {
 };
 
 /* GET avatar request. */
-router.get('/:uuid.:ext?', function(req, res) {
+router.get("/:uuid.:ext?", function(req, res) {
   var uuid = req.params.uuid;
   var size = req.query.size || config.default_size;
   var def = req.query.default;
-  var helm = req.query.hasOwnProperty('helm');
+  var helm = req.query.hasOwnProperty("helm");
   var start = new Date();
   var etag = null;
 
@@ -43,7 +43,7 @@ router.get('/:uuid.:ext?', function(req, res) {
         logging.error(err);
       }
       etag = hash && hash.substr(0, 32) || "none";
-      var matches = req.get("If-None-Match") == '"' + etag + '"';
+      var matches = req.get("If-None-Match") == "'" + etag + "'";
       if (image) {
         var http_status = 200;
         if (matches) {
@@ -68,11 +68,11 @@ router.get('/:uuid.:ext?', function(req, res) {
   function handle_default(http_status, img_status) {
     if (def && def != "steve" && def != "alex") {
       res.writeHead(301, {
-        'Cache-Control': 'max-age=' + config.browser_cache_time + ', public',
-        'Response-Time': new Date() - start,
-        'X-Storage-Type': human_status[img_status],
-        'Access-Control-Allow-Origin': '*',
-        'Location': def
+        "Cache-Control": "max-age=" + config.browser_cache_time + ", public",
+        "Response-Time": new Date() - start,
+        "X-Storage-Type": human_status[img_status],
+        "Access-Control-Allow-Origin": "*",
+        "Location": def
       });
       res.end();
     } else {
@@ -85,12 +85,12 @@ router.get('/:uuid.:ext?', function(req, res) {
 
   function sendimage(http_status, img_status, image) {
     res.writeHead(http_status, {
-      'Content-Type': 'image/png',
-      'Cache-Control': 'max-age=' + config.browser_cache_time + ', public',
-      'Response-Time': new Date() - start,
-      'X-Storage-Type': human_status[img_status],
-      'Access-Control-Allow-Origin': '*',
-      'Etag': '"' + etag + '"'
+      "Content-Type": "image/png",
+      "Cache-Control": "max-age=" + config.browser_cache_time + ", public",
+      "Response-Time": new Date() - start,
+      "X-Storage-Type": human_status[img_status],
+      "Access-Control-Allow-Origin": "*",
+      "Etag": '"' + etag + '"'
     });
     res.end(http_status == 304 ? null : image);
   }

+ 5 - 5
routes/index.js

@@ -1,11 +1,11 @@
-var express = require('express');
-var config = require('../modules/config');
+var express = require("express");
+var config = require("../modules/config");
 var router = express.Router();
 
 /* GET home page. */
-router.get('/', function(req, res) {
-  res.render('index', {
-    title: 'Crafatar',
+router.get("/", function(req, res) {
+  res.render("index", {
+    title: "Crafatar",
     domain: "https://" + req.headers.host,
     config: config
   });

+ 19 - 19
routes/skins.js

@@ -1,12 +1,12 @@
-var router = require('express').Router();
-var networking = require('../modules/networking');
-var logging = require('../modules/logging');
-var helpers = require('../modules/helpers');
-var config = require('../modules/config');
-var skins = require('../modules/skins');
+var router = require("express").Router();
+var networking = require("../modules/networking");
+var logging = require("../modules/logging");
+var helpers = require("../modules/helpers");
+var config = require("../modules/config");
+var skins = require("../modules/skins");
 
 /* GET skin request. */
-router.get('/:uuid.:ext?', function(req, res) {
+router.get("/:uuid.:ext?", function(req, res) {
   var uuid = req.params.uuid;
   var def = req.query.default;
   var start = new Date();
@@ -27,7 +27,7 @@ router.get('/:uuid.:ext?', function(req, res) {
         logging.error(err);
       }
       etag = hash && hash.substr(0, 32) || "none";
-      var matches = req.get("If-None-Match") == '"' + etag + '"';
+      var matches = req.get("If-None-Match") == "\"" + etag + "\"";
       if (image) {
         var http_status = 200;
         if (matches) {
@@ -52,11 +52,11 @@ router.get('/:uuid.:ext?', function(req, res) {
   function handle_default(http_status) {
     if (def && def != "steve" && def != "alex") {
       res.writeHead(301, {
-        'Cache-Control': 'max-age=' + config.browser_cache_time + ', public',
-        'Response-Time': new Date() - start,
-        'X-Storage-Type': "downloaded",
-        'Access-Control-Allow-Origin': '*',
-        'Location': def
+        "Cache-Control": "max-age=" + config.browser_cache_time + ", public",
+        "Response-Time": new Date() - start,
+        "X-Storage-Type": "downloaded",
+        "Access-Control-Allow-Origin": "*",
+        "Location": def
       });
       res.end();
     } else {
@@ -69,12 +69,12 @@ router.get('/:uuid.:ext?', function(req, res) {
 
   function sendimage(http_status, image) {
     res.writeHead(http_status, {
-      'Content-Type': 'image/png',
-      'Cache-Control': 'max-age=' + config.browser_cache_time + ', public',
-      'Response-Time': new Date() - start,
-      'X-Storage-Type': "downloaded",
-      'Access-Control-Allow-Origin': '*',
-      'Etag': '"' + etag + '"'
+      "Content-Type": "image/png",
+      "Cache-Control": "max-age=" + config.browser_cache_time + ", public",
+      "Response-Time": new Date() - start,
+      "X-Storage-Type": "downloaded",
+      "Access-Control-Allow-Origin": "*",
+      "Etag": "\"" + etag + "\""
     });
     res.end(http_status == 304 ? null : image);
   }

+ 5 - 5
server.js

@@ -1,9 +1,9 @@
 #!/usr/bin/env node
-var debug = require('debug')('crafatar');
-var app = require('./app');
+var debug = require("debug")("crafatar");
+var app = require("./app");
 
-app.set('port', process.env.PORT || 3000);
+app.set("port", process.env.PORT || 3000);
 
-var server = app.listen(app.get('port'), function() {
-  debug('Crafatar server listening on port ' + server.address().port);
+var server = app.listen(app.get("port"), function() {
+  debug("Crafatar server listening on port " + server.address().port);
 });

+ 1 - 1
test/bulk.sh

@@ -7,7 +7,7 @@ fi
 dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 rm -f "$dir/../skins/"*.png || exit 1
 for uuid in `cat "$dir/uuids.txt"`; do
-  uuid=`echo "$uuid" | tr -d '\r'`
+  uuid=`echo "$uuid" | tr -d "\r"`
   size=$(( ((RANDOM<<15)|RANDOM) % 514 - 1 )) # random number from -1 to 513
   helm=""
   if [ "$(( ((RANDOM<<15)|RANDOM) % 2 ))" -eq "1" ]; then

+ 14 - 14
test/test.js

@@ -1,11 +1,11 @@
-var assert = require('assert');
-var fs = require('fs');
+var assert = require("assert");
+var fs = require("fs");
 
-var networking = require('../modules/networking');
-var helpers = require('../modules/helpers');
-var logging = require('../modules/logging');
-var config = require('../modules/config');
-var skins = require('../modules/skins');
+var networking = require("../modules/networking");
+var helpers = require("../modules/helpers");
+var logging = require("../modules/logging");
+var config = require("../modules/config");
+var skins = require("../modules/skins");
 var cache = require("../modules/cache");
 
 // we don't want tests to fail because of slow internet
@@ -14,15 +14,15 @@ config.http_timeout *= 3;
 // no spam
 logging.log = function(){};
 
-var uuids = fs.readFileSync('test/uuids.txt').toString().split(/\r?\n/);
-var usernames = fs.readFileSync('test/usernames.txt').toString().split(/\r?\n/);
+var uuids = fs.readFileSync("test/uuids.txt").toString().split(/\r?\n/);
+var usernames = fs.readFileSync("test/usernames.txt").toString().split(/\r?\n/);
 // Get a random UUID + username in order to prevent rate limiting
 var uuid = uuids[Math.round(Math.random() * (uuids.length - 1))];
 console.log("using uuid '" + uuid + "'");
 var username = usernames[Math.round(Math.random() * (usernames.length - 1))];
 console.log("using username '" + username + "'");
 
-describe('Crafatar', function() {
+describe("Crafatar", function() {
   // we might have to make 2 HTTP requests
   this.timeout(config.http_timeout * 2 + 50);
 
@@ -30,7 +30,7 @@ describe('Crafatar', function() {
     cache.get_redis().flushall();
   });
 
-  describe('UUID/username', function() {
+  describe("UUID/username", function() {
     it("should be an invalid uuid", function(done) {
       assert.strictEqual(helpers.uuid_valid("g098cb60fa8e427cb299793cbd302c9a"), false);
       done();
@@ -81,7 +81,7 @@ describe('Crafatar', function() {
     });
   });
 
-  describe('Networking: Avatar', function() {
+  describe("Networking: Avatar", function() {
     it("should be downloaded (uuid)", function(done) {
       helpers.get_avatar(uuid, false, 160, function(err, status, image) {
         assert.strictEqual(status, 2);
@@ -127,7 +127,7 @@ describe('Crafatar', function() {
       });
     });
     it("should not exist (but account does)", function(done) {
-      // profile 'Alex'
+      // profile "Alex"
       helpers.get_avatar("ec561538f3fd461daff5086b22154bce", false, 160, function(err, status, image) {
         assert.strictEqual(status, 2);
         done();
@@ -143,7 +143,7 @@ describe('Crafatar', function() {
     });
   });
 
-  describe('Errors', function() {
+  describe("Errors", function() {
     before(function() {
       cache.get_redis().flushall();
     });

+ 1 - 1
views/layout.jade

@@ -4,7 +4,7 @@ html
     title= title
     link(rel="icon", sizes="16x16", type="image/png", href="/favicon.png")
     link(href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.0/css/bootstrap.min.css", rel="stylesheet")
-    link(rel='stylesheet', href='/stylesheets/style.css')
+    link(rel="stylesheet", href="/stylesheets/style.css")
     meta(name="description", content="A Minecraft avatar service with UUID support")
     meta(name="keywords", content="minecraft, avatar, uuid")
     meta(name="viewport", content="initial-scale=1,maximum-scale=1")