Chocobozzz/PeerTube

View on GitHub
server/core/initializers/checker-after-init.ts

Summary

Maintainability
F
3 days
Test Coverage

File checker-after-init.ts has 296 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { uniqify } from '@peertube/peertube-core-utils'
import { getFFmpegVersion } from '@peertube/peertube-ffmpeg'
import { VideoRedundancyConfigFilter } from '@peertube/peertube-models'
import { isProdInstance } from '@peertube/peertube-node-utils'
import config from 'config'
Severity: Minor
Found in server/core/initializers/checker-after-init.ts - About 3 hrs to fix

    Function checkObjectStorageConfig has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    function checkObjectStorageConfig () {
      if (CONFIG.OBJECT_STORAGE.ENABLED !== true) return
    
      if (!CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BUCKET_NAME) {
        throw new Error('videos_bucket should be set when object storage support is enabled.')
    Severity: Minor
    Found in server/core/initializers/checker-after-init.ts - About 2 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 checkObjectStorageConfig has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function checkObjectStorageConfig () {
      if (CONFIG.OBJECT_STORAGE.ENABLED !== true) return
    
      if (!CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BUCKET_NAME) {
        throw new Error('videos_bucket should be set when object storage support is enabled.')
    Severity: Minor
    Found in server/core/initializers/checker-after-init.ts - About 1 hr to fix

      Function checkLocalRedundancyConfig has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkLocalRedundancyConfig () {
        const redundancyVideos = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES
      
        if (isArray(redundancyVideos)) {
          const available = [ 'most-views', 'trending', 'recently-added' ]
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts - About 1 hr 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 checkLiveConfig has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkLiveConfig () {
        if (CONFIG.LIVE.ENABLED === true) {
          if (CONFIG.LIVE.ALLOW_REPLAY === true && CONFIG.TRANSCODING.ENABLED === false) {
            throw new Error('Live allow replay cannot be enabled if transcoding is not enabled.')
          }
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts - About 1 hr 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 checkTranscodingConfig has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkTranscodingConfig () {
        if (CONFIG.TRANSCODING.ENABLED) {
          if (CONFIG.TRANSCODING.WEB_VIDEOS.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) {
            throw new Error('You need to enable at least Web Video transcoding or HLS transcoding.')
          }
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts - About 55 mins 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 checkStorageConfig has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkStorageConfig () {
        // Check storage directory locations
        if (isProdInstance()) {
          const configStorage = config.get<{ [ name: string ]: string }>('storage')
      
      
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts - About 55 mins 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 checkEmailConfig has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkEmailConfig () {
        if (!isEmailEnabled()) {
          if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) {
            throw new Error('SMTP is not configured but you require signup email verification.')
          }
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts - About 35 mins 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 checkRemovedConfigKeys has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      function checkRemovedConfigKeys () {
        // Moved configuration keys
        if (config.has('services.csp-logger')) {
          logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.')
        }
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts - About 25 mins 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 checkFFmpegVersion has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      async function checkFFmpegVersion () {
        const version = await getFFmpegVersion()
        const semvar = parseSemVersion(version)
      
        if (!semvar) {
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts - About 25 mins 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

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

        if (
          CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BUCKET_NAME === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.BUCKET_NAME &&
          CONFIG.OBJECT_STORAGE.WEB_VIDEOS.PREFIX === CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS.PREFIX
        ) {
          if (CONFIG.OBJECT_STORAGE.WEB_VIDEOS.PREFIX === '') {
      Severity: Major
      Found in server/core/initializers/checker-after-init.ts and 1 other location - About 3 hrs to fix
      server/core/initializers/checker-after-init.ts on lines 333..344

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

      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

          if (
            CONFIG.OBJECT_STORAGE.WEB_VIDEOS.BUCKET_NAME === CONFIG.OBJECT_STORAGE.ORIGINAL_VIDEO_FILES.BUCKET_NAME &&
            CONFIG.OBJECT_STORAGE.WEB_VIDEOS.PREFIX === CONFIG.OBJECT_STORAGE.ORIGINAL_VIDEO_FILES.PREFIX
          ) {
            if (CONFIG.OBJECT_STORAGE.WEB_VIDEOS.PREFIX === '') {
      Severity: Major
      Found in server/core/initializers/checker-after-init.ts and 1 other location - About 3 hrs to fix
      server/core/initializers/checker-after-init.ts on lines 313..324

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

      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

        if (CONFIG.BROADCAST_MESSAGE.ENABLED) {
          const currentLevel = CONFIG.BROADCAST_MESSAGE.LEVEL
          const available = [ 'info', 'warning', 'error' ]
      
          if (available.includes(currentLevel) === false) {
      Severity: Major
      Found in server/core/initializers/checker-after-init.ts and 1 other location - About 2 hrs to fix
      server/core/initializers/checker-after-init.ts on lines 162..169

      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

      function checkNSFWPolicyConfig () {
        const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY
      
        const available = [ 'do_not_list', 'blur', 'display' ]
        if (available.includes(defaultNSFWPolicy) === false) {
      Severity: Major
      Found in server/core/initializers/checker-after-init.ts and 1 other location - About 2 hrs to fix
      server/core/initializers/checker-after-init.ts on lines 261..268

      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

          if (CONFIG.TRANSCODING.WEB_VIDEOS.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) {
            throw new Error('You need to enable at least Web Video transcoding or HLS transcoding.')
          }
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts and 1 other location - About 45 mins to fix
      server/core/initializers/checker-after-init.ts on lines 285..287

      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

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

          if (CONFIG.LIVE.RTMP.ENABLED === false && CONFIG.LIVE.RTMPS.ENABLED === false) {
            throw new Error('You must enable at least RTMP or RTMPS')
          }
      Severity: Minor
      Found in server/core/initializers/checker-after-init.ts and 1 other location - About 45 mins to fix
      server/core/initializers/checker-after-init.ts on lines 238..240

      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