X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Frequests.ts;h=5c6dc5e195638d997cc5acbb92dc72ac614fda99;hb=4e553a41fdc67c4da186502522ac99a5ba230453;hp=5760ad1c1854dc617f164b00aa68fbd8dd5a9fe4;hpb=745778256ced65415b04a9817fc49db70d4b6681;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 5760ad1c1..5c6dc5e19 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -1,13 +1,13 @@ import * as Bluebird from 'bluebird' import { createWriteStream } from 'fs-extra' import * as request from 'request' -import { ACTIVITY_PUB } from '../initializers' +import { ACTIVITY_PUB, CONFIG } from '../initializers' import { processImage } from './image-utils' -import { extname } from 'path' +import { join } from 'path' function doRequest ( requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean } -): Bluebird<{ response: request.RequestResponse, body: any }> { +): Bluebird<{ response: request.RequestResponse, body: T }> { if (requestOptions.activityPub === true) { if (!Array.isArray(requestOptions.headers)) requestOptions.headers = {} requestOptions.headers['accept'] = ACTIVITY_PUB.ACCEPT_HEADER @@ -29,10 +29,11 @@ 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) +async function downloadImage (url: string, destDir: string, destName: string, size: { width: number, height: number }) { + const tmpPath = join(CONFIG.STORAGE.TMP_DIR, 'pending-' + destName) await doRequestAndSaveToFile({ method: 'GET', uri: url }, tmpPath) + const destPath = join(destDir, destName) await processImage({ path: tmpPath }, destPath, size) }