Skip to content

Commit cb840f6

Browse files
author
dushimsam
committed
fix(MULTIPLE-API-CALLS) merge multiple upload-api calls into one
Signed-off-by: dushimsam <[email protected]>
1 parent 133c1af commit cb840f6

File tree

6 files changed

+392
-163
lines changed

6 files changed

+392
-163
lines changed

src/api/upload.js

Lines changed: 136 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright (C) 2021 Shruti Agarwal ([email protected]), Aman Dwivedi ([email protected])
3+
Copyright (C) 2022 Samuel Dushimimana ([email protected])
34
45
SPDX-License-Identifier: GPL-2.0
56
@@ -26,17 +27,55 @@ import { getToken } from "shared/authHelper";
2627
import sendRequest from "./sendRequest";
2728

2829
// Create Uploads from File
29-
export const createUploadApi = (
30-
folderId,
31-
uploadDescription,
32-
accessLevel,
33-
ignoreScm,
34-
fileInput
35-
) => {
30+
export const createUploadApi = (uploadFileData, scanData) => {
31+
const { folderId, uploadDescription, accessLevel, ignoreScm, fileInput } =
32+
uploadFileData;
33+
34+
const { bucket, copyrightEmailAuthor, ecc, keyword, mime, monk, nomos, ojo } =
35+
scanData?.analysis;
36+
const { nomosMonk, bulkReused, newScanner, ojoDecider } = scanData?.decider;
37+
const {
38+
reuseUpload,
39+
reuseGroup,
40+
reuseMain,
41+
reuseEnhanced,
42+
reuseReport,
43+
reuseCopyright,
44+
} = scanData?.reuse;
45+
3646
const url = endpoints.upload.uploadCreate();
3747
const formdata = new FormData();
48+
const scanOptions = {
49+
analysis: {
50+
bucket,
51+
copyright_email_author: copyrightEmailAuthor,
52+
ecc,
53+
keyword,
54+
mime,
55+
monk,
56+
nomos,
57+
ojo,
58+
package: scanData.analysis.package,
59+
},
60+
decider: {
61+
nomos_monk: nomosMonk,
62+
bulk_reused: bulkReused,
63+
new_scanner: newScanner,
64+
ojo_decider: ojoDecider,
65+
},
66+
reuse: {
67+
reuse_upload: reuseUpload,
68+
reuse_group: reuseGroup,
69+
reuse_main: reuseMain,
70+
reuse_enhanced: reuseEnhanced,
71+
reuse_report: reuseReport,
72+
reuse_copyright: reuseCopyright,
73+
},
74+
};
75+
3876
if (fileInput) {
3977
formdata.append("fileInput", fileInput, fileInput?.name);
78+
formdata.append("scanOptions", JSON.stringify(scanOptions));
4079
}
4180
return sendRequest({
4281
url,
@@ -48,41 +87,123 @@ export const createUploadApi = (
4887
uploadDescription,
4988
public: accessLevel,
5089
ignoreScm,
51-
uploadType: "",
90+
uploadType: "file",
5291
},
5392
body: formdata,
5493
});
5594
};
5695

5796
// Create Uploads from Version Control System
58-
export const createUploadVcsApi = (header, body) => {
97+
export const createUploadVcsApi = (header, vcsData, scanData) => {
5998
const url = endpoints.upload.uploadCreate();
99+
const { bucket, copyrightEmailAuthor, ecc, keyword, mime, monk, nomos, ojo } =
100+
scanData?.analysis;
101+
const { nomosMonk, bulkReused, newScanner, ojoDecider } = scanData?.decider;
102+
const {
103+
reuseUpload,
104+
reuseGroup,
105+
reuseMain,
106+
reuseEnhanced,
107+
reuseReport,
108+
reuseCopyright,
109+
} = scanData?.reuse;
110+
60111
return sendRequest({
61112
url,
62113
method: "POST",
63114
headers: {
64115
...header,
65116
Authorization: getToken(),
66117
},
67-
body,
118+
body: {
119+
data: vcsData,
120+
scanOptions: {
121+
analysis: {
122+
bucket,
123+
copyright_email_author: copyrightEmailAuthor,
124+
ecc,
125+
keyword,
126+
mime,
127+
monk,
128+
nomos,
129+
ojo,
130+
package: scanData.analysis.package,
131+
},
132+
decider: {
133+
nomos_monk: nomosMonk,
134+
bulk_reused: bulkReused,
135+
new_scanner: newScanner,
136+
ojo_decider: ojoDecider,
137+
},
138+
reuse: {
139+
reuse_upload: reuseUpload,
140+
reuse_group: reuseGroup,
141+
reuse_main: reuseMain,
142+
reuse_enhanced: reuseEnhanced,
143+
reuse_report: reuseReport,
144+
reuse_copyright: reuseCopyright,
145+
},
146+
},
147+
},
68148
});
69149
};
70150

71151
// Create Uploads from URL
72-
export const createUploadUrlApi = (header, body) => {
152+
export const createUploadUrlApi = (header, urlData, scanData) => {
73153
const url = endpoints.upload.uploadCreate();
154+
const { bucket, copyrightEmailAuthor, ecc, keyword, mime, monk, nomos, ojo } =
155+
scanData?.analysis;
156+
const { nomosMonk, bulkReused, newScanner, ojoDecider } = scanData?.decider;
157+
const {
158+
reuseUpload,
159+
reuseGroup,
160+
reuseMain,
161+
reuseEnhanced,
162+
reuseReport,
163+
reuseCopyright,
164+
} = scanData?.reuse;
165+
74166
return sendRequest({
75167
url,
76168
method: "POST",
77169
headers: {
78170
...header,
79171
Authorization: getToken(),
80172
},
81-
body,
173+
body: {
174+
data: urlData,
175+
scanOptions: {
176+
analysis: {
177+
bucket,
178+
copyright_email_author: copyrightEmailAuthor,
179+
ecc,
180+
keyword,
181+
mime,
182+
monk,
183+
nomos,
184+
ojo,
185+
package: scanData.analysis.package,
186+
},
187+
decider: {
188+
nomos_monk: nomosMonk,
189+
bulk_reused: bulkReused,
190+
new_scanner: newScanner,
191+
ojo_decider: ojoDecider,
192+
},
193+
reuse: {
194+
reuse_upload: reuseUpload,
195+
reuse_group: reuseGroup,
196+
reuse_main: reuseMain,
197+
reuse_enhanced: reuseEnhanced,
198+
reuse_report: reuseReport,
199+
reuse_copyright: reuseCopyright,
200+
},
201+
},
202+
},
82203
});
83204
};
84205

85-
// Getting a Upload by id
206+
// Getting an Upload by id
86207
export const getUploadByIdApi = (uploadId, retries) => {
87208
const url = endpoints.upload.getId(uploadId);
88209
return sendRequest({
@@ -95,7 +216,7 @@ export const getUploadByIdApi = (uploadId, retries) => {
95216
});
96217
};
97218

98-
// Getting a Upload Summary
219+
// Getting an Upload Summary
99220
export const getUploadSummaryApi = (uploadId) => {
100221
const url = endpoints.upload.getSummary(uploadId);
101222
return sendRequest({
@@ -107,7 +228,7 @@ export const getUploadSummaryApi = (uploadId) => {
107228
});
108229
};
109230

110-
// Getting a Upload License
231+
// Getting an Upload License
111232
export const getUploadLicenseApi = (uploadId, agent) => {
112233
const url = endpoints.upload.getLicense(uploadId);
113234
return sendRequest({

0 commit comments

Comments
 (0)