mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
fix protocol error
This commit is contained in:
parent
f5107c7236
commit
f55ad19141
@ -1,10 +1,15 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
|
import http from 'http';
|
||||||
import { Duplex, PassThrough, Readable } from 'stream';
|
import { Duplex, PassThrough, Readable } from 'stream';
|
||||||
import { stat, createReadStream, ReadStream } from 'fs-extra';
|
import { stat, createReadStream, ReadStream } from 'fs-extra';
|
||||||
|
|
||||||
import type { IAsset } from '../../../../types';
|
import type { IAsset } from '../../../../types';
|
||||||
|
|
||||||
|
const httpMethod = (filepath) => {
|
||||||
|
return filepath?.startsWith('https') ? https : http;
|
||||||
|
};
|
||||||
|
|
||||||
function getFileStream(filepath: string, isLocal = false): PassThrough | ReadStream {
|
function getFileStream(filepath: string, isLocal = false): PassThrough | ReadStream {
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
return createReadStream(filepath);
|
return createReadStream(filepath);
|
||||||
@ -12,7 +17,7 @@ function getFileStream(filepath: string, isLocal = false): PassThrough | ReadStr
|
|||||||
|
|
||||||
const readableStream = new PassThrough();
|
const readableStream = new PassThrough();
|
||||||
|
|
||||||
https
|
httpMethod(filepath)
|
||||||
.get(filepath, (res) => {
|
.get(filepath, (res) => {
|
||||||
if (res.statusCode !== 200) {
|
if (res.statusCode !== 200) {
|
||||||
readableStream.emit(
|
readableStream.emit(
|
||||||
@ -36,7 +41,7 @@ function getFileStats(filepath: string, isLocal = false): Promise<{ size: number
|
|||||||
return stat(filepath);
|
return stat(filepath);
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
https
|
httpMethod(filepath)
|
||||||
.get(filepath, (res) => {
|
.get(filepath, (res) => {
|
||||||
if (res.statusCode !== 200) {
|
if (res.statusCode !== 200) {
|
||||||
reject(new Error(`Request failed with status code ${res.statusCode}`));
|
reject(new Error(`Request failed with status code ${res.statusCode}`));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user