-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·267 lines (231 loc) · 7.16 KB
/
index.php
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
require_once dirname(__FILE__) . '/../LVH-Fling/resources/php/aws/s3.php';
?>
<html>
<head>
<style media="screen" type="text/css">
.progress {
position: relative;
width: 100%;
height: 15px;
background: #C7DA9F;
border-radius: 10px;
overflow: hidden;
}
.bar {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 15px;
background: #85C220;
}
</style>
<!-- Include Public Scripts -->
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script src="/javascript/jquery.fileupload.js"></script>
<!-- Include LVH-Fling Scripts -->
<script src="../LVH-Fling/resources/config.js"></script>
<script src="../LVH-Fling/resources/js/common.js"></script>
<script src="../LVH-Fling/resources/js/aws/sqs.js"></script>
<script type="text/javascript">
/******************************************************************************************************************
* S3 Upload Process
******************************************************************************************************************/
DEBUG_ENABLED = true;
//Test Area
//var num = 12345;
//alert(CreateSqsQueue(num));
//Variables
var localFileName = "";
var s3FileName = "";
var jobId = "";
var s3Directory = "Jobs/";
var statusTimeout = 5000; //ms
//SQS Queues
var sqsBaseUrl = 'https://sqs.us-east-1.amazonaws.com/293388242627/';
var sqsJobsQueueName = 'LVH_VIChallenge_Jobs/';
var jobsQueueUrl = sqsBaseUrl.concat(sqsJobsQueueName);
$(document).ready
(
function()
{
$('.direct-upload').each( function()
{
var form = $(this);
$(this).fileupload(
{
url: form.attr('action'),
type: 'POST',
datatype: 'xml',
add: function (event, data)
{
if(DEBUG_ENABLED == true)
{
alert("add");
}
//Store Values, We'll Need Them Later
localFileName = data.files[0].name;
jobId = UniqueId();
s3FileName = jobId.concat(localFileName.replace(/\s+/g,""));
//Check the file extension and set the S3 destination path of the form.
var fileExtension = s3FileName.substr(s3FileName.lastIndexOf("."));
//Check File Type
if(fileExtension == ".vi" || fileExtension == ".zip")
{
//Valid Extension, Set S3 Form Destination Path
document.getElementById("s3UploadKey").value = s3Directory.concat(s3FileName);
}
else
{
alert("Please choose a file with .VI or .ZIP extension.");
}
if(DEBUG_ENABLED == true)
{
alert("localFileName = " + localFileName);
alert("s3FileName = " + s3FileName);
alert("s3Directory = " + s3Directory);
}
// Use XHR, fallback to iframe
options = $(this).fileupload('option');
use_xhr = !options.forceIframeTransport && ((!options.multipart && $.support.xhrFileUpload) || $.support.xhrFormDataFileUpload);
if (!use_xhr)
{
using_iframe_transport = true;
}
//Submit File to S3
data.submit();
},
send: function(e, data)
{
if(DEBUG_ENABLED == true)
{
alert("send");
}
},
progress: function(e, data)
{
var percent = Math.round((data.loaded / data.total) * 100);
if(DEBUG_ENABLED == true)
{
alert("progress: " + percent + "%");
}
},
fail: function(e, data)
{
if(DEBUG_ENABLED == true)
{
alert("fail");
alert(e);
}
},
success: function(data)
{
if(DEBUG_ENABLED == true)
{
alert("success");
}
//Send Job Ready Message To Jobs SQS Queue
//Create Job Specific
var queueName = "LVH_VIChallengeJob_";// + jobId;
var statusSqsQueue = CreateSqsQueue(queueName);
//SendSqsMessage(jobsQueueUrl, jobId);
//Long Poll For Status Until Job Is Complete, Update Elements
var workerState = -1;
var now = new Date();
var lastTime = now.getTime();
while(workerState < 4)
{
//Check Specific Job Queue For Status Updates. It We Don't Get A Status Update In The Given Time Report Timeout. We Can Sit In The Queued State
//As Long As We Are Getting Updates, But After Leaving The Queue State We Only Move Forward So Don't Report Other Updates But Always Reset Timer On Update.
var status = GetSqsMessage(statusSqsQueue, 5, '');
switch(status)
{
case 'queued':
now = new Date();
lastTime = now.getTime();
if(workerState <= 0)
{
workerState = 0;
alert('queued');
}
break;
case 'preparing':
now = new Date();
lastTime = now.getTime();
if(workerState < 1)
{
workerState = 1;
alert('queued');
}
break;
case 'processing':
now = new Date();
lastTime = now.getTime();
if(workerState < 2)
{
workerState = 2;
alert('queued');
}
break;
case 'uploading':
now = new Date();
lastTime = now.getTime();
if(workerState < 3)
{
workerState = 3;
alert('queued');
}
break;
case 'complete':
now = new Date();
lastTime = now.getTime();
if(workerState < 4)
{
workerState = 4;
alert('queued');
}
break;
default:
workerState = -1;
break;
}
//Check For Timeout
now = new Date();
alert("Last Time: " + lastTime + "\nCurrentTime : " + now.getTime());
if( (now.getTime() - lastTime) > statusTimeout)
{
alert("timeout");
break;
}
}
//Check workerState And Either Update Page Or Report Error
},
done: function (event, data)
{
if(DEBUG_ENABLED == true)
{
alert("done");
}
},
});
});
}
);
/******************************************************************************************************************
* S3 Upload Helpers
******************************************************************************************************************/
</script>
</head>
<body>
<!-- Direct Upload to S3 -->
<?php
S3UploadForm(LVH_VIChallenge);
?>
<!-- Used to Track Upload within our App -->
<form action="process-form-data.php" method="POST">
<input type="hidden" name="upload_original_name" />
</form>
</body>
</html>