|
1 | | -import axios, { AxiosError, AxiosResponse } from 'axios'; |
| 1 | +import axios from 'axios'; |
2 | 2 | import { url } from '../utils/Utils'; |
3 | 3 |
|
4 | | -const urlScanAPI = async ( |
5 | | - urlParam: string, |
6 | | - userCredentials?: any, |
7 | | - accessKey?: string, |
8 | | - secretKey?: string, |
9 | | - max_limit?: number, |
10 | | - query_source?: string |
11 | | -) => { |
| 4 | +interface ScanProps { |
| 5 | + urlParam: string; |
| 6 | + userCredentials?: any; |
| 7 | + model?: string; |
| 8 | + accessKey?: string; |
| 9 | + secretKey?: string; |
| 10 | + max_limit?: number; |
| 11 | + query_source?: string; |
| 12 | +} |
| 13 | + |
| 14 | +const urlScanAPI = async (props: ScanProps) => { |
12 | 15 | try { |
13 | 16 | const formData = new FormData(); |
14 | | - formData.append('uri', userCredentials?.uri); |
15 | | - formData.append('userName', userCredentials?.userName); |
16 | | - formData.append('password', userCredentials?.password); |
17 | | - formData.append('source_url', urlParam); |
18 | | - if (accessKey?.length) { |
19 | | - formData.append('aws_access_key_id', accessKey); |
| 17 | + formData.append('uri', props?.userCredentials?.uri); |
| 18 | + formData.append('userName', props?.userCredentials.userName); |
| 19 | + formData.append('password', props?.userCredentials?.password); |
| 20 | + formData.append('source_url', props?.urlParam); |
| 21 | + if (props.model != undefined) { |
| 22 | + formData.append('model', props?.model); |
| 23 | + } |
| 24 | + if (props.accessKey?.length) { |
| 25 | + formData.append('aws_access_key_id', props?.accessKey); |
20 | 26 | } |
21 | | - if (secretKey?.length) { |
22 | | - formData.append('aws_secret_access_key', secretKey); |
| 27 | + if (props?.secretKey?.length) { |
| 28 | + formData.append('aws_secret_access_key', props?.secretKey); |
23 | 29 | } |
24 | | - if (query_source?.length) { |
25 | | - formData.append('query_source', query_source); |
| 30 | + if (props?.query_source?.length) { |
| 31 | + formData.append('query_source', props?.query_source); |
26 | 32 | } |
27 | | - if (max_limit != undefined) { |
28 | | - formData.append('max_limit', max_limit.toString()); |
| 33 | + if (props?.max_limit != undefined) { |
| 34 | + formData.append('max_limit', props?.max_limit.toString()); |
29 | 35 | } |
30 | 36 |
|
31 | | - const response:any = await axios.post(`${url()}/url/scan`, formData, { |
| 37 | + const response: any = await axios.post(`${url()}/url/scan`, formData, { |
32 | 38 | headers: { |
33 | 39 | 'Content-Type': 'multipart/form-data', |
34 | 40 | }, |
35 | 41 | }); |
36 | 42 | return response; |
37 | 43 | } catch (error) { |
38 | 44 | console.log('Error uploading file:', error); |
39 | | - throw error; |
| 45 | + return error; |
40 | 46 | } |
41 | 47 | }; |
42 | 48 |
|
|
0 commit comments