generated from nighthawkcoders/Nighthawk-Pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.html
360 lines (314 loc) · 12 KB
/
upload.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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload</title>
<style>
body {
background: linear-gradient(45deg, #000000, #2c2c2e);
height: 100vh;
font-family: 'Montserrat', sans-serif;
}
.container {
position: absolute;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
}
.error {
background: rgba(58, 58, 60, 0.3);
padding: 3em;
height: auto;
border-radius: 20px;
border-left: 1px solid rgba(58, 58, 60, 0.3);
border-top: 1px solid rgba(58, 58, 60, 0.3);
backdrop-filter: blur(10px);
box-shadow: 20px 20px 40px -6px rgba(0, 0, 0, 0.2);
text-align: center;
position: relative;
transition: all 0.2s ease-in-out;
&:hover {
box-shadow: 4px 4px 60px 8px rgba(0, 0, 0, 0.2);
}
}
form {
background: rgba(58, 58, 60, 0.3);
padding: 3em;
height: auto;
border-radius: 20px;
border-left: 1px solid rgba(58, 58, 60, 0.3);
border-top: 1px solid rgba(58, 58, 60, 0.3);
backdrop-filter: blur(10px);
box-shadow: 20px 20px 40px -6px rgba(0, 0, 0, 0.2);
text-align: center;
position: relative;
transition: all 0.2s ease-in-out;
&:hover {
margin: 4px;
}
}
p {
font-weight: 500;
color: #fff;
opacity: 0.7;
font-size: 1.4rem;
margin-top: 0;
margin-bottom: 60px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}
a {
text-decoration: none;
color: #ddd;
font-size: 12px;
&:hover {
text-shadow: 2px 2px 6px #00000040;
}
&:active {
text-shadow: none;
}
}
input {
background: transparent;
width: 200px;
padding: 1em;
margin-bottom: 2em;
border: none;
border-left: 1px solid rgba(58, 58, 60, 0.3);
border-top: 1px solid rgba(58, 58, 60, 0.3);
border-radius: 5000px;
backdrop-filter: blur(5px);
box-shadow: 4px 4px 60px rgba(0, 0, 0, 0.2);
color: #fff;
font-family: Montserrat, sans-serif;
font-weight: 500;
transition: all 0.2s ease-in-out;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
&:hover {
background: rgba(255, 255, 255, 0.1);
box-shadow: 4px 4px 60px 8px rgba(0, 0, 0, 0.2);
}
&[type="email"],
&[type="password"] {
&:focus {
background: rgba(255, 255, 255, 0.1);
box-shadow: 4px 4px 60px 8px rgba(0, 0, 0, 0.2);
}
}
&[type="button"] {
margin-top: 10px;
width: 150px;
font-size: 1rem;
&:hover {
cursor: pointer;
}
&:active {
background: rgba(255, 255, 255, 0.2);
}
}
}
::placeholder {
font-family: Montserrat, sans-serif;
font-weight: 400;
color: #fff;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
}
.drop {
background: rgba(58, 58, 60, 0.3);
backdrop-filter: blur(10px);
border-radius: 10px;
border-left: 1px solid rgba(58, 58, 60, 0.3);
border-top: 1px solid rgba(58, 58, 60, 0.3);
box-shadow: 10px 10px 60px -8px rgba(0, 0, 0, 0.2);
position: absolute;
transition: all 0.2s ease;
}
.drop-1 {
height: 80px;
width: 80px;
top: -20px;
left: -40px;
z-index: -1;
}
.drop-2 {
height: 80px;
width: 80px;
bottom: -30px;
right: -10px;
}
.drop-3 {
height: 100px;
width: 100px;
bottom: 120px;
right: -50px;
z-index: -1;
}
.drop-4 {
height: 120px;
width: 120px;
top: -60px;
right: -60px;
}
.drop-5 {
height: 60px;
width: 60px;
bottom: 170px;
left: 90px;
z-index: -1;
}
label {
color: white;
}
a,
input:focus,
select:focus,
textarea:focus,
button:focus {
outline: none;
}
</style>
</head>
<body>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500&display=swap" rel="stylesheet">
<div class="container">
<!-- login form -->
<form method="POST" id="myForm">
<p>Upload Video</p>
<!-- <label for="thumbnailField" class="custom-file-label">Select Thumbnail</label><br> -->
<input type="text" id="nameField" name="name" placeholder="Video Title"><br>
<!-- <label for="thumbnailField" class="custom-file-label">Select Thumbnail</label><br> -->
<input type="text" id="descField" name="desc" placeholder="Video Description"><br>
<label for="thumbnailField" class="custom-file-label">Select Thumbnail</label><br>
<input type="file" id="thumbnailField" name="thumbnail"><br>
<label for="thumbnailField" class="custom-file-label">Select Video</label><br>
<input type="file" id="videoField" name="video"><br>
<label for="genre">Choose a genre:</label>
<select id="genre" name="genre">
<option value="none">None</option>
<option value="gaming">Gaming</option>
<option value="sports">Sports</option>
<option value="music">Music</option>
<option value="educational">Educational</option>
</select><br><br>
<!-- <label for="thumbnailField" class="custom-file-label">Select Thumbnail</label><br> -->
<!-- submit button -->
<input type="hidden" id="csrfTokenField" name="csrf_token" value="">
<input type="submit" value="Upload Video"><br>
</form>
<!-- square things in the background -->
<div class="drops">
<div class="drop drop-1"></div>
<div class="drop drop-2"></div>
<div class="drop drop-3"></div>
<div class="drop drop-4"></div>
<div class="drop drop-5"></div>
</div>
</div>
<script>
window.addEventListener('load', function () {
// Reset the form on page load
document.getElementById('myForm').reset();
});
// 200 success
function success(uploadSuccessful) {
const messageElement = document.createElement('p');
messageElement.textContent = uploadSuccessful ? 'Upload successful!' : 'Upload failed. Please try again.';
messageElement.style.color = uploadSuccessful ? 'green' : 'red';
document.body.appendChild(messageElement);
// Optionally, you can reset the form or do other actions here
}
// Assuming you have an input element with id="imageInput" where users can select an image file
// Function to handle the image conversion
function convertImageToBase64(thumbnail) {
return new Promise((resolve, reject) => {
// Make sure a file is selected
if (thumbnail.files.length > 0) {
var file = thumbnail.files[0];
// Create a FileReader object
var reader = new FileReader();
// Set up a function to be called once the file is loaded
reader.onload = function (event) {
// event.target.result contains the base64 encoded image
base64String = event.target.result.split(',')[1]; // Remove the data URL prefix
resolve(base64String);
};
reader.readAsDataURL(file);
} else {
reject('Please select an image file.');
}
});
}
async function submitForm() {
// get the elements (username, password, etc)
const uid = localStorage.getItem("uid")
const name = document.getElementById('nameField').value; // full name
const description = document.getElementById('descField').value; // date of birth // username
const vid = document.getElementById('videoField'); // email
var formData = new FormData();
var thumb = document.getElementById('thumbnailField');
var base64String = "";
var form = document.getElementById('myForm');
var video = null;
var thumb_name = thumb.files[0].name
var genre = document.getElementById("genre").value
if (uid == null) {
console.log("LOG IN PRIOR TO UPLOAD")
return "SIGN IN"
}
formData.append('video', vid.files[0]);
try {
const apiUrl = "http://127.0.0.1:8069/api/video/"
console.log(genre.value2)
var formData = new FormData(form);
video = (vid.files[0]).name;
convertImageToBase64(thumb)
.then(base64String => {
const base64 = "data:image/png;base64," + base64String;
fetch(apiUrl, {
mode: 'cors',
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': 'http://127.0.0.1:4100',
'Access-Control-Allow-Credentials': 'true'
},
body: JSON.stringify({ name: name, description: description, thumbnail: thumb_name, base64: base64String, video: video, uid: uid, genre:genre }) // convert payload to JSON
})
// Do something with the base64String, such as sending it to a server or displaying it
})
.catch(error => {
console.error(error);
});
//upload desc, name, and thumbnail
//upload video
fetch(apiUrl, {
mode: 'cors',
method: 'POST',
credentials: 'include',
headers: {
'Access-Control-Allow-Origin': 'http://127.0.0.1:4100',
'Access-Control-Allow-Credentials': 'true'},
body: formData
})
.catch(error => {
// Handle any errors
console.error('Error uploading video:', error);
});
if (!uploadResponse.ok) {
throw new Error('Upload request was not successful');
}
success(true)
}
catch {
console.log("TRY FAILED")
}
}
const form = document.getElementById('myForm');
form.addEventListener('submit', function (event) {
event.preventDefault();
submitForm();
});
</script>
</body>
</html>