mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-6019] [ACS-6021] [ACS-6023] Replaced request with node-fetch (#8999)
* [ACS-6019] Replaced request with node-fetch * [ACS-6019] [Non-Functional Change] Added documentation to peopleSelected event emitter - Change to trigger affected E2Es * [ACS-6019] Added return type to getFileFromRemote function. Removed request dependencies from package.json * [ACS-6019] Commit package-lock.json * [ACS-6019] Testing node-fetch v2 * [ACS-6019] Commiting package-lock.json
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
import program from 'commander';
|
||||
import request = require('request');
|
||||
import fetch from 'node-fetch';
|
||||
import * as fs from 'fs';
|
||||
import { logger } from './logger';
|
||||
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
|
||||
@@ -664,19 +664,30 @@ function findFailingApps(deployedApps: any[]): any[] {
|
||||
* @param url url to file
|
||||
* @param name name
|
||||
*/
|
||||
async function getFileFromRemote(url: string, name: string) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
request(url)
|
||||
.pipe(fs.createWriteStream(`${name}.zip`))
|
||||
.on('finish', () => {
|
||||
async function getFileFromRemote(url: string, name: string): Promise<void> {
|
||||
return fetch(url)
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.then((response) => new Promise<void>((resolve, reject) => {
|
||||
const outputFile = fs.createWriteStream(`${name}.zip`);
|
||||
response.body.pipe(outputFile);
|
||||
outputFile.on('finish', () => {
|
||||
logger.info(`The file is finished downloading.`);
|
||||
resolve();
|
||||
})
|
||||
.on('error', (error: any) => {
|
||||
});
|
||||
outputFile.on('error', (error) => {
|
||||
logger.error(`Not possible to download the project form remote`);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}))
|
||||
.catch((error) => {
|
||||
logger.error(`Failed to fetch file from remote: ${error.message}`);
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user