pinclub/pinclub

View on GitHub
api/v2/image.js

Summary

Maintainability
F
3 days
Test Coverage

File image.js has 338 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var _ = require('lodash');
var TopicProxy = require('../../proxy').Topic;
var TopicLike = require('../../proxy').TopicLike;
var TopicBoard = require('../../proxy').TopicBoard;
var BoardProxy = require('../../proxy').Board;
Severity: Minor
Found in api/v2/image.js - About 4 hrs to fix

    Function getImage has 85 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.getImage = function (req, res, next) {
        req.checkBody({
            'topic_id': {
                notEmpty: {
                    options: [true],
    Severity: Major
    Found in api/v2/image.js - About 3 hrs to fix

      Function like has 70 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.like = function (req, res, next) {
          if (!req.body.id) {
              return res.status(500).send({success: false, error_msg: "必要参数id未传."});
          }
      
      
      Severity: Major
      Found in api/v2/image.js - About 2 hrs to fix

        Function show has 66 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        exports.show = function (req, res, next) {
            var topicId = String(req.params.id);
        
            var mdrender = req.query.mdrender === 'false' ? false : true;
            var ep = new EventProxy();
        Severity: Major
        Found in api/v2/image.js - About 2 hrs to fix

          Function index has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          exports.index = function (req, res, next) {
              var type = 'image';
              var page = parseInt(req.query.page, 10) || 1;
              page = page > 0 ? page : 1;
          
          
          Severity: Major
          Found in api/v2/image.js - About 2 hrs to fix

            Function sim has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            exports.sim = function (req, res, next) {
                var limit = parseInt(req.query.limit, 10) || 3;
                if (!req.query.id) {
                    return res.status(500).send({success: false, error_msg: "必要参数id未传."});
                }
            Severity: Minor
            Found in api/v2/image.js - About 1 hr to fix

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

              exports.delete = function(req, res, next) {
                  var topicId = String(req.params.id);
                  TopicProxy.remove(topicId, function (err, result) {
                      if (err) {
                          return next(err);
              Severity: Major
              Found in api/v2/image.js and 1 other location - About 2 hrs to fix
              api/v2/board.js on lines 344..352

              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 90.

              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

                          UserProxy.getUserById(currentUser.id, function (err, user) {
                              if (err) {
                                  return next(err);
                              }
                              user.like_image_count -= 1;
              Severity: Major
              Found in api/v2/image.js and 1 other location - About 2 hrs to fix
              api/v2/image.js on lines 244..251

              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 77.

              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

                      UserProxy.getUserById(currentUser.id, function (err, user) {
                          if (err) {
                              return next(err);
                          }
                          user.like_image_count += 1;
              Severity: Major
              Found in api/v2/image.js and 1 other location - About 2 hrs to fix
              api/v2/image.js on lines 269..276

              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 77.

              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 4 locations. Consider refactoring.
              Open

                  req.checkBody({
                      'topic_id': {
                          notEmpty: {
                              options: [true],
                              errorMessage: 'topic_id 不能为空'
              Severity: Major
              Found in api/v2/image.js and 3 other locations - About 1 hr to fix
              api/v2/auth.js on lines 160..173
              controllers/node.js on lines 6..19
              controllers/sign.js on lines 193..206

              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 60.

              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

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

                          liked_t_ids.forEach(function(lti){
                              let tid = lti.toString();
                              if (topic.id === tid) {
                                  structedTopic.liked = true;
                              }
              Severity: Major
              Found in api/v2/image.js and 1 other location - About 1 hr to fix
              api/v2/topic.js on lines 103..108

              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 57.

              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 10 locations. Consider refactoring.
              Open

                  if (!validator.isMongoId(topicId)) {
                      res.status(400);
                      return res.send({success: false, error_msg: '不是有效的话题id'});
                  }
              Severity: Major
              Found in api/v2/image.js and 9 other locations - About 45 mins to fix
              api/v1/reply.js on lines 24..27
              api/v1/reply.js on lines 84..87
              api/v1/topic.js on lines 114..117
              api/v1/topic_collect.js on lines 55..58
              api/v1/topic_collect.js on lines 103..106
              api/v2/board.js on lines 63..66
              api/v2/board.js on lines 170..173
              api/v2/board.js on lines 230..233
              api/v2/topic.js on lines 193..196

              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 50.

              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

              There are no issues that match your filters.

              Category
              Status