Spaces:
Sleeping
Sleeping
Update up_fa.html
Browse files- up_fa.html +86 -50
up_fa.html
CHANGED
@@ -87,69 +87,105 @@
|
|
87 |
</form>
|
88 |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
|
89 |
<script>
|
90 |
-
|
|
|
|
|
|
|
91 |
event.preventDefault();
|
92 |
var formData = new FormData(this);
|
93 |
var request = new XMLHttpRequest();
|
94 |
-
request.open('POST', '/
|
|
|
|
|
|
|
|
|
95 |
request.upload.addEventListener('progress', function(event) {
|
96 |
if (event.lengthComputable) {
|
97 |
var percentComplete = (event.loaded / event.total) * 100;
|
98 |
-
document.getElementById('progressBar')
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
100 |
}
|
101 |
}, false);
|
|
|
102 |
request.addEventListener('load', function(event) {
|
103 |
var response = event.target.responseText;
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
request.send(formData);
|
115 |
});
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
}
|
137 |
-
}
|
138 |
-
function copyToClipboard(element) {
|
139 |
-
var tempInput = document.createElement("input");
|
140 |
-
tempInput.value = element.innerText;
|
141 |
-
document.body.appendChild(tempInput);
|
142 |
-
tempInput.select();
|
143 |
-
document.execCommand("copy");
|
144 |
-
document.body.removeChild(tempInput);
|
145 |
-
Toastify({
|
146 |
-
text: "Ссылка на загруженный файл",
|
147 |
-
duration: 3000,
|
148 |
-
gravity: "top",
|
149 |
-
position: "center",
|
150 |
-
backgroundColor: "#4CAF50",
|
151 |
-
}).showToast();
|
152 |
-
}
|
153 |
</script>
|
154 |
</body>
|
155 |
</html>
|
|
|
87 |
</form>
|
88 |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
|
89 |
<script>
|
90 |
+
document.addEventListener('DOMContentLoaded', function() {
|
91 |
+
const uploadForm = document.getElementById('uploadForm');
|
92 |
+
if (uploadForm) {
|
93 |
+
uploadForm.addEventListener('submit', function(event) {
|
94 |
event.preventDefault();
|
95 |
var formData = new FormData(this);
|
96 |
var request = new XMLHttpRequest();
|
97 |
+
request.open('POST', '/up_page');
|
98 |
+
|
99 |
+
// Логирование начала загрузки
|
100 |
+
console.log('Upload started');
|
101 |
+
|
102 |
request.upload.addEventListener('progress', function(event) {
|
103 |
if (event.lengthComputable) {
|
104 |
var percentComplete = (event.loaded / event.total) * 100;
|
105 |
+
const progressBar = document.getElementById('progressBar');
|
106 |
+
if (progressBar) {
|
107 |
+
progressBar.style.width = percentComplete + '%';
|
108 |
+
progressBar.innerText = Math.round(percentComplete) + '%';
|
109 |
+
} else {
|
110 |
+
console.error("Element with id 'progressBar' not found");
|
111 |
+
}
|
112 |
}
|
113 |
}, false);
|
114 |
+
|
115 |
request.addEventListener('load', function(event) {
|
116 |
var response = event.target.responseText;
|
117 |
+
console.log('Response:', response); // Логирование ответа сервера
|
118 |
+
|
119 |
+
if (event.target.status === 200) {
|
120 |
+
var fullUrl = response.split('saved to ')[1];
|
121 |
+
console.log('Full URL:', fullUrl); // Логирование полного URL
|
122 |
+
|
123 |
+
const imageUrl = document.getElementById('imageUrl');
|
124 |
+
if (imageUrl) {
|
125 |
+
imageUrl.innerText = 'Click to copy URL';
|
126 |
+
imageUrl.setAttribute('data-url', fullUrl);
|
127 |
+
} else {
|
128 |
+
console.error("Element with id 'imageUrl' not found");
|
129 |
+
}
|
130 |
+
|
131 |
+
Toastify({
|
132 |
+
text: "File uploaded successfully",
|
133 |
+
duration: 3000,
|
134 |
+
gravity: "top",
|
135 |
+
position: "center",
|
136 |
+
backgroundColor: "#4CAF50",
|
137 |
+
}).showToast();
|
138 |
+
} else if (event.target.status === 409) {
|
139 |
+
Toastify({
|
140 |
+
text: "File with this name already exists",
|
141 |
+
duration: 3000,
|
142 |
+
gravity: "top",
|
143 |
+
position: "center",
|
144 |
+
backgroundColor: "#FF5733",
|
145 |
+
}).showToast();
|
146 |
+
} else {
|
147 |
+
console.error('Upload failed with status:', event.target.status);
|
148 |
+
}
|
149 |
+
|
150 |
+
const progressBar = document.getElementById('progressBar');
|
151 |
+
if (progressBar) {
|
152 |
+
progressBar.style.width = '0%';
|
153 |
+
progressBar.innerText = '0%';
|
154 |
+
} else {
|
155 |
+
console.error("Element with id 'progressBar' not found");
|
156 |
+
}
|
157 |
}, false);
|
158 |
+
|
159 |
+
request.addEventListener('error', function(event) {
|
160 |
+
console.error('Upload error:', event);
|
161 |
+
});
|
162 |
+
|
163 |
+
request.addEventListener('abort', function(event) {
|
164 |
+
console.error('Upload aborted:', event);
|
165 |
+
});
|
166 |
+
|
167 |
request.send(formData);
|
168 |
});
|
169 |
+
} else {
|
170 |
+
console.error("Element with id 'uploadForm' not found");
|
171 |
+
}
|
172 |
+
|
173 |
+
function copyToClipboard(element) {
|
174 |
+
var tempInput = document.createElement("input");
|
175 |
+
tempInput.value = element.getAttribute('data-url');
|
176 |
+
document.body.appendChild(tempInput);
|
177 |
+
tempInput.select();
|
178 |
+
document.execCommand("copy");
|
179 |
+
document.body.removeChild(tempInput);
|
180 |
+
Toastify({
|
181 |
+
text: "URL copied to clipboard",
|
182 |
+
duration: 3000,
|
183 |
+
gravity: "top",
|
184 |
+
position: "center",
|
185 |
+
backgroundColor: "#4CAF50",
|
186 |
+
}).showToast();
|
187 |
+
}
|
188 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
</script>
|
190 |
</body>
|
191 |
</html>
|