DmitrMakeev commited on
Commit
6819288
·
verified ·
1 Parent(s): e2705c5

Create up_fa_vk.html

Browse files
Files changed (1) hide show
  1. up_fa_vk.html +86 -0
up_fa_vk.html ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- templates/up_fa_vk.html -->
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>File Upload</title>
8
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
9
+ </head>
10
+ <body>
11
+ <div id="progressBarContainer">
12
+ <div id="progressBar">0%</div>
13
+ </div>
14
+ <div id="imageUrl" onclick="copyToClipboard(this)">Кликните после загрузки, для получения ссылка на сохранённый файл.</div>
15
+ <form id="uploadForm" enctype="multipart/form-data" method="post" action="/upload_vk">
16
+ <input type="file" name="file">
17
+ <button type="submit">Загрузить</button>
18
+ </form>
19
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
20
+ <script>
21
+ document.getElementById('uploadForm').addEventListener('submit', function(event) {
22
+ event.preventDefault();
23
+ var formData = new FormData(this);
24
+ // Получаем ключ из локального хранилища
25
+ const apiKeySys = localStorage.getItem('api_key_sys');
26
+ if (!apiKeySys) {
27
+ Toastify({
28
+ text: "Ключ авторизации не найден",
29
+ duration: 3000,
30
+ gravity: "top",
31
+ position: "center",
32
+ backgroundColor: "#FF5733",
33
+ }).showToast();
34
+ return;
35
+ }
36
+ // Добавляем ключ в FormData
37
+ formData.append('api_key_sys', apiKeySys);
38
+ var request = new XMLHttpRequest();
39
+ request.open('POST', '/upload_vk');
40
+ request.upload.addEventListener('progress', function(event) {
41
+ if (event.lengthComputable) {
42
+ var percentComplete = (event.loaded / event.total) * 100;
43
+ document.getElementById('progressBar').style.width = percentComplete + '%';
44
+ document.getElementById('progressBar').innerText = Math.round(percentComplete) + '%';
45
+ }
46
+ }, false);
47
+ request.addEventListener('load', function(event) {
48
+ var response = JSON.parse(event.target.responseText);
49
+ if (response.error) {
50
+ Toastify({
51
+ text: "Ошибка: " + response.error,
52
+ duration: 3000,
53
+ gravity: "top",
54
+ position: "center",
55
+ backgroundColor: "#FF5733",
56
+ }).showToast();
57
+ } else {
58
+ var fullUrl = response.url;
59
+ document.getElementById('imageUrl').innerText = fullUrl;
60
+ document.getElementById('progressBar').style.width = '0%';
61
+ document.getElementById('progressBar').innerText = '0%';
62
+ // Сохранение ссылки в локальное хранилище
63
+ localStorage.setItem('fileUrl', fullUrl);
64
+ }
65
+ }, false);
66
+ request.send(formData);
67
+ });
68
+
69
+ function copyToClipboard(element) {
70
+ var tempInput = document.createElement("input");
71
+ tempInput.value = element.innerText;
72
+ document.body.appendChild(tempInput);
73
+ tempInput.select();
74
+ document.execCommand("copy");
75
+ document.body.removeChild(tempInput);
76
+ Toastify({
77
+ text: "Ссылка на загруженный файл скопирована",
78
+ duration: 3000,
79
+ gravity: "top",
80
+ position: "center",
81
+ backgroundColor: "#4CAF50",
82
+ }).showToast();
83
+ }
84
+ </script>
85
+ </body>
86
+ </html>