Skip to content

Commit

Permalink
Bug Fix: issue with chunk uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
TamimiGitHub committed Sep 28, 2024
1 parent 37db540 commit f6a74bf
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 105 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
"@types/long": "^5.0.0",
"@types/node": "^20.8.9",
"ascii-table": "^0.0.9",
"axios": "^1.7.7",
"chalk": "~4.1.2",
"commander": "^11.1.0",
"core-js": "^3.26.0",
"enquirer": "^2.4.1",
"express": "^4.18.2",
"form-data": "^4.0.0",
"http": "^0.0.1-security",
"json-schema-library": "^10.0.0-rc1",
"node-localstorage": "^3.0.5",
Expand All @@ -57,7 +59,9 @@
"zip-lib": "^1.0.4"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/concat-stream": "^2.0.0",
"@types/form-data": "^2.5.0",
"@types/node-fetch": "^2.6.11",
"@types/signale": "^1.4.4",
"typescript": "^4.7.3"
Expand Down
63 changes: 38 additions & 25 deletions src/lib/feed-contribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { defaultEventFeedsFile, defaultFakerRulesFile, defaultFeedAnalysisFile,
import { chalkBoldLabel, chalkBoldVariable, chalkBoldWhite } from '../utils/chalkUtils';
import { getLocalEventFeeds } from '../utils/listfeeds';
import { prettyJSON } from '../utils/prettify';
import axios, { AxiosResponse } from 'axios';
import FormData from 'form-data';

const contribute = async (options: ManageFeedClientOptions, optionsSource: any) => {
const { Select, Confirm, Input, List } = require('enquirer');
Expand Down Expand Up @@ -233,7 +235,7 @@ const contribute = async (options: ManageFeedClientOptions, optionsSource: any)

async function createPR (feedName:string, info:any, azureFunctionInfo:any, feedLocalPath:string, ) {
let PRLink = null
// const azureFunctionURL = 'http://localhost:7071/api/triggerContribute'
// const azureFunctionURL = 'http://127.0.0.1:7071/api/triggerContribute'
const azureFunctionURL = 'https://stm-contribute.azurewebsites.net/api/triggerContribute'
// Query EVENT-FEEDS.json
try {
Expand All @@ -258,29 +260,37 @@ async function createPR (feedName:string, info:any, azureFunctionInfo:any, feedL
try {
if (info.type === 'asyncapi_feed') {
const analysis:any = readFile(`${feedLocalPath}/${defaultFeedAnalysisFile}`);

// Create form-data body payload
// Create a new FormData object
let formData = new FormData();
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedAnalysisFile}`))]), defaultFeedAnalysisFile);
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedSchemasFile}`))]), defaultFeedSchemasFile);
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedRulesFile}`))]), defaultFeedRulesFile);
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${defaultFakerRulesFile}`))]), defaultFakerRulesFile);
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${analysis.fileName}`))]), analysis.fileName);
formData.append('files', new Blob([JSON.stringify(info)]), defaultFeedInfoFile);
formData.append('files', new Blob([JSON.stringify(communityFeeds)]), 'EVENT_FEEDS.json');
formData.append('files', new Blob([JSON.stringify(azureFunctionInfo)]), 'azureFunctionInfo.json');

formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedAnalysisFile}`)), defaultFeedAnalysisFile);
formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedSchemasFile}`)), defaultFeedSchemasFile);
formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedRulesFile}`)), defaultFeedRulesFile);
formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${defaultFakerRulesFile}`)), defaultFakerRulesFile);
formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${analysis.fileName}`)), analysis.fileName);
formData.append('files', JSON.stringify(info), defaultFeedInfoFile);
formData.append('files', JSON.stringify(communityFeeds), 'EVENT_FEEDS.json');
formData.append('files', JSON.stringify(azureFunctionInfo), 'azureFunctionInfo.json');

// formData.getLength((err: Error | null, length: number) => {
// if (err) {
// console.error('Error getting form data length:', err);
// } else {
// console.log('Form data length:', length);
// }
// });

functionBody = await executeFunction(azureFunctionURL, formData)
} else if (info.type === 'restapi_feed') {

// Create form-data body payload
// Create a new FormData object
let formData = new FormData();
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedApiEndpointFile}`))]), defaultFeedApiEndpointFile);
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedRulesFile}`))]), defaultFeedRulesFile);
formData.append('files', new Blob([JSON.stringify(await readFile(`${feedLocalPath}/${defaultFakerRulesFile}`))]), defaultFakerRulesFile);
formData.append('files', new Blob([JSON.stringify(info)]), defaultFeedInfoFile);
formData.append('files', new Blob([JSON.stringify(communityFeeds)]), 'EVENT_FEEDS.json');
formData.append('files', new Blob([JSON.stringify(azureFunctionInfo)]), 'azureFunctionInfo.json');
formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedApiEndpointFile}`)), defaultFeedApiEndpointFile);
formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${defaultFeedRulesFile}`)), defaultFeedRulesFile);
formData.append('files', JSON.stringify(await readFile(`${feedLocalPath}/${defaultFakerRulesFile}`)), defaultFakerRulesFile);
formData.append('files', JSON.stringify(info), defaultFeedInfoFile);
formData.append('files', JSON.stringify(communityFeeds), 'EVENT_FEEDS.json');
formData.append('files', JSON.stringify(azureFunctionInfo), 'azureFunctionInfo.json');

functionBody = await executeFunction(azureFunctionURL, formData)
}
Expand All @@ -302,21 +312,24 @@ async function createPR (feedName:string, info:any, azureFunctionInfo:any, feedL

async function executeFunction (azureFunctionURL:string, formData:FormData) {
try {
let response: Response = await fetch(azureFunctionURL, {
method: 'POST',
body: formData,
const response: AxiosResponse = await axios.post(azureFunctionURL, formData, {
headers: {
...formData.getHeaders(),
},
maxContentLength: Infinity,
maxBodyLength: Infinity
});

let body = await response.json()

if(response.ok) {
let body = response.data
if(response.status === 200) {
return body
} else {
Logger.error(`Error executing function:\n${JSON.stringify(body, null, 2)}`)
process.exit(1);
}
} catch (error) {
Logger.error(`Error executing function: contact [email protected] for help`)
Logger.error(`Error executing function: contact [email protected] for help.`)
axios.isAxiosError(error) ? Logger.error(`\n${JSON.stringify(error.response?.data, null, 2)}`) : null
process.exit(1);
}
}
Expand Down
Loading

0 comments on commit f6a74bf

Please sign in to comment.