Fix remote image fetching
authorChocobozzz <me@florianbigard.com>
Thu, 15 Feb 2018 17:40:24 +0000 (18:40 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 15 Feb 2018 17:40:24 +0000 (18:40 +0100)
server/helpers/image-utils.ts
server/helpers/requests.ts
server/tools/import-youtube.ts
server/tools/upload.ts

index ba57b5812c91f7961b736f46efd05db612f6a628..0065f4210319866683fd931e9b8652276fe2aba4 100644 (file)
@@ -3,7 +3,7 @@ import * as sharp from 'sharp'
 import { unlinkPromise } from './core-utils'
 
 async function processImage (
-  physicalFile: Express.Multer.File,
+  physicalFile: { path: string },
   destination: string,
   newSize: { width: number, height: number }
 ) {
index eb8a12868137802fec658275874ed9e488f74597..64e3ce663b13f8668483296047577f956e171bdb 100644 (file)
@@ -17,11 +17,13 @@ function doRequest (
 }
 
 function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.UriOptions, destPath: string) {
-  return new Bluebird<request.RequestResponse>((res, rej) => {
+  return new Bluebird<void>((res, rej) => {
+    const file = createWriteStream(destPath)
+    file.on('finish', () => res())
+
     request(requestOptions)
-      .on('response', response => res(response as request.RequestResponse))
       .on('error', err => rej(err))
-      .pipe(createWriteStream(destPath))
+      .pipe(file)
   })
 }
 
index 295109cd8d05117dc1f1f7c33851d255c1c2cd79..ab91afbc060a263932bce94d6f6109a966da0679 100644 (file)
@@ -62,7 +62,7 @@ async function run () {
     console.log('Will download and upload %d videos.\n', videos.length)
 
     for (const video of videos) {
-      await processVideo(video, program['languageCode'])
+      await processVideo(video, program['language'])
     }
 
     console.log('I\'m finished!')
@@ -107,7 +107,10 @@ async function uploadVideoOnPeerTube (videoInfo: any, videoPath: string, languag
   const licence = getLicence(videoInfo.license)
   let tags = []
   if (Array.isArray(videoInfo.tags)) {
-    tags = videoInfo.tags.filter(t => t.length < CONSTRAINTS_FIELDS.VIDEOS.TAG.max).slice(0, 5)
+    tags = videoInfo.tags
+      .filter(t => t.length < CONSTRAINTS_FIELDS.VIDEOS.TAG.max)
+      .map(t => t.normalize())
+      .slice(0, 5)
   }
 
   let thumbnailfile
index de8ff8d26fef23c61bcff649818b58d24a6f46fc..97e24dc8851f0693eb83ae7692054cb4ed9d4898 100644 (file)
@@ -20,6 +20,7 @@ program
   .option('-d, --video-description <description>', 'Video description')
   .option('-t, --tags <tags>', 'Video tags', list)
   .option('-b, --thumbnail <thumbnailPath>', 'Thumbnail path')
+  .option('-v, --preview <previewPath>', 'Preview path')
   .option('-f, --file <file>', 'Video absolute file path')
   .parse(process.argv)
 
@@ -74,7 +75,8 @@ async function run () {
     tags: program['tags'],
     commentsEnabled: program['commentsEnabled'],
     fixture: program['file'],
-    thumbnailfile: program['thumbnailPath']
+    thumbnailfile: program['thumbnailPath'],
+    previewfile: program['previewPath']
   }
 
   await uploadVideo(program['url'], accessToken, videoAttributes)