aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-16 16:48:17 +0100
committerChocobozzz <me@florianbigard.com>2018-11-16 16:48:17 +0100
commit58d515e32fe1d0133435b3a5e550c6ff24906fff (patch)
treee769b2f29bdb7bb626208f72fc765ba21a54e9ab /server/helpers
parentbabecc3c09cd4ed06fe643a97fff4bcc31c5a9be (diff)
downloadPeerTube-58d515e32fe1d0133435b3a5e550c6ff24906fff.tar.gz
PeerTube-58d515e32fe1d0133435b3a5e550c6ff24906fff.tar.zst
PeerTube-58d515e32fe1d0133435b3a5e550c6ff24906fff.zip
Fix images size when downloading them
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/requests.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 51facc9e0..805930a9f 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -2,6 +2,7 @@ import * as Bluebird from 'bluebird'
2import { createWriteStream } from 'fs-extra' 2import { createWriteStream } from 'fs-extra'
3import * as request from 'request' 3import * as request from 'request'
4import { ACTIVITY_PUB } from '../initializers' 4import { ACTIVITY_PUB } from '../initializers'
5import { processImage } from './image-utils'
5 6
6function doRequest <T> ( 7function doRequest <T> (
7 requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } 8 requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }
@@ -27,9 +28,18 @@ function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.U
27 }) 28 })
28} 29}
29 30
31async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) {
32 const tmpPath = destPath + '.tmp'
33
34 await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath)
35
36 await processImage({ path: tmpPath }, destPath, size)
37}
38
30// --------------------------------------------------------------------------- 39// ---------------------------------------------------------------------------
31 40
32export { 41export {
33 doRequest, 42 doRequest,
34 doRequestAndSaveToFile 43 doRequestAndSaveToFile,
44 downloadImage
35} 45}