diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-04 16:02:49 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-04 16:04:15 +0100 |
commit | 6040f87d143a5fa01db79867ece8197c3ce7be47 (patch) | |
tree | 98e5fcbced3e55df2f51421250eaa57f3c511299 /server/helpers/requests.ts | |
parent | 745778256ced65415b04a9817fc49db70d4b6681 (diff) | |
download | PeerTube-6040f87d143a5fa01db79867ece8197c3ce7be47.tar.gz PeerTube-6040f87d143a5fa01db79867ece8197c3ce7be47.tar.zst PeerTube-6040f87d143a5fa01db79867ece8197c3ce7be47.zip |
Add tmp and redundancy directories
Diffstat (limited to 'server/helpers/requests.ts')
-rw-r--r-- | server/helpers/requests.ts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 5760ad1c1..3fc776f1a 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | 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, CONFIG } from '../initializers' |
5 | import { processImage } from './image-utils' | 5 | import { processImage } from './image-utils' |
6 | import { extname } from 'path' | 6 | import { join } from 'path' |
7 | 7 | ||
8 | function doRequest <T> ( | 8 | function doRequest <T> ( |
9 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } | 9 | requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } |
@@ -29,10 +29,11 @@ function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.U | |||
29 | }) | 29 | }) |
30 | } | 30 | } |
31 | 31 | ||
32 | async function downloadImage (url: string, destPath: string, size: { width: number, height: number }) { | 32 | async function downloadImage (url: string, destDir: string, destName: string, size: { width: number, height: number }) { |
33 | const tmpPath = destPath + '.tmp' + extname(destPath) | 33 | const tmpPath = join(CONFIG.STORAGE.TMP_DIR, 'pending-' + destName) |
34 | await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath) | 34 | await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath) |
35 | 35 | ||
36 | const destPath = join(destDir, destName) | ||
36 | await processImage({ path: tmpPath }, destPath, size) | 37 | await processImage({ path: tmpPath }, destPath, size) |
37 | } | 38 | } |
38 | 39 | ||