Skip to content

Commit

Permalink
chore: use node-fetch instead of request (#1422)
Browse files Browse the repository at this point in the history
Co-authored-by: asyncapi-bot <[email protected]>%0ACo-authored-by: samz <[email protected]>
  • Loading branch information
helios2003 and Amzani authored May 15, 2024
1 parent 8a428e6 commit 01f068a
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions scripts/fetch-asyncapi-example.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const request = require('request');
const fetch = require('node-fetch');
const fs = require('fs');
const unzipper = require('unzipper');
const path = require('path');
Expand All @@ -23,14 +23,28 @@ const EXAMPLE_DIRECTORY = path.join(__dirname, '../assets/examples');
const TEMP_ZIP_NAME = 'spec-examples.zip';

const fetchAsyncAPIExamplesFromExternalURL = () => {
return new Promise((resolve, reject) => {
request(SPEC_EXAMPLES_ZIP_URL)
.pipe(fs.createWriteStream(TEMP_ZIP_NAME))
.on('close', () => {
console.log('Fetched ZIP file');
resolve();
}).on('error', reject);
});
try {
return new Promise((resolve, reject) => {
fetch(SPEC_EXAMPLES_ZIP_URL)
.then((res) => {
if (res.status !== 200) {
reject(new Error(`Failed to fetch examples from ${SPEC_EXAMPLES_ZIP_URL}`));
}
const file = fs.createWriteStream(TEMP_ZIP_NAME);
res.body.pipe(file);
file.on('close', () => {
console.log('Fetched ZIP file');
file.close();
resolve();
}).on('error', (err) => {
reject(err);
});
})
.catch(reject);
});
} catch (error) {
console.error(error);
}
};

const unzipAsyncAPIExamples = async () => {
Expand Down

0 comments on commit 01f068a

Please sign in to comment.