-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
174 lines (155 loc) · 5.71 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Regulatory Document SuperDuper System</title>
<style>
body {
background-color: #202b3c;
display: flex;
/* Centering the form */
justify-content: center;
/* Centering the form */
align-items: center;
/* Centering the form */
height: 100vh;
/* Centering the form */
margin: 0;
/* Removing default margin */
}
.main-frame {
display: flex;
flex-direction: column;
/* Aligning form elements vertically */
align-items: center;
/* Centering form elements horizontally */
background-color: #fff;
/* Adding a white background to the form */
padding: 20px;
/* Adding padding to the form */
border-radius: 8px;
/* Adding border radius to the form */
}
label,
button {
color: #FF9900;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
margin: 10px 0;
/* Adding margin between elements */
}
input {
color: #232F3E;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
margin: 10px 0;
/* Adding margin between elements */
width: 80%;
/* Setting input width */
padding: 5px;
/* Adding padding to input */
}
button {
background-color: #FF9900;
/* Adding background color to button */
color: #fff;
/* Changing button text color */
border: none;
/* Removing button border */
padding: 10px 20px;
/* Adding padding to button */
cursor: pointer;
/* Changing cursor to pointer on hover */
}
h1 {
color: #202b3c;
font-family: Arial, Helvetica, sans-serif;
}
</style>
<script>
// Define the function to call the API with the provided first name, last name, and phone number
let callAPI = (doc) => {
document.getElementById("status").innerHTML = "Processing..."
let getRealMimeType = function (reader) {
var arr = (new Uint8Array(reader.result)).subarray(0, 4);
var header = '';
var realMimeType;
for (var i = 0; i < arr.length; i++) {
header += arr[i].toString(16);
}
// magic numbers: http://www.garykessler.net/library/file_sigs.html
switch (header) {
case "89504e47":
realMimeType = "image/png";
break;
case "47494638":
realMimeType = "image/gif";
break;
case "ffd8ffDB":
case "ffd8ffe0":
case "ffd8ffe1":
case "ffd8ffe2":
case "ffd8ffe3":
case "ffd8ffe8":
realMimeType = "image/jpeg";
break;
case "25504446":
realMimeType = "application/pdf";
break;
default:
realMimeType = "unknown"; // Or you can use the blob.type as fallback
break;
}
return realMimeType;
}
var reader = new FileReader();
var readerBase64 = new FileReader();
reader.onloadend = function () {
var realMimeType = getRealMimeType(reader);
if (realMimeType !== 'unknown') {
readerBase64.readAsDataURL(doc);
} else {
document.getElementById("output").innerHTML = "Please upload a valid file";
}
};
reader.readAsArrayBuffer(doc);
readerBase64.onloadend = function () {
let encoded = this.result.toString().replace(/^data:(.*,)?/, '');
if ((encoded.length % 4) > 0) {
encoded += '='.repeat(4 - (encoded.length % 4));
}
// Define the request options including method, headers, body, and redirect behavior
let requestOptions = {
method: 'POST', // Method type
body: JSON.stringify({ 'document': encoded }), // The body of the request containing the JSON string
redirect: 'follow' // Automatically follow redirects
};
document.getElementById("status").innerHTML = "Awating response from POWERFUL AI..."
// Use the fetch API to send the request to the specified URL
fetch("YOUR AWS LAMBDA FUNCTION (OR API ENDPOINT) PUBLIC URL", requestOptions) // Replace "API_KEY" with your actual API endpoint
.then(response => response.text()) // Parse the response as text
.then(result => {
document.getElementById("status").innerHTML = "Success"
document.getElementById("results").innerHTML = result.replaceAll(/\\n/g, '<br />')
}) // Parse the result as JSON and alert the message
.catch(error => {
result
document.getElementById("status").innerHTML = "Error: " + error.replaceAll(/\\n/g, '<br />')
});
};
}
</script>
</head>
<body>
<form class="main-frame" id="send-form">
<h1 style="color: red;">Service Message: Replace the fetch URL in the JS code</h1>
<h1>Upload Regulatory Document</h1>
<input type="file" id="fDoc" />
<button type="button" onclick="callAPI(document.getElementById('fDoc').files[0])">Submit</button>
<div>Status: <div id="status"></div>
</div>
<div>Results: <div id="results" style="white-space: pre-wrap;"></div>
</div>
</form>
</body>
</html>