mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
fix protocol error
This commit is contained in:
parent
f5107c7236
commit
f55ad19141
@ -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}`));
|
||||
|
Loading…
x
Reference in New Issue
Block a user