DmitrMakeev commited on
Commit
df73573
·
verified ·
1 Parent(s): 0f42868

Update up_fa.html

Browse files
Files changed (1) hide show
  1. 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
- 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', '/upload');
 
 
 
 
95
  request.upload.addEventListener('progress', function(event) {
96
  if (event.lengthComputable) {
97
  var percentComplete = (event.loaded / event.total) * 100;
98
- document.getElementById('progressBar').style.width = percentComplete + '%';
99
- document.getElementById('progressBar').innerText = Math.round(percentComplete) + '%';
 
 
 
 
 
100
  }
101
  }, false);
 
102
  request.addEventListener('load', function(event) {
103
  var response = event.target.responseText;
104
- var fullUrl = response.split('saved to ')[1];
105
- var filename = fullUrl.split('/').pop();
106
- document.getElementById('imageUrl').innerText = fullUrl;
107
- displayMedia(fullUrl);
108
- document.getElementById('progressBar').style.width = '0%';
109
- document.getElementById('progressBar').innerText = '0%';
110
- // Сохранение имени файла и ссылки в локальное хранилище
111
- localStorage.setItem('filename', filename);
112
- localStorage.setItem('fileUrl', fullUrl);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  }, false);
 
 
 
 
 
 
 
 
 
114
  request.send(formData);
115
  });
116
- function displayMedia(url) {
117
- var mediaContainer = document.getElementById('mediaContainer');
118
- mediaContainer.innerHTML = '';
119
- var extension = url.split('.').pop().toLowerCase();
120
- if (['jpg', 'jpeg', 'png', 'gif'].includes(extension)) {
121
- var img = document.createElement('img');
122
- img.src = url;
123
- mediaContainer.appendChild(img);
124
- } else if (['mp4', 'webm', 'ogg'].includes(extension)) {
125
- var video = document.createElement('video');
126
- video.src = url;
127
- video.controls = true;
128
- mediaContainer.appendChild(video);
129
- } else if (['mp3', 'wav', 'ogg'].includes(extension)) {
130
- var audio = document.createElement('audio');
131
- audio.src = url;
132
- audio.controls = true;
133
- mediaContainer.appendChild(audio);
134
- } else {
135
- mediaContainer.innerText = 'Unsupported file type';
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>