-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
163 lines (150 loc) · 4.7 KB
/
main.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
$(document).ready(function () {
// init states
$("#alert").hide()
$("#upload").hide()
$("#video").hide()
$("#submitToAPI").hide();
$("#alias").hide();
// set functions
$("#generate").click(function () {
var seed = $("#seed").val();
var walletAdd = $("#wallet").val();
if (seed === '') {
M.toast({ html: "please set a password to generate wallet!" })
// $("#alert").html("please set a password to generate wallet!")
// $("#alert").show()
}
else{
$("#alert").hide()
// var settings = {
// "async": true,
// "crossDomain": true,
// "url": "http://172.16.21.223:3000/api/platform/register",
// "dataType": "json",
// "method": "POST",
// "headers": {
// "Content-Type": "application/json",
// "Accept": "application/json"
// },
// "processData": false,
//
// "data": {password: "seed" }
// }
//
// $.ajax(settings).done(function (response) {
// console.log(response);
// $("#register").html(response);
// });
$.ajax({
type: 'POST',
url: "http://172.16.21.223:3000/api/platform/register",
data: JSON.stringify({
'password': seed
}),
dataType: "json",
contentType: "application/json",
success: function (result) {
console.log(result);
$("#register").html("Your Wallet address is: "+result.result);
},
error: function (err) {
console.log(err);
M.toast({ html: "Invalid credentials!" })
}
});
}
})
$("#checkin").click(function (){
var wallet = $("#wallet").val();
var seed = $("#seed").val();
if (seed === '' || wallet==='') {
M.toast({ html: "please enter credentials to checkin!" })
// $("#alert").html("please enter some credentials to checkin!")
// $("#alert").show()
}
else {
$("#alert").hide()
var status = ""
// TODO: call api to checkin heartbeat and set status
$.ajax({
type: 'POST',
url: "http://172.16.21.223:3000/api/platform/getHeartbeat",
data: JSON.stringify({
'password': seed,
'walletAddress': wallet
}),
dataType: "json",
contentType: "application/json",
success: function (result) {
console.log("adhgs0", result);
status = "success";
$("#upload").show()
$("#alias").show()
$("#login").hide()
$("#checkinBtn").hide()
$("#register").hide()
$("#submitToAPI").show();
var files;
$('#fileInput').on('change', prepareUpload);
function prepareUpload(event){
console.log(event)
files = event.target.files;
};
$("#submitToAPI").click(function(){
if($("alias1").val()===""||$("alias2").val()===""||$("heartbeatDays").val()===""){
M.toast({ html: "Please enter required details!" })
}
else{
var form = new FormData();
// form.append("file", "");
console.log(files);
form.append("walletAddress", wallet);
form.append("password", seed);
form.append("alias1", $("#alias1").val());
form.append("alias2", $("#alias2").val());
form.append("file",files[0]);
// $.each(files, function(key, value){
// form.append(key, value);
// });
console.log(form);
$.ajax({
type: 'POST',
url: "http://172.16.21.223:3000/api/platform/uploadDocument",
data: form,
contentType: false,
processData: false,
mimeType: "multipart/form-data",
success: function (result) {
if(result.result==="true"){
console.log(result);
status = "success";
M.toast({ html: "File successfully uploaded!" })
$("#submitToAPI").hide();
}
},
error: function (err) {
console.log(err);
}
});
}
})
},
error: function (err) {
console.log(err);
M.toast({ html: "Invalid checkin credentials!" })
}
});
}
})
$("#uploadButton").click(function(){
$("#fileInput").click()
})
$("#record").click(function(){
$("#buttons").hide()
$("#video").show()
startFunction()
})
$("#uploadToChainButton").click(function () {
downloadVideo()
})
});