-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
191 lines (169 loc) · 5.92 KB
/
index.js
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
window.onload = () =>{
btn.disabled = true;
let validaForm = () =>{
if(username.value.length > 0 && senha.value.length > 0){
btn.disabled = false;
}else btn.disabled = true;
};
username.oninput = validaForm;
senha.oninput = validaForm;
/*btn.onclick = (evento) =>{
registraDadosAJAX();
evento.preventDefault();
//var x = evento;
}*/
}
function postData(input) {
$.ajax({
type: "POST",
url: "https://api-curriculum.herokuapp.com/Python/analyze-808e.py?input_file="+{param: input}+"&file_type=application/pdf&output_file=testes.json",
data: { param: input },
success: callbackFunc
});
}
function callbackFunc(response) {
// do something with the response
console.log(response);
}
/*function fileSelected(event){
var file = event.srcElement.files[0];
console.log(file);
var reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = function() {
//postData(btoa(reader.result));
pdfExtractor(btoa(reader.result));
console.log(btoa(reader.result));
};
reader.onerror = function() {
console.log('there are some problems');
};
}*/
function onFileChanged(event) {
var files = event.target.files; // event.dataTransfer.files;
if (!files.length) {
return;
}
var formData = new FormData();
// Add the File object to the formdata
if (this.multiple) {
formData.append("files", files);
} else {
formData.append("file", files[0]);
}
// Add your data...
//formData.append("data", myData);
}
function uploadDocument(formData) {
console.log('data sent');
console.log(formdata);
pdfExtractor(Axios.post('/api/documents', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}));
}
function mostra(){
x=document.getElementById("arq");
if (x.style.display == 'inline') {
x.style.display = 'none';
} else {
x.style.display = 'inline';
}
}
function registraDadosAJAX(){
//executar chamada AJAX para a API do JSONSERVER
let xhr = new XMLHttpRequest();
xhr.onload = verificaLogin;
xhr.open('POST', `http://localhost:6543/estudante/add?username=${username.value}&password=${senha.value}&prenome=${prenome.value}&sobrenome=${sobrenome.value}&email=${email.value}&cpf=${cpf.value}&curso=${curso.value}&periodo=${periodo.value}&endereco=${endereco.value}&telefone=${telefone.value}&linkedin=${linkedin.value}&idiomas=${idiomas.value}&skills=${skills.value}`);
xhr.send();
}
function verificaLogin(dados){
dados = JSON.parse(this.responseText);
for(i = 0; i < dados.length; i++){
let nomeAluno = dados[i].nome;
let idAluno = dados[i].id;
let tipoAluno = dados[i].is_monitor;
let senhaAluno = dados[i].senha;
if(nome.value == idAluno){
i = dados.length;
if(senha.value == senhaAluno){
login(idAluno, nomeAluno, tipoAluno);
}else alert("Usuário ou senha incorretos!");
}
}
}
function register(id, nomeAluno, type){
let user = {nome:nomeAluno, userId:id, tipo:type};
localStorage.setItem('user', JSON.stringify(user));
window.location.replace("./../html/initialScreen.html");
}
function getJson(){
axios.get('https://doors1.cognitiveservices.azure.com/formrecognizer/v2.1-preview.3/custom/models/808eb101-c6ac-422a-9298-679c47b2a0fc/analyzeResults/{resultId}')
.then(response => console.log(response)) //caso retorne um sucesso
.catch(error => console.log(error)) //caso ocorra algum erro
}
//var file = document.getElementsByTagName('input').value();
//var tipo = "application/"+file.split('.').pop();
imageHandler = (e) => {
const reader = new FileReader();
reader.readAsDataURL(e.target.files[0]);
let formData = new FormData();
formData.append("file", e.target.files[0]);
let url = "https://doors1.cognitiveservices.azure.com/formrecognizer/v2.1-preview.3/custom/models/808eb101-c6ac-422a-9298-679c47b2a0fc/analyze?";
axios
.post(url, formData, {
headers: {
"Content-Type": "application/pdf",
"Ocp-Apim-Subscription-Key": "267a6513a34b45bb8c045a7099016532",
},
})
.then((res) => {
console.log(res);
});
};
function pdfExtractor(formdata) {
var params = {
// Request parameters
"includeTextDetails": true,//formdata,
};
$.ajax({
post_url:"https://doors1.cognitiveservices.azure.com/formrecognizer/v2.1-preview.3/custom/models/808eb101-c6ac-422a-9298-679c47b2a0fc/analyze?",
url: "https://doors1.cognitiveservices.azure.com/formrecognizer/v2.1-preview.3/custom/models/808eb101-c6ac-422a-9298-679c47b2a0fc/analyze?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/pdf");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","267a6513a34b45bb8c045a7099016532");
},
type: "POST",
// Request body
data: formdata,
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
}
function getInformations() {
var params = {
// Request parameters
};
$.ajax({
url: "https://doors1.cognitiveservices.azure.com/formrecognizer/v2.1-preview.3/custom/models/808eb101-c6ac-422a-9298-679c47b2a0fc/analyzeResults/{resultId}?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","267a6513a34b45bb8c045a7099016532");
},
type: "GET",
// Request body
data: "{body}",
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
}