Skip to content

Uses /project route for valid tools #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,27 @@ export class GenerateModalComponent implements OnInit {
this.status = GenerationStatus.ZIPPING;

this.service.zipFileDirectory(result).then((data) => {
this.zippedFileData = data;
this.status = GenerationStatus.PROJECT_INFO;

//TODO: Prompt user beforehand on OSI or Parsers so don't need to upload project if don't have to OR the backend should be reworked for parsers
this.service.uploadProject(data, 'osi').then((tools: any) => {

tools.forEach((tool: any) => {
this.osiTools[tool] = true;
})

this.zippedFileData = data;
this.status = GenerationStatus.PROJECT_INFO;

}).catch((error) => {
this.Close();
})
}).catch((error) => {
this.Close();
})
}).catch((error) => {
this.Close();
})
});

this.service.getOSITools().subscribe((data) => {
data.forEach((tool) => {
this.osiTools[tool] = true;
})
})
}

ngOnChanges(): void {
Expand All @@ -79,11 +85,19 @@ export class GenerateModalComponent implements OnInit {

this.status = GenerationStatus.GENERATING;

this.service.uploadProject(this.zippedFileData,
let tools = [];

for (let key in this.osiTools) {
if (this.osiTools[key])
tools.push(key);
}

this.service.generateFile(this.zippedFileData,
this.options.name,
this.options.schema,
this.options.format,
this.options.type).then((data: any) => {
this.options.type,
tools).then((data: any) => {
this.sbomService.addSBOMbyID(data);
this.Close();
}).catch(() => {
Expand Down
29 changes: 24 additions & 5 deletions src/app/shared/services/SVIP.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export class SVIPService {
})
})
}


//#endregion
//#region Electron
/**
Expand Down Expand Up @@ -194,15 +194,19 @@ export class SVIPService {
})
}

async uploadProject(file: any, projectName: string, schema: string, format: string, type: string) {

async generateFile(file: any, projectName: string, schema: string, format: string, type: string, osiTools: string[]) {
return new Promise(async(resolve, reject) => {
let formData = new FormData();
formData.append('zipFile', new File([file], 'temp.zip'));

formData.append('projectName', projectName);
formData.append('schema', schema);
formData.append('format', format);

if(type.toLowerCase() === 'osi')
formData.append('toolNames', JSON.stringify(osiTools));
else
formData.append('zipFile', new File([file], 'temp.zip'));

let params = new HttpParams();

this.client.postFile('generators/' + type.toLowerCase(), formData, params).subscribe((data) => {
Expand All @@ -213,8 +217,23 @@ export class SVIPService {
return reject(false);
})
});
}

async uploadProject(file: any, type: string) {
return new Promise(async(resolve, reject) => {
let formData = new FormData();
formData.append('project', new File([file], 'temp.zip'));

let params = new HttpParams();

this.client.postFile('generators/' + type.toLowerCase() + "/project", formData, params).subscribe((data) => {
if(data) {
return resolve(data);
}

return reject(false);
})
});
}
//#endregion
}