-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
222 lines (207 loc) · 5.28 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Pype</title>
<style>
body {
font-family: courier,arial;
color: white;
}
#main_title {
position: absolute;
top: 30px;
left: 30px;
color: #2980cc;
font-weight: bold;
font-size: 30px;
}
#CLI {
height: 300px;
width: 650px;
padding: 25px;
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: black;
border-radius: 0 0 7px 7px;
}
#CLI #bar {
position: absolute;
top: -25px;
left: 0;
right: 0;
width: 100%;
height: 25px;
border-radius: 7px 7px 0 0;
background: #e0e0e0;
text-align: center;
}
#CLI #bar #title {
font-size: 80%;
color: #757575;
margin-top: 5px;
}
#CLI #bar #green {
position: absolute;
top: 5px;
right: 10px;
height: 15px;
width: 15px;
border-radius: 25px;
background: #3cba3c;
border: solid 1px grey;
}
#CLI #bar #orange {
position: absolute;
top: 5px;
right: 33px;
height: 15px;
width: 15px;
border-radius: 25px;
background: #fcbd51;
border: solid 1px grey;
}
#CLI #bar #red {
position: absolute;
top: 5px;
right: 56px;
height: 15px;
width: 15px;
border-radius: 25px;
background: #ff5757;
border: solid 1px grey;
}
#texte {
margin-top: 50px;
font-size: 15px;
}
#upload {
white-space: pre;
cursor: pointer;
}
#blue {
color: #2980cc;
}
#red {
color: #ff5757;
}
#author {
position: absolute;
bottom: 10px;
left: 10px;
color: #808080;
}
</style>
<script>
function update_progress(progress){
let bar = document.getElementById('upload')
bar.innerHTML = '['+'#'.repeat(progress/2).padEnd(50)+'] '+progress+'%'
}
function upload_error(error){
let bar = document.getElementById('upload')
bar.innerHTML = 'Error : <span id="red">'+error+'</span>'
}
function upload_done(url){
let bar = document.getElementById('upload')
bar.innerHTML = 'Upload done : <span id="blue">'+url+'</span>'
}
function upload_file(file_name, file_content){
var xhr = null
if(window.XMLHttpRequest){ // Firefox et autres
xhr = new XMLHttpRequest()
}else if(window.ActiveXObject){ // Internet Explorer
try {
xhr = new ActiveXObject('Msxml2.XMLHTTP')
} catch (e) {
xhr = new ActiveXObject('Microsoft.XMLHTTP')
}
}else{
alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest...')
xhr = false
}
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
upload_done(xhr.responseText)
}else if(xhr.readyState == 4 && xhr.status != 200){
upload_error(xhr.responseText)
}
}
xhr.upload.onprogress = function(e){
if(e.lengthComputable){
let progress = Math.round(parseFloat(e.loaded / e.total) * 100);
update_progress(progress)
}
}
xhr.open('PUT', '/'+file_name, true)
xhr.send(file_content)
}
document.addEventListener("DOMContentLoaded", function() {
var drop_zone = document.getElementById('CLI')
var file_input = document.getElementById('file_input')
var upload_string = document.getElementById('upload')
drop_zone.addEventListener('dragover', function(e){
e.stopPropagation()
e.preventDefault()
e.dataTransfer.dropEffect = 'copy'
})
drop_zone.addEventListener('drop', function(e){
e.stopPropagation()
e.preventDefault()
var files = e.dataTransfer.files
for (var i=0, file; file=files[i]; i++){
var reader = new FileReader()
reader.onload = function(){
let content = new Blob([reader.result])
upload_file(reader.file_name, content)
}
reader.file_name = file.name
reader.readAsArrayBuffer(file)
}
})
upload_string.addEventListener('click', function(e){
file_input.click()
})
file_input.addEventListener('change', function(e){
var files = file_input.files
for (var i=0, file; file=files[i]; i++){
var reader = new FileReader()
reader.onload = function(){
let content = new Blob([reader.result])
upload_file(reader.file_name, content)
}
reader.file_name = file.name
reader.readAsArrayBuffer(file)
}
})
})
</script>
</head>
<body>
<div id='main_title'>Pype</div>
<a href="https://github.com/sellan/Pype" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="Github-ribbon.png" alt="Fork me on GitHub"></a>
<div id='CLI'>
<div id='bar'>
<div id='title'>Pype - [url]</div>
<div id='green'></div>
<div id='orange'></div>
<div id='red'></div>
</div>
<div id='texte'>
Simple file sharing server, to upload and download file from CLI
<br/><br/><br/>
To upload : curl -T file.txt [url]<br/>
To download : curl [url]/e5f7/file.txt > files.txt<br/>
<br/><br/><br/>
<center>or</center>
<br/><br/><br/>
<center><span id='upload'>[ <span id="blue">Drop a file or click here !</span> ]</span></center>
<input id="file_input" type="file" style="display: none" />
</div>
</div>
<a href="https://contact.sellan.fr"><div id="author">Etienne SELLAN</div></a>
</body>
</html>