Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -44,7 +44,7 @@ HTML_CONTENT = """
|
|
44 |
transform: translateY(-5px);
|
45 |
box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
|
46 |
}
|
47 |
-
h1 {
|
48 |
color: #ffffff;
|
49 |
margin-bottom: 1.5rem;
|
50 |
font-weight: 600;
|
@@ -253,7 +253,7 @@ HTML_CONTENT = """
|
|
253 |
transform: scale(1);
|
254 |
}
|
255 |
.copy-embed-btn {
|
256 |
-
background-color: #
|
257 |
color: white;
|
258 |
border: none;
|
259 |
padding: 10px 20px;
|
@@ -264,10 +264,20 @@ HTML_CONTENT = """
|
|
264 |
margin: 4px 2px;
|
265 |
transition-duration: 0.4s;
|
266 |
cursor: pointer;
|
267 |
-
border-radius:
|
268 |
}
|
269 |
.copy-embed-btn:hover {
|
270 |
-
background-color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
}
|
272 |
</style>
|
273 |
</head>
|
@@ -276,12 +286,12 @@ HTML_CONTENT = """
|
|
276 |
<h1>Radd PRO Uploader</h1>
|
277 |
<form id="uploadForm">
|
278 |
<div id="dropZone" class="drop-zone">
|
279 |
-
<input type="file" name="
|
280 |
-
<label for="
|
281 |
-
<p>or drag and drop
|
282 |
</div>
|
283 |
<div class="file-name" id="fileName"></div>
|
284 |
-
<button type="
|
285 |
<div class="progress-container" id="progressContainer"></div>
|
286 |
<div class="loading-spinner" id="loadingSpinner"></div>
|
287 |
</form>
|
@@ -296,15 +306,17 @@ HTML_CONTENT = """
|
|
296 |
<span class="close">×</span>
|
297 |
<h2>Embed Video Link</h2>
|
298 |
<p>Copy the following link to embed the video:</p>
|
299 |
-
<
|
300 |
-
|
|
|
|
|
301 |
</div>
|
302 |
</div>
|
303 |
|
304 |
<script>
|
305 |
-
const fileInput = document.getElementById('
|
306 |
const fileName = document.getElementById('fileName');
|
307 |
-
const
|
308 |
const progressContainer = document.getElementById('progressContainer');
|
309 |
const loadingSpinner = document.getElementById('loadingSpinner');
|
310 |
const resultContainer = document.getElementById('resultContainer');
|
@@ -313,13 +325,12 @@ HTML_CONTENT = """
|
|
313 |
const span = document.getElementsByClassName("close")[0];
|
314 |
const embedLinkInput = document.getElementById('embedLink');
|
315 |
|
316 |
-
|
317 |
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
uploadFiles(selectedFiles);
|
323 |
}
|
324 |
});
|
325 |
|
@@ -335,21 +346,18 @@ HTML_CONTENT = """
|
|
335 |
dropZone.addEventListener('drop', (e) => {
|
336 |
e.preventDefault();
|
337 |
dropZone.classList.remove('drag-over');
|
338 |
-
|
339 |
});
|
340 |
|
341 |
document.addEventListener('paste', (e) => {
|
342 |
const items = e.clipboardData.items;
|
343 |
-
const files = [];
|
344 |
for (let i = 0; i < items.length; i++) {
|
345 |
if (items[i].kind === 'file') {
|
346 |
const file = items[i].getAsFile();
|
347 |
-
files
|
|
|
348 |
}
|
349 |
}
|
350 |
-
if (files.length > 0) {
|
351 |
-
handleFiles({ target: { files: files } });
|
352 |
-
}
|
353 |
});
|
354 |
|
355 |
span.onclick = function() {
|
@@ -362,53 +370,31 @@ HTML_CONTENT = """
|
|
362 |
}
|
363 |
}
|
364 |
|
365 |
-
function
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
uploadBtn.style.display = 'inline-block';
|
371 |
}
|
372 |
}
|
373 |
|
374 |
-
function
|
375 |
progressContainer.innerHTML = '';
|
376 |
progressContainer.style.display = 'block';
|
377 |
loadingSpinner.style.display = 'block';
|
378 |
-
uploadBtn.disabled = true;
|
379 |
resultContainer.innerHTML = '';
|
380 |
resultContainer.style.display = 'none';
|
381 |
|
382 |
-
|
383 |
-
|
384 |
-
progressContainer.appendChild(progressBar);
|
385 |
-
uploadFile(file, progressBar, index);
|
386 |
-
});
|
387 |
-
}
|
388 |
|
389 |
-
function createProgressBar(fileName) {
|
390 |
-
const progressBarContainer = document.createElement('div');
|
391 |
-
progressBarContainer.className = 'progress-bar';
|
392 |
-
const progress = document.createElement('div');
|
393 |
-
progress.className = 'progress';
|
394 |
-
progressBarContainer.appendChild(progress);
|
395 |
-
const label = document.createElement('div');
|
396 |
-
label.textContent = fileName;
|
397 |
-
label.style.fontSize = '0.8rem';
|
398 |
-
label.style.marginBottom = '5px';
|
399 |
-
const container = document.createElement('div');
|
400 |
-
container.appendChild(label);
|
401 |
-
container.appendChild(progressBarContainer);
|
402 |
-
return container;
|
403 |
-
}
|
404 |
-
|
405 |
-
function uploadFile(file, progressBarContainer, index) {
|
406 |
const formData = new FormData();
|
407 |
formData.append('file', file);
|
408 |
|
409 |
const xhr = new XMLHttpRequest();
|
410 |
xhr.open('POST', '/upload', true);
|
411 |
-
xhr.upload.onprogress = (event) => updateProgress(event,
|
412 |
xhr.onload = function() {
|
413 |
if (xhr.status === 200) {
|
414 |
const response = JSON.parse(xhr.responseText);
|
@@ -420,26 +406,44 @@ HTML_CONTENT = """
|
|
420 |
} else {
|
421 |
alert('Upload failed: ' + xhr.statusText);
|
422 |
}
|
423 |
-
|
424 |
-
resetUploadState();
|
425 |
-
}
|
426 |
};
|
427 |
xhr.onerror = function() {
|
428 |
alert('Upload failed: Network error');
|
429 |
-
|
430 |
-
resetUploadState();
|
431 |
-
}
|
432 |
};
|
433 |
xhr.send(formData);
|
434 |
}
|
435 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
function resetUploadState() {
|
437 |
fileInput.value = '';
|
438 |
fileName.textContent = '';
|
439 |
-
uploadBtn.style.display = 'none';
|
440 |
-
uploadBtn.disabled = false;
|
441 |
loadingSpinner.style.display = 'none';
|
442 |
-
selectedFiles = [];
|
443 |
}
|
444 |
|
445 |
function addResultLink(url, fileName) {
|
|
|
44 |
transform: translateY(-5px);
|
45 |
box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
|
46 |
}
|
47 |
+
h1, h2 {
|
48 |
color: #ffffff;
|
49 |
margin-bottom: 1.5rem;
|
50 |
font-weight: 600;
|
|
|
253 |
transform: scale(1);
|
254 |
}
|
255 |
.copy-embed-btn {
|
256 |
+
background-color: #333;
|
257 |
color: white;
|
258 |
border: none;
|
259 |
padding: 10px 20px;
|
|
|
264 |
margin: 4px 2px;
|
265 |
transition-duration: 0.4s;
|
266 |
cursor: pointer;
|
267 |
+
border-radius: 5px;
|
268 |
}
|
269 |
.copy-embed-btn:hover {
|
270 |
+
background-color: #444;
|
271 |
+
}
|
272 |
+
.embed-container {
|
273 |
+
display: flex;
|
274 |
+
align-items: center;
|
275 |
+
justify-content: space-between;
|
276 |
+
margin-top: 15px;
|
277 |
+
}
|
278 |
+
#embedLink {
|
279 |
+
flex-grow: 1;
|
280 |
+
margin-right: 10px;
|
281 |
}
|
282 |
</style>
|
283 |
</head>
|
|
|
286 |
<h1>Radd PRO Uploader</h1>
|
287 |
<form id="uploadForm">
|
288 |
<div id="dropZone" class="drop-zone">
|
289 |
+
<input type="file" name="file" id="file" class="file-input" accept=".zip,.mp4,.txt,.mp3,image/*,.pdf" required>
|
290 |
+
<label for="file" class="btn">Choose File</label>
|
291 |
+
<p>or drag and drop file here/paste image</p>
|
292 |
</div>
|
293 |
<div class="file-name" id="fileName"></div>
|
294 |
+
<button type="submit" id="uploadBtn" class="btn" style="display: none; margin-top: 1rem;">Upload File</button>
|
295 |
<div class="progress-container" id="progressContainer"></div>
|
296 |
<div class="loading-spinner" id="loadingSpinner"></div>
|
297 |
</form>
|
|
|
306 |
<span class="close">×</span>
|
307 |
<h2>Embed Video Link</h2>
|
308 |
<p>Copy the following link to embed the video:</p>
|
309 |
+
<div class="embed-container">
|
310 |
+
<input type="text" id="embedLink" readonly>
|
311 |
+
<button onclick="copyEmbedLink()" class="copy-embed-btn">Copy</button>
|
312 |
+
</div>
|
313 |
</div>
|
314 |
</div>
|
315 |
|
316 |
<script>
|
317 |
+
const fileInput = document.getElementById('file');
|
318 |
const fileName = document.getElementById('fileName');
|
319 |
+
const uploadForm = document.getElementById('uploadForm');
|
320 |
const progressContainer = document.getElementById('progressContainer');
|
321 |
const loadingSpinner = document.getElementById('loadingSpinner');
|
322 |
const resultContainer = document.getElementById('resultContainer');
|
|
|
325 |
const span = document.getElementsByClassName("close")[0];
|
326 |
const embedLinkInput = document.getElementById('embedLink');
|
327 |
|
328 |
+
fileInput.addEventListener('change', handleFileSelect);
|
329 |
|
330 |
+
uploadForm.addEventListener('submit', (e) => {
|
331 |
+
e.preventDefault();
|
332 |
+
if (fileInput.files.length > 0) {
|
333 |
+
uploadFile(fileInput.files[0]);
|
|
|
334 |
}
|
335 |
});
|
336 |
|
|
|
346 |
dropZone.addEventListener('drop', (e) => {
|
347 |
e.preventDefault();
|
348 |
dropZone.classList.remove('drag-over');
|
349 |
+
handleFileSelect({ target: { files: e.dataTransfer.files } });
|
350 |
});
|
351 |
|
352 |
document.addEventListener('paste', (e) => {
|
353 |
const items = e.clipboardData.items;
|
|
|
354 |
for (let i = 0; i < items.length; i++) {
|
355 |
if (items[i].kind === 'file') {
|
356 |
const file = items[i].getAsFile();
|
357 |
+
handleFileSelect({ target: { files: [file] } });
|
358 |
+
break;
|
359 |
}
|
360 |
}
|
|
|
|
|
|
|
361 |
});
|
362 |
|
363 |
span.onclick = function() {
|
|
|
370 |
}
|
371 |
}
|
372 |
|
373 |
+
function handleFileSelect(e) {
|
374 |
+
if (e.target.files.length > 0) {
|
375 |
+
const file = e.target.files[0];
|
376 |
+
fileName.textContent = file.name;
|
377 |
+
document.getElementById('uploadBtn').style.display = 'inline-block';
|
|
|
378 |
}
|
379 |
}
|
380 |
|
381 |
+
function uploadFile(file) {
|
382 |
progressContainer.innerHTML = '';
|
383 |
progressContainer.style.display = 'block';
|
384 |
loadingSpinner.style.display = 'block';
|
385 |
+
document.getElementById('uploadBtn').disabled = true;
|
386 |
resultContainer.innerHTML = '';
|
387 |
resultContainer.style.display = 'none';
|
388 |
|
389 |
+
const progressBar = createProgressBar(file.name);
|
390 |
+
progressContainer.appendChild(progressBar);
|
|
|
|
|
|
|
|
|
391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
const formData = new FormData();
|
393 |
formData.append('file', file);
|
394 |
|
395 |
const xhr = new XMLHttpRequest();
|
396 |
xhr.open('POST', '/upload', true);
|
397 |
+
xhr.upload.onprogress = (event) => updateProgress(event, progressBar.querySelector('.progress'));
|
398 |
xhr.onload = function() {
|
399 |
if (xhr.status === 200) {
|
400 |
const response = JSON.parse(xhr.responseText);
|
|
|
406 |
} else {
|
407 |
alert('Upload failed: ' + xhr.statusText);
|
408 |
}
|
409 |
+
resetUploadState();
|
|
|
|
|
410 |
};
|
411 |
xhr.onerror = function() {
|
412 |
alert('Upload failed: Network error');
|
413 |
+
resetUploadState();
|
|
|
|
|
414 |
};
|
415 |
xhr.send(formData);
|
416 |
}
|
417 |
|
418 |
+
function createProgressBar(fileName) {
|
419 |
+
const progressBarContainer = document.createElement('div');
|
420 |
+
progressBarContainer.className = 'progress-bar';
|
421 |
+
const progress = document.createElement('div');
|
422 |
+
progress.className = 'progress';
|
423 |
+
progressBarContainer.appendChild(progress);
|
424 |
+
const label = document.createElement('div');
|
425 |
+
label.textContent = fileName;
|
426 |
+
label.style.fontSize = '0.8rem';
|
427 |
+
label.style.marginBottom = '5px';
|
428 |
+
const container = document.createElement('div');
|
429 |
+
container.appendChild(label);
|
430 |
+
container.appendChild(progressBarContainer);
|
431 |
+
return container;
|
432 |
+
}
|
433 |
+
|
434 |
+
function updateProgress(event, progressBar) {
|
435 |
+
if (event.lengthComputable) {
|
436 |
+
const percentComplete = (event.loaded / event.total) * 100;
|
437 |
+
progressBar.style.width = percentComplete + '%';
|
438 |
+
}
|
439 |
+
}
|
440 |
+
|
441 |
function resetUploadState() {
|
442 |
fileInput.value = '';
|
443 |
fileName.textContent = '';
|
444 |
+
document.getElementById('uploadBtn').style.display = 'none';
|
445 |
+
document.getElementById('uploadBtn').disabled = false;
|
446 |
loadingSpinner.style.display = 'none';
|
|
|
447 |
}
|
448 |
|
449 |
function addResultLink(url, fileName) {
|