diff options
author | buoyantair <buoyantair@protonmail.com> | 2018-11-18 21:55:52 +0530 |
---|---|---|
committer | buoyantair <buoyantair@protonmail.com> | 2018-11-18 21:55:52 +0530 |
commit | b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13 (patch) | |
tree | dcdf451ac431ec7953bee58e814f642d1c370d1b /server/helpers/requests.ts | |
parent | 92e07c3b5d9dbf2febedb1b5b87ec676eb6d1ac8 (diff) | |
parent | 9d0b856e930ee1c676d16a56408a3e4a18f8f978 (diff) | |
download | PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.tar.gz PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.tar.zst PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.zip |
Merge branch 'develop' of https://github.com/Chocobozzz/PeerTube into move-utils-to-shared
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 12 |
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' | |||
2 | import { createWriteStream } from 'fs-extra' | 2 | import { createWriteStream } from 'fs-extra' |
3 | import * as request from 'request' | 3 | import * as request from 'request' |
4 | import { ACTIVITY_PUB } from '../initializers' | 4 | import { ACTIVITY_PUB } from '../initializers' |
5 | import { processImage } from './image-utils' | ||
5 | 6 | ||
6 | function doRequest <T> ( | 7 | function 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 | ||
31 | async 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 | ||
32 | export { | 41 | export { |
33 | doRequest, | 42 | doRequest, |
34 | doRequestAndSaveToFile | 43 | doRequestAndSaveToFile, |
44 | downloadImage | ||
35 | } | 45 | } |