crafatar/crafatar

View on GitHub

Showing 62 of 62 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

  if (defname !== "steve" && defname !== "mhf_steve" && defname !== "alex" && defname !== "mhf_alex") {
    if (helpers.id_valid(def)) {
      // clean up the old URL to match new image
      req.url.searchParams.delete('default');
      req.url.path_list[2] = def;
Severity: Major
Found in lib/routes/renders.js and 2 other locations - About 6 hrs to fix
lib/routes/avatars.js on lines 14..48
lib/routes/skins.js on lines 14..57

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 158.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

  if (defname !== "steve" && defname !== "mhf_steve" && defname !== "alex" && defname !== "mhf_alex") {
    if (helpers.id_valid(def)) {
      // clean up the old URL to match new image
      req.url.searchParams.delete('default');
      req.url.path_list[1] = def;
Severity: Major
Found in lib/routes/avatars.js and 2 other locations - About 6 hrs to fix
lib/routes/renders.js on lines 17..54
lib/routes/skins.js on lines 14..57

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 158.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

  if (defname !== "steve" && defname !== "mhf_steve" && defname !== "alex" && defname !== "mhf_alex") {
    if (helpers.id_valid(def)) {
      // clean up the old URL to match new image
      req.url.searchParams.delete('default');
      req.url.path_list[1] = def;
Severity: Major
Found in lib/routes/skins.js and 2 other locations - About 6 hrs to fix
lib/routes/avatars.js on lines 14..48
lib/routes/renders.js on lines 17..54

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 158.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function exports has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function(request, response, result) {
  // These headers are the same for every response
  var headers = {
    "Content-Type": result.body && result.type || "text/plain",
    "Content-Length": Buffer.from(result.body || "").length,
Severity: Minor
Found in lib/response.js - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function draw_model has 111 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exp.draw_model = function(rid, img, scale, overlay, is_body, slim, callback) {
  var canvas = cvs.createCanvas();
  canvas.width = scale * 20;
  canvas.height = scale * (is_body ? 45.1 : 18.5);

Severity: Major
Found in lib/renders.js - About 4 hrs to fix

    File helpers.js has 323 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var networking = require("./networking");
    var logging = require("./logging");
    var renders = require("./renders");
    var config = require("../config");
    var cache = require("./cache");
    Severity: Minor
    Found in lib/helpers.js - About 3 hrs to fix

      Function get_image_hash has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

      exp.get_image_hash = function(rid, userId, type, callback) {
        cache.get_details(userId, function(err, cache_details) {
          var cached_hash = null;
          if (cache_details !== null) {
            cached_hash = type === "skin" ? cache_details.skin : cache_details.cape;
      Severity: Minor
      Found in lib/helpers.js - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function extract_helm has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exp.extract_helm = function(rid, facefile, buffer, outname, callback) {
        lwip.open(buffer, "png", function(err, skin_img) {
          if (err) {
            callback(err);
          } else {
      Severity: Major
      Found in lib/skins.js - About 2 hrs to fix

        Function exports has 69 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports = function(request, response, result) {
          // These headers are the same for every response
          var headers = {
            "Content-Type": result.body && result.type || "text/plain",
            "Content-Length": Buffer.from(result.body || "").length,
        Severity: Major
        Found in lib/response.js - About 2 hrs to fix

          Function requestHandler has 65 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function requestHandler(req, res) {
            req.url = new URL(decodeURI(req.url), 'http://' + req.headers.host);
            req.url.pathname = path.resolve('/', req.url.pathname);
            req.url.path_list = path_list(req.url.pathname);
            req.id = request_id();
          Severity: Major
          Found in lib/server.js - About 2 hrs to fix

            Function get_from_options has 59 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            exp.get_from_options = function(rid, url, options, callback) {
              var is_session_req = config.server.sessions_rate_limit && url.startsWith(session_url);
            
              // This is to prevent being blocked by CloudFront for exceeding the rate limit
              if (is_session_req && req_count() >= config.server.sessions_rate_limit) {
            Severity: Major
            Found in lib/networking.js - About 2 hrs to fix

              Function exports has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              module.exports = function(req, callback) {
                var raw_type = req.url.path_list[1] || "";
                var rid = req.id;
                var body = raw_type === "body";
                var userId = (req.url.path_list[2] || "").split(".")[0];
              Severity: Major
              Found in lib/routes/renders.js - About 2 hrs to fix

                Consider simplifying this complex logical expression.
                Open

                  if (is_session_req && req_count() >= config.server.sessions_rate_limit) {
                    var e = new Error("Skipped, rate limit exceeded");
                    e.name = "HTTP";
                    e.code = "RATELIMIT";
                
                
                Severity: Critical
                Found in lib/networking.js - About 2 hrs to fix

                  Function store_skin has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function store_skin(rid, userId, profile, cache_details, callback) {
                    networking.get_skin_info(rid, userId, profile, function(err, url, slim) {
                      if (err) {
                        slim = cache_details ? cache_details.slim : undefined;
                      }
                  Severity: Major
                  Found in lib/helpers.js - About 2 hrs to fix

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                      renders: {
                        // for 3D rendered skins
                        min_scale: parseInt(process.env.RENDER_MIN) || 1,
                        // for 3D rendered skins; large values might lead to slow response time or DoS
                        max_scale: parseInt(process.env.RENDER_MAX) || 10,
                    Severity: Major
                    Found in config.js and 1 other location - About 2 hrs to fix
                    config.js on lines 2..9

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 75.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                      avatars: {
                        // for avatars
                        min_size: parseInt(process.env.AVATAR_MIN) || 1,
                        // for avatars; large values might lead to slow response time or DoS
                        max_size: parseInt(process.env.AVATAR_MAX) || 512,
                    Severity: Major
                    Found in config.js and 1 other location - About 2 hrs to fix
                    config.js on lines 10..17

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 75.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Function exports has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    module.exports = function(req, callback) {
                      var userId = (req.url.path_list[1] || "").split(".")[0];
                      var size = parseInt(req.url.searchParams.get("size")) || config.avatars.default_size;
                      var def = req.url.searchParams.get("default");
                      var overlay = req.url.searchParams.has("overlay") || req.url.searchParams.has("helm");
                    Severity: Minor
                    Found in lib/routes/avatars.js - About 1 hr to fix

                      Function handle_default has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function handle_default(img_status, userId, def, req, err, callback) {
                        def = def || skins.default_skin(userId);
                        var defname = def.toLowerCase();
                        if (defname !== "steve" && defname !== "mhf_steve" && defname !== "alex" && defname !== "mhf_alex") {
                          if (helpers.id_valid(def)) {
                      Severity: Minor
                      Found in lib/routes/skins.js - About 1 hr to fix

                        Function exports has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        module.exports = function(req, callback) {
                          var userId = (req.url.path_list[1] || "").split(".")[0];
                          var def = req.url.searchParams.get("default");
                          var rid = req.id;
                        
                        
                        Severity: Minor
                        Found in lib/routes/skins.js - About 1 hr to fix

                          Function exports has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          module.exports = function(req, callback) {
                            var userId = (req.url.path_list[1] || "").split(".")[0];
                            var def = req.url.searchParams.get('default');
                            var rid = req.id;
                          
                          
                          Severity: Minor
                          Found in lib/routes/capes.js - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language