DmitrMakeev commited on
Commit
e82e275
·
verified ·
1 Parent(s): 8d74358

Update up_fa.html

Browse files
Files changed (1) hide show
  1. up_fa.html +58 -50
up_fa.html CHANGED
@@ -87,69 +87,77 @@
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
  request.upload.addEventListener('progress', function(event) {
99
  if (event.lengthComputable) {
100
  var percentComplete = (event.loaded / event.total) * 100;
101
+ const progressBar = document.getElementById('progressBar');
102
+ if (progressBar) {
103
+ progressBar.style.width = percentComplete + '%';
104
+ progressBar.innerText = Math.round(percentComplete) + '%';
105
+ }
106
  }
107
  }, false);
108
  request.addEventListener('load', function(event) {
109
  var response = event.target.responseText;
110
+ if (event.target.status === 200) {
111
+ var fullUrl = response.split('saved to ')[1];
112
+ const imageUrl = document.getElementById('imageUrl');
113
+ if (imageUrl) {
114
+ imageUrl.innerText = 'Click to copy URL';
115
+ imageUrl.setAttribute('data-url', fullUrl);
116
+ }
117
+ Toastify({
118
+ text: "File uploaded successfully",
119
+ duration: 3000,
120
+ gravity: "top",
121
+ position: "center",
122
+ backgroundColor: "#4CAF50",
123
+ }).showToast();
124
+ } else if (event.target.status === 409) {
125
+ Toastify({
126
+ text: "File with this name already exists",
127
+ duration: 3000,
128
+ gravity: "top",
129
+ position: "center",
130
+ backgroundColor: "#FF5733",
131
+ }).showToast();
132
+ }
133
+ const progressBar = document.getElementById('progressBar');
134
+ if (progressBar) {
135
+ progressBar.style.width = '0%';
136
+ progressBar.innerText = '0%';
137
+ }
138
  }, false);
139
  request.send(formData);
140
  });
141
+ } else {
142
+ console.error("Element with id 'uploadForm' not found");
143
+ }
144
+
145
+ function copyToClipboard(element) {
146
+ var tempInput = document.createElement("input");
147
+ tempInput.value = element.getAttribute('data-url');
148
+ document.body.appendChild(tempInput);
149
+ tempInput.select();
150
+ document.execCommand("copy");
151
+ document.body.removeChild(tempInput);
152
+ Toastify({
153
+ text: "URL copied to clipboard",
154
+ duration: 3000,
155
+ gravity: "top",
156
+ position: "center",
157
+ backgroundColor: "#4CAF50",
158
+ }).showToast();
159
+ }
160
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  </script>
162
  </body>
163
  </html>