From f55ad19141cf11609a679ea65b5740454fd67b9f Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 2 Aug 2023 10:01:49 +0200 Subject: [PATCH] fix protocol error --- .../src/strapi/providers/local-source/assets.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/data-transfer/src/strapi/providers/local-source/assets.ts b/packages/core/data-transfer/src/strapi/providers/local-source/assets.ts index 4c5992fea8..792183f74b 100644 --- a/packages/core/data-transfer/src/strapi/providers/local-source/assets.ts +++ b/packages/core/data-transfer/src/strapi/providers/local-source/assets.ts @@ -1,10 +1,15 @@ import { join } from 'path'; import https from 'https'; +import http from 'http'; import { Duplex, PassThrough, Readable } from 'stream'; import { stat, createReadStream, ReadStream } from 'fs-extra'; import type { IAsset } from '../../../../types'; +const httpMethod = (filepath) => { + return filepath?.startsWith('https') ? https : http; +}; + function getFileStream(filepath: string, isLocal = false): PassThrough | ReadStream { if (isLocal) { return createReadStream(filepath); @@ -12,7 +17,7 @@ function getFileStream(filepath: string, isLocal = false): PassThrough | ReadStr const readableStream = new PassThrough(); - https + httpMethod(filepath) .get(filepath, (res) => { if (res.statusCode !== 200) { readableStream.emit( @@ -36,7 +41,7 @@ function getFileStats(filepath: string, isLocal = false): Promise<{ size: number return stat(filepath); } return new Promise((resolve, reject) => { - https + httpMethod(filepath) .get(filepath, (res) => { if (res.statusCode !== 200) { reject(new Error(`Request failed with status code ${res.statusCode}`));