-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
371 lines (321 loc) · 13.5 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=0.7">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://unicons.iconscout.com/release/v2.1.9/css/unicons.css" />
<link rel="stylesheet" href="home.css" />
</head>
<body><a href="https://mrrishabhjain.github.io/filetolink/" class="logo" target="_self">
<img src="https://assets.codepen.io/1462889/fcy.png" alt="">
</a>
<div class="section">
<div class="container">
<div class="row full-height justify-content-center">
<div class="col-12 text-center align-self-center py-5">
<div class="section pb-5 pt-5 pt-sm-2 text-center">
<h6 class="mb-0 pb-3" ><span onclick="document.getElementById('reg-log').checked=false" ><a>Download</a></span><span onclick="document.getElementById('reg-log').checked=true"><a>Upload</a></span></h6>
<input class="checkbox" type="checkbox" id="reg-log" name="reg-log" />
<label for="reg-log"></label>
<div class="card-3d-wrap mx-auto">
<div class="card-3d-wrapper">
<div class="card-front">
<div class="center-wrap">
<div class="section text-center">
<h4 class="mb-4 pb-3">Download File</h4>
<div class="form-group">
<!-- <input type="email" name="logemail" class="form-style" placeholder="Your Email" id="logemail" autocomplete="off"> -->
<i class="input-icon uil uil-at"></i>
</div>
<div class="form-group mt-2">
<input type="text" name="logpass" class="form-style" placeholder="Enter File Key" id="logpass" onfocus="NameSelected()" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div>
<a href="#" class="btn mt-4" onclick="downloadFile()" id="getBtn2">lookup</a>
<!-- <p class="mb-0 mt-4 text-center"><a href="#0" class="link">Forgot your password?</a></p> -->
</div>
</div>
</div>
<div class="card-back">
<div class="center-wrap">
<div class="section text-center">
<h4 class="mb-4 pb-3">Upload File</h4>
<form id="myFormId">
<!-- action="http://52.136.120.54:5000/uploader" method="POST" enctype="multipart/form-data"> -->
<div class="form-group">
<!-- <textarea id="codeVar" style="display:none"></textarea> -->
<input type="file" name="file" id="getFile" onchange="FileSelected()" style="display:none">
<div class="form-style" id="codeVar" onclick="uploadFile()" style="text-align:left; opacity: 0.7"> <span id="fileName1">Drag file here</span></div>
<!-- <input type="text" name="logname" class="form-style" placeholder="Your Full Name" id="logname" autocomplete="off"> -->
<i class="input-icon uil uil-upload"></i>
</div>
<!-- <div class="form-group mt-2">
<input type="email" name="logemail" class="form-style" placeholder="Your Email" id="logemail" autocomplete="off">
<body>
<button style="display:block;width:120px; height:30px;" onclick="document.getElementById('getFile').click()">Your text here</button>
</body>
<i class="input-icon uil uil-at"></i>
</div> -->
<!-- <div class="form-group mt-2">
<input type="password" name="logpass" class="form-style" placeholder="Your Password" id="logpass" autocomplete="off">
<i class="input-icon uil uil-lock-alt"></i>
</div> -->
<a href="#" class="btn mt-4" onclick="uploadFile()" id="getBtn">browse</a>
<!-- <input href="#" class="btn mt-4" type = "submit" value='upload'/> -->
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
const params = new URLSearchParams(document.location.search);
console.log('gotKey',params.get("key"));
if(null!=params.get("key")){
document.getElementById("logpass").value = params.get("key")
downloadFile()
}
var input = document.getElementById("logpass");
var gkey=''
// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup", function(event) {
// Number 13 is the "Enter" key on the keyboard
if (event.keyCode === 13) {
// Cancel the default action, if needed
event.preventDefault();
// Trigger the button element with a click
document.getElementById("getBtn2").click();
document.getElementById("logpass").blur();
}
});
function NameSelected(){
gkey=''
document.getElementById("getBtn2").innerText = 'lookup'
document.getElementById("logpass").placeholder = 'Enter File Key'
}
function downloadFile(){
key = document.getElementById("logpass").value
console.log("logpass",key)
var filename = ''
if (document.getElementById("getBtn2").innerText == "LOOKUP") {
var stat = 0
document.getElementById("logpass").blur();
document.getElementById("logpass").placeholder = 'Loading...'
document.getElementById("getBtn2").innerText = 'checking'
fetch('https://52.136.120.54:5500/lookup?key='+key)
.then((resp) => {
stat = resp.status
return resp.text();//.json(); // or resp.text() or whatever the server sends
})
.then( filename => {
if (filename!='Error!' && stat==200){
gkey = document.getElementById("logpass").value
document.getElementById("logpass").value = ''
document.getElementById("logpass").placeholder = 'File: ' + filename
document.getElementById("getBtn2").innerText = 'Download'
}
else{
document.getElementById("logpass").value = ''
document.getElementById("getBtn2").innerText = 'lookup'
document.getElementById("logpass").placeholder = 'Invalid Key. Try Again.'
}
})
} else if (document.getElementById("getBtn2").innerText == "DOWNLOAD"){
//key = document.getElementById("logpass").innerText
document.getElementById("getBtn2").innerText = 'Downloading'
fetch('https://52.136.120.54:5500/download?key='+ gkey)
.then(response => {
if(response.headers.get('content-disposition')){
filename = response.headers.get('content-disposition').split("=")[1];
document.getElementById("logpass").placeholder = 'File: ' + filename
return response.blob();
}else{
document.getElementById("getBtn2").innerText = 'lookup'
document.getElementById("logpass").placeholder = 'Invalid Key'
}})
.then( blob => {
// var file = window.URL.createObjectURL(blob);
// window.location.assign(file);
if(filename!=''){
download(blob, filename, "application/octet-stream");
document.getElementById("getBtn2").innerText = 'Downloaded';
}else{
document.getElementById("getBtn2").innerText = 'Download'
}
})
}}
function uploadFile() {
if (document.getElementById("getBtn").innerText == "BROWSE") {
document.getElementById('getFile').click()
} else if (document.getElementById("getBtn").innerText == "UPLOAD"){
console.log('getBtn',document.getElementById('getBtn'))
uploadFetch()
} else {
navigator.clipboard.writeText('https://mrrishabhjain.github.io/filetolink/?key='+gkey)
document.getElementById("getBtn").innerText = 'link copied';
}
}
function uploadFetch() {
document.getElementById("fileName1").innerText = 'Uploading file...'
var input = document.querySelector('input[type="file"]')
var data = new FormData()
data.append('file', input.files[0])
// data.append('user', 'hubot')
fetch('https://52.136.120.54:5500/uploader', {
method: 'POST',
body: data
}).then((resp) => {
return resp.text();//.json(); // or resp.text() or whatever the server sends
}).then((body) => {
console.log('code', body)
document.getElementById("fileName1").innerText = 'Your File Key is '+body;
// document.getElementById("codeVar").innerHtml = body;
gkey = body
document.getElementById("getBtn").innerText = 'copy link';
// TODO handle body
}).catch((error) => {
console.log('err', body)
// TODO handle error
});
}
function FileSelected(e) {
file = document.getElementById('getFile').files[document.getElementById('getFile').files.length - 1];
document.getElementById("fileName1").innerText = file.name;
document.getElementById("getBtn").innerText = 'upload';
}
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.download = factory();
}
}(this, function () {
return function download(data, strFileName, strMimeType) {
var self = window, // this script is only for browsers anyway...
defaultMime = "application/octet-stream", // this default mime also triggers iframe downloads
mimeType = strMimeType || defaultMime,
payload = data,
url = !strFileName && !strMimeType && payload,
anchor = document.createElement("a"),
toString = function(a){return String(a);},
myBlob = (self.Blob || self.MozBlob || self.WebKitBlob || toString),
fileName = strFileName || "download",
blob,
reader;
myBlob= myBlob.call ? myBlob.bind(self) : Blob ;
if(String(this)==="true"){ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
payload=[payload, mimeType];
mimeType=payload[0];
payload=payload[1];
}
if(url && url.length< 2048){ // if no filename and no mime, assume a url was passed as the only argument
fileName = url.split("/").pop().split("?")[0];
anchor.href = url; // assign href prop to temp anchor
if(anchor.href.indexOf(url) !== -1){ // if the browser determines that it's a potentially valid url path:
var ajax=new XMLHttpRequest();
ajax.open( "GET", url, true);
ajax.responseType = 'blob';
ajax.onload= function(e){
download(e.target.response, fileName, defaultMime);
};
setTimeout(function(){ ajax.send();}, 0); // allows setting custom ajax headers using the return:
return ajax;
} // end if valid url?
} // end if url?
//go ahead and download dataURLs right away
if(/^data\:[\w+\-]+\/[\w+\-]+[,;]/.test(payload)){
if(payload.length > (1024*1024*1.999) && myBlob !== toString ){
payload=dataUrlToBlob(payload);
mimeType=payload.type || defaultMime;
}else{
return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs:
navigator.msSaveBlob(dataUrlToBlob(payload), fileName) :
saver(payload) ; // everyone else can save dataURLs un-processed
}
}//end if dataURL passed?
blob = payload instanceof myBlob ?
payload :
new myBlob([payload], {type: mimeType}) ;
function dataUrlToBlob(strUrl) {
var parts= strUrl.split(/[:;,]/),
type= parts[1],
decoder= parts[2] == "base64" ? atob : decodeURIComponent,
binData= decoder( parts.pop() ),
mx= binData.length,
i= 0,
uiArr= new Uint8Array(mx);
for(i;i<mx;++i) uiArr[i]= binData.charCodeAt(i);
return new myBlob([uiArr], {type: type});
}
function saver(url, winMode){
if ('download' in anchor) { //html5 A[download]
anchor.href = url;
anchor.setAttribute("download", fileName);
anchor.className = "download-js-link";
anchor.innerHTML = "downloading...";
anchor.style.display = "none";
document.body.appendChild(anchor);
setTimeout(function() {
anchor.click();
document.body.removeChild(anchor);
if(winMode===true){setTimeout(function(){ self.URL.revokeObjectURL(anchor.href);}, 250 );}
}, 66);
return true;
}
// handle non-a[download] safari as best we can:
if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
url=url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
if(!window.open(url)){ // popup blocked, offer direct download:
if(confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")){ location.href=url; }
}
return true;
}
//do iframe dataURL download (old ch+FF):
var f = document.createElement("iframe");
document.body.appendChild(f);
if(!winMode){ // force a mime that will download:
url="data:"+url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
}
f.src=url;
setTimeout(function(){ document.body.removeChild(f); }, 333);
}//end saver
if (navigator.msSaveBlob) { // IE10+ : (has Blob, but not a[download] or URL)
return navigator.msSaveBlob(blob, fileName);
}
if(self.URL){ // simple fast and modern way using Blob and URL:
saver(self.URL.createObjectURL(blob), true);
}else{
// handle non-Blob()+non-URL browsers:
if(typeof blob === "string" || blob.constructor===toString ){
try{
return saver( "data:" + mimeType + ";base64," + self.btoa(blob) );
}catch(y){
return saver( "data:" + mimeType + "," + encodeURIComponent(blob) );
}
}
// Blob but not URL support:
reader=new FileReader();
reader.onload=function(e){
saver(this.result);
};
reader.readAsDataURL(blob);
}
return true;
}; /* end download() */
}));
</script>
</body>
</html>