DmitrMakeev commited on
Commit
c9af98b
·
verified ·
1 Parent(s): a5e823c

Create pages.html

Browse files
Files changed (1) hide show
  1. pages.html +130 -0
pages.html ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>File Upload</title>
7
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ text-align: center;
12
+ background-color: #f0f0f0;
13
+ margin: 0;
14
+ padding: 0;
15
+ }
16
+ h1 {
17
+ background-color: #4CAF50;
18
+ color: white;
19
+ padding: 20px;
20
+ margin: 0;
21
+ border-bottom: 2px solid #388E3C;
22
+ }
23
+ button[type="submit"] {
24
+ color: white;
25
+ background-color: #4CAF50;
26
+ border: none;
27
+ cursor: pointer;
28
+ padding: 10px 20px;
29
+ font-size: 16px;
30
+ border-radius: 5px;
31
+ margin-top: 20px;
32
+ }
33
+ button[type="submit"]:hover {
34
+ background-color: #388E3C;
35
+ }
36
+ #imageUrl {
37
+ margin-top: 20px;
38
+ font-size: 16px;
39
+ color: #333;
40
+ cursor: pointer;
41
+ text-decoration: underline;
42
+ }
43
+ #progressBarContainer {
44
+ width: 80%;
45
+ margin: 20px auto;
46
+ background-color: #ddd;
47
+ border-radius: 13px;
48
+ padding: 3px;
49
+ }
50
+ #progressBar {
51
+ width: 0%;
52
+ height: 20px;
53
+ background-color: #4CAF50;
54
+ border-radius: 10px;
55
+ text-align: center;
56
+ line-height: 20px;
57
+ color: white;
58
+ }
59
+ </style>
60
+ </head>
61
+ <body>
62
+ <h1>Отправка HTML файла с пользовательским именем</h1>
63
+ <div id="progressBarContainer">
64
+ <div id="progressBar">0%</div>
65
+ </div>
66
+ <div id="imageUrl" onclick="copyToClipboard(this)">Кликните после загрузки, если нужна ссылка на сохранённый файл.</div>
67
+ <form id="uploadForm" enctype="multipart/form-data" method="post" action="/pages">
68
+ <input type="file" name="file" accept=".html">
69
+ <input type="text" name="filename" placeholder="Enter filename (without .html)">
70
+ <button type="submit">Загрузить</button>
71
+ </form>
72
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
73
+ <script>
74
+ document.getElementById('uploadForm').addEventListener('submit', function(event) {
75
+ event.preventDefault();
76
+ var formData = new FormData(this);
77
+ var request = new XMLHttpRequest();
78
+ request.open('POST', '/up_page');
79
+ request.upload.addEventListener('progress', function(event) {
80
+ if (event.lengthComputable) {
81
+ var percentComplete = (event.loaded / event.total) * 100;
82
+ document.getElementById('progressBar').style.width = percentComplete + '%';
83
+ document.getElementById('progressBar').innerText = Math.round(percentComplete) + '%';
84
+ }
85
+ }, false);
86
+ request.addEventListener('load', function(event) {
87
+ var response = event.target.responseText;
88
+ if (event.target.status === 200) {
89
+ var fullUrl = response.split('saved to ')[1];
90
+ document.getElementById('imageUrl').innerText = 'Click to copy URL';
91
+ document.getElementById('imageUrl').setAttribute('data-url', fullUrl);
92
+ Toastify({
93
+ text: "File uploaded successfully",
94
+ duration: 3000,
95
+ gravity: "top",
96
+ position: "center",
97
+ backgroundColor: "#4CAF50",
98
+ }).showToast();
99
+ } else if (event.target.status === 409) {
100
+ Toastify({
101
+ text: "File with this name already exists",
102
+ duration: 3000,
103
+ gravity: "top",
104
+ position: "center",
105
+ backgroundColor: "#FF5733",
106
+ }).showToast();
107
+ }
108
+ document.getElementById('progressBar').style.width = '0%';
109
+ document.getElementById('progressBar').innerText = '0%';
110
+ }, false);
111
+ request.send(formData);
112
+ });
113
+ function copyToClipboard(element) {
114
+ var tempInput = document.createElement("input");
115
+ tempInput.value = element.getAttribute('data-url');
116
+ document.body.appendChild(tempInput);
117
+ tempInput.select();
118
+ document.execCommand("copy");
119
+ document.body.removeChild(tempInput);
120
+ Toastify({
121
+ text: "URL copied to clipboard",
122
+ duration: 3000,
123
+ gravity: "top",
124
+ position: "center",
125
+ backgroundColor: "#4CAF50",
126
+ }).showToast();
127
+ }
128
+ </script>
129
+ </body>
130
+ </html>