From 02988fdc0bdd345bddf89171d258822cab4229d6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Feb 2018 18:40:24 +0100 Subject: Fix remote image fetching --- server/helpers/image-utils.ts | 2 +- server/helpers/requests.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index ba57b5812..0065f4210 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts @@ -3,7 +3,7 @@ import * as sharp from 'sharp' import { unlinkPromise } from './core-utils' async function processImage ( - physicalFile: Express.Multer.File, + physicalFile: { path: string }, destination: string, newSize: { width: number, height: number } ) { diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index eb8a12868..64e3ce663 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -17,11 +17,13 @@ function doRequest ( } function doRequestAndSaveToFile (requestOptions: request.CoreOptions & request.UriOptions, destPath: string) { - return new Bluebird((res, rej) => { + return new Bluebird((res, rej) => { + const file = createWriteStream(destPath) + file.on('finish', () => res()) + request(requestOptions) - .on('response', response => res(response as request.RequestResponse)) .on('error', err => rej(err)) - .pipe(createWriteStream(destPath)) + .pipe(file) }) } -- cgit v1.2.3