]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/requests.ts
Fix thumbnail processing
[github/Chocobozzz/PeerTube.git] / server / helpers / requests.ts
index 51facc9e03a7c44e63a34332115c3c500a6fb994..5760ad1c1854dc617f164b00aa68fbd8dd5a9fe4 100644 (file)
@@ -2,6 +2,8 @@ import * as Bluebird from 'bluebird'
 import { createWriteStream } from 'fs-extra'
 import * as request from 'request'
 import { ACTIVITY_PUB } from '../initializers'
+import { processImage } from './image-utils'
+import { extname } from 'path'
 
 function doRequest <T> (
   requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }
@@ -27,9 +29,17 @@ function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.U
   })
 }
 
+async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) {
+  const tmpPath = destPath + '.tmp' + extname(destPath)
+  await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath)
+
+  await processImage({ path: tmpPath }, destPath, size)
+}
+
 // ---------------------------------------------------------------------------
 
 export {
   doRequest,
-  doRequestAndSaveToFile
+  doRequestAndSaveToFile,
+  downloadImage
 }