]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix import with when the imported file has the same extension than an
authorChocobozzz <me@florianbigard.com>
Mon, 11 Jun 2018 17:16:00 +0000 (19:16 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 11 Jun 2018 17:16:00 +0000 (19:16 +0200)
already existing file

server/controllers/services.ts
server/models/video/video.ts
server/tests/cli/create-import-video-file-job.ts

index 1f82db9c40a7a7c6a71ddee1978251f391eb2b09..1dd8e28e5e1c64d39f6e5899c59ed52d57cdbf6a 100644 (file)
@@ -45,7 +45,8 @@ function generateOEmbed (req: express.Request, res: express.Response, next: expr
     thumbnailUrl = undefined
   }
 
-  const html = `<iframe width="${embedWidth}" height="${embedHeight}" sandbox="allow-same-origin allow-scripts" src="${embedUrl}" frameborder="0" allowfullscreen></iframe>`
+  const html = `<iframe width="${embedWidth}" height="${embedHeight}" sandbox="allow-same-origin allow-scripts" ` +
+    `src="${embedUrl}" frameborder="0" allowfullscreen></iframe>`
 
   const json: any = {
     type: 'video',
index faa6f3f9b5922f2cdc3c07e976c41a22b681b3f5..1cb1e6798407b9098fb1a17a8f778b9867a0e563 100644 (file)
@@ -1325,9 +1325,6 @@ export class VideoModel extends Model<VideoModel> {
       videoId: this.id
     })
 
-    const outputPath = this.getVideoFilePath(updatedVideoFile)
-    await copyFilePromise(inputFilePath, outputPath)
-
     const currentVideoFile = this.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
 
     if (currentVideoFile) {
@@ -1344,6 +1341,9 @@ export class VideoModel extends Model<VideoModel> {
       updatedVideoFile = currentVideoFile
     }
 
+    const outputPath = this.getVideoFilePath(updatedVideoFile)
+    await copyFilePromise(inputFilePath, outputPath)
+
     await this.createTorrentAndSetInfoHash(updatedVideoFile)
 
     await updatedVideoFile.save()
index 372c7e51751a8c23ebc3e4951c5486116a0bacec..1472e60f6fb5630910f54ea827b500c825ae1b7a 100644 (file)
@@ -73,22 +73,22 @@ describe('Test create import video jobs', function () {
 
       expect(videoDetail.files).to.have.lengthOf(2)
       const [originalVideo, transcodedVideo] = videoDetail.files
-      assertVideoProperties(originalVideo, 720, 'webm')
-      assertVideoProperties(transcodedVideo, 480, 'webm')
+      assertVideoProperties(originalVideo, 720, 'webm', 218910)
+      assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
 
       if (!magnetUri) magnetUri = transcodedVideo.magnetUri
       else expect(transcodedVideo.magnetUri).to.equal(magnetUri)
     }
   })
 
-  it('Should run a import job on video 2 with the same resolution', async function () {
+  it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
     const env = getEnvCli(servers[1])
     await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`)
 
     await wait(30000)
 
     let magnetUri: string
-    for (const server of servers.reverse()) {
+    for (const server of servers) {
       const { data: videos } = (await getVideosList(server.url)).body
       expect(videos).to.have.lengthOf(2)
 
@@ -107,6 +107,30 @@ describe('Test create import video jobs', function () {
     }
   })
 
+  it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
+    const env = getEnvCli(servers[0])
+    await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`)
+
+    await wait(30000)
+
+    let magnetUri: string
+    for (const server of servers) {
+      const { data: videos } = (await getVideosList(server.url)).body
+      expect(videos).to.have.lengthOf(2)
+
+      const video = videos.find(({ uuid }) => uuid === video1UUID)
+      const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+
+      expect(videoDetail.files).to.have.lengthOf(2)
+      const [ video720, video480 ] = videoDetail.files
+      assertVideoProperties(video720, 720, 'webm', 942961)
+      assertVideoProperties(video480, 480, 'webm', 69217)
+
+      if (!magnetUri) magnetUri = video720.magnetUri
+      else expect(video720.magnetUri).to.equal(magnetUri)
+    }
+  })
+
   after(async function () {
     killallServers(servers)