Update up_page.html
Browse files- up_page.html +36 -8
up_page.html
CHANGED
@@ -86,10 +86,27 @@
|
|
86 |
<button type="submit">Загрузить</button>
|
87 |
</form>
|
88 |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
|
89 |
-
|
90 |
document.getElementById('uploadForm').addEventListener('submit', function(event) {
|
91 |
event.preventDefault();
|
92 |
var formData = new FormData(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
var request = new XMLHttpRequest();
|
94 |
request.open('POST', '/up_page');
|
95 |
request.upload.addEventListener('progress', function(event) {
|
@@ -100,16 +117,27 @@
|
|
100 |
}
|
101 |
}, false);
|
102 |
request.addEventListener('load', function(event) {
|
103 |
-
var response = event.target.responseText;
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
}, false);
|
111 |
request.send(formData);
|
112 |
});
|
|
|
113 |
function copyToClipboard(element) {
|
114 |
var tempInput = document.createElement("input");
|
115 |
tempInput.value = element.innerText;
|
|
|
86 |
<button type="submit">Загрузить</button>
|
87 |
</form>
|
88 |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
|
89 |
+
<script>
|
90 |
document.getElementById('uploadForm').addEventListener('submit', function(event) {
|
91 |
event.preventDefault();
|
92 |
var formData = new FormData(this);
|
93 |
+
|
94 |
+
// Получаем ключ из локального хранилища
|
95 |
+
const apiKeySys = localStorage.getItem('api_key_sys');
|
96 |
+
if (!apiKeySys) {
|
97 |
+
Toastify({
|
98 |
+
text: "Ключ авторизации не найден",
|
99 |
+
duration: 3000,
|
100 |
+
gravity: "top",
|
101 |
+
position: "center",
|
102 |
+
backgroundColor: "#FF5733",
|
103 |
+
}).showToast();
|
104 |
+
return;
|
105 |
+
}
|
106 |
+
|
107 |
+
// Добавляем ключ в FormData
|
108 |
+
formData.append('api_key_sys', apiKeySys);
|
109 |
+
|
110 |
var request = new XMLHttpRequest();
|
111 |
request.open('POST', '/up_page');
|
112 |
request.upload.addEventListener('progress', function(event) {
|
|
|
117 |
}
|
118 |
}, false);
|
119 |
request.addEventListener('load', function(event) {
|
120 |
+
var response = JSON.parse(event.target.responseText);
|
121 |
+
if (response.error) {
|
122 |
+
Toastify({
|
123 |
+
text: "Ошибка: " + response.error,
|
124 |
+
duration: 3000,
|
125 |
+
gravity: "top",
|
126 |
+
position: "center",
|
127 |
+
backgroundColor: "#FF5733",
|
128 |
+
}).showToast();
|
129 |
+
} else {
|
130 |
+
var fullUrl = response.url;
|
131 |
+
document.getElementById('imageUrl').innerText = fullUrl;
|
132 |
+
document.getElementById('progressBar').style.width = '0%';
|
133 |
+
document.getElementById('progressBar').innerText = '0%';
|
134 |
+
// Сохранение ссылки в локальное хранилище
|
135 |
+
localStorage.setItem('fileUrl', fullUrl);
|
136 |
+
}
|
137 |
}, false);
|
138 |
request.send(formData);
|
139 |
});
|
140 |
+
|
141 |
function copyToClipboard(element) {
|
142 |
var tempInput = document.createElement("input");
|
143 |
tempInput.value = element.innerText;
|