Chocobozzz/PeerTube

View on GitHub
server/core/controllers/api/videos/source.ts

Summary

Maintainability
C
7 hrs
Test Coverage

Function replaceVideoSourceResumable has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function replaceVideoSourceResumable (req: express.Request, res: express.Response) {
  const videoPhysicalFile = res.locals.updateVideoFileResumable
  const user = res.locals.oauth.token.User

  const videoFile = await buildNewFile({ path: videoPhysicalFile.path, mode: 'web-video', ffprobe: res.locals.ffprobe })
Severity: Major
Found in server/core/controllers/api/videos/source.ts - About 2 hrs to fix

    Function addVideoJobsAfterUpload has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function addVideoJobsAfterUpload (video: MVideoFullLight, videoFile: MVideoFile) {
      const jobs: (CreateJobArgument & CreateJobOptions)[] = [
        {
          type: 'manage-video-torrent' as 'manage-video-torrent',
          payload: {
    Severity: Minor
    Found in server/core/controllers/api/videos/source.ts - About 1 hr to fix

      Function video has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          const video = await sequelizeTypescript.transaction(async transaction => {
            const video = await VideoModel.loadFull(res.locals.videoAll.id, transaction)
      
            oldWebVideoFiles = video.VideoFiles
            oldStreamingPlaylists = video.VideoStreamingPlaylists
      Severity: Minor
      Found in server/core/controllers/api/videos/source.ts - About 1 hr to fix

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

          if (video.state === VideoState.TO_TRANSCODE) {
            jobs.push({
              type: 'transcoding-job-builder' as 'transcoding-job-builder',
              payload: {
                videoUUID: video.uuid,
        Severity: Major
        Found in server/core/controllers/api/videos/source.ts and 1 other location - About 1 hr to fix
        server/core/lib/video-jobs.ts on lines 98..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 68.

        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

        setupUploadResumableRoutes({
          routePath: '/:id/source/replace-resumable',
          router: videoSourceRouter,
        
          uploadInitAfterMiddlewares: [ asyncMiddleware(replaceVideoSourceResumableInitValidator) ],
        Severity: Minor
        Found in server/core/controllers/api/videos/source.ts and 1 other location - About 50 mins to fix
        server/core/controllers/api/users/user-imports.ts on lines 28..36

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

        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