-
Notifications
You must be signed in to change notification settings - Fork 1
/
folderupload.html
949 lines (852 loc) · 25.2 KB
/
folderupload.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
<html>
<head>
<title>upload test</title>
<script>
var globallog = ""
var pagelog;
function synclog()
{
if(!pagelog)
pagelog = document.getElementById("pagelog");
pagelog.value = globallog;
pagelog.scrollTop = pagelog.scrollHeight;
}
function writelog(text,sync)
{
if(globallog.length > 32768)
globallog = globallog.substring(16384);
globallog += ""+text+"\n";
if(sync)synclog();
}
Object.keys = Object.keys || (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"),
DontEnums = [
'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty',
'isPrototypeOf', 'propertyIsEnumerable', 'constructor'
],
DontEnumsLength = DontEnums.length;
return function (o) {
if (typeof o != "object" && typeof o != "function" || o === null)
throw new TypeError("Object.keys called on a non-object");
var result = [];
for (var name in o) {
if (hasOwnProperty.call(o, name))
result.push(name);
}
if (hasDontEnumBug) {
for (var i = 0; i < DontEnumsLength; i++) {
if (hasOwnProperty.call(o, DontEnums[i]))
result.push(DontEnums[i]);
}
}
return result;
};
})();
function writeerror(e)
{
var text = "Exception: "
try{
text += "" + e;
}catch(e){}
try{
text += " " + e.name;
}catch(e){}
try{
text += " " + e.message;
}catch(e){}
try{
if(e.description)
text += " " + e.description;
}catch(e){}
try{
if(e.method)
text += " " + e.method;
}catch(e){}
try{
text += " " + e.fileName + ":" + (e.lineNumber || e.number) ;
}catch(e){}
try{
if(e.stack)
text += " " + e.stack;
}catch(e){}
// hack: rethrow error for onerror and browser-internal handler
try{
setTimeout(function(){throw(e);},100);
writelog(Object.keys(e), true);
}catch(e){}
writelog(text, true);
}
</script>
</head>
<body onerror="writelog(event, true);writelog(event.message, true);">
<style>
html, body {
height: 100%; }
html {
background-color: #222; }
body {
position: relative;
/*max-width: 1024px;
min-width: 768px;*/
min-width: 600px;
margin: 0 auto;
font: 12px sans-serif;
}
header {
color: #fff;
background-color: #000;
height: 24px;
overflow: hidden; }
.sidebar td {
color: #fff;
background-color: #000;
}
.sidebar a:link {
color: #FFA;
}
.sidebar a:visited {
color: #FFC;
}
.sidebar, .main {
-webkit-overflow-scrolling: touch;
position: absolute;
top: 24px;
bottom: 0; }
.sidebar {
overflow:scroll;
overflow-x:auto;
width: 50%;
background-color: #333;
left: 0; }
.main {
overflow: hidden;
background-color: #f5f5f5;
position: absolute;
left: 50%;
width: 50%;
right: 0;
/*padding: 20px;*/
padding-bottom:25px; }
</style>
<header><div style="position:absolute;overflow:hidden;color:white" id="pathdisplay"></div><div style="position:absolute;right:0px;overflow:hidden">
<input type="checkbox" id="enable_fileapi"/><label for="enable_fileapi" style="color:white;">Enable FileList API</label>
<input type="checkbox" id="enable_xhr"/><label for="enable_xhr" style="color:white;">Enable XHR</label>
<button id="mkdir" onclick="mkdirClick()">Create Directory</button>
<button id="mkfile" onclick="createFile();">Create File</button>
</div>
</header>
<div class="sidebar"><div id="filelist"></div><iframe src="/indexredir" width="100%" height="100%" style="border:0;padding:0;" loading="lazy" id="legacyframe"></iframe></div>
<div class="main" id="uploadcontainer">
<table border="0" height="100%">
<tr><td><form><label for="filesdir">Upload dir:</label><br />
<input id="filesdir" name=filesdir
type="file"
directory="directory"
multiple
size="4"
webkitdirectory="webkitdirectory" style="font:40% sans-serif;max-width:100px" disabled />
<input type="button" value="Upload" disabled id="upload" onclick="startUpload()" /></form></td><td style="vertical-align: top;">
<form id="legacyupload" method="POST" action="/legacyupload" encoding="multipart/form-data" enctype="multipart/form-data"><label for="file">Upload file:</label><br />
<input id="file" name="file"
type="file"
multiple size="4" style="font:40% sans-serif;max-width:100px" />
<input type="submit" value="Send" id="uploadlegacy"/></form></td>
<td style="vertical-align: top;"><form id="zipform" method="POST" action="/legacyzip" encoding="multipart/form-data" enctype="multipart/form-data"><label for="zipfile">Upload zip:</label><br />
<input id="zipfile" name="zipfile"
type="file"
size="4" style="font:40% sans-serif;max-width:100px" />
<input type="submit" value="Extract" id="uploadzip"/></form></td>
<td border="0" width="100%" cellspacing="0"></td><td border="0" width="0" cellspacing="0"></td></tr><tr>
<td height="100%" width="100%" colspan="4">
<div id="dropcontainer" style="border:1px solid black;width:100%;height:75%;">Drop here</div><textarea id="pagelog" style="width:100%;height:25%;resize:none;"></textarea>
</div>
</td><td border="0" cellspacing="0" style="width:0;border-color:#f5f5f5;border-width:0;padding:0;"><div style="height:200px;width:0;overflow:hidden;padding:0;" ><br/></div></td>
</tr></table></div>
<div id="editorcontainer" class="main" style="padding-bottom:40px;overflow:hidden;display:none">
<button onclick="saveEdit();">Save</button><button onclick="cancelEdit();">Cancel</button><br/>
<textarea id="editor" style="width:100%;height:100%;resize:none;"></textarea>
</div>
</div>
<!--[if IE]>
<script>
window.onresize = document.body.onload = function()
{
uploadContainer.style.height = document.body.clientHeight - 26;
if(oldFileList)
oldFileList.style.height = document.body.clientHeight - 26;
fileListContainer.parentNode.style.height = document.body.clientHeight - 26;
}
</script>
<![endif]-->
<script>
window.onerror = function(msg, url, lno) {
writelog("Error handler:" + "\n" +
"Error: " + msg + "\n" + "URL: " + url + "\n" +
"Line Number: " + lno, true);
return false; // let browser print error to
}
</script>
<script>
// ie
function parseJSON(text)
{
if("JSON" in window)
{
return JSON.parse(text);
}
else return eval("("+text+")");
}
if(('navigator' in window) && window.navigator && window.navigator.userAgent.indexOf("ELinks") >= 0)
{
writelog = alert;
XMLHttpRequest.prototype.open_orig = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(a,b,c)
{
this.open_orig(a,document.location.href + b.substring(1),c);
};
}
function getXMLHttpRequest()
{
var xhr = null;
if(window.XMLHttpRequest)
xhr = new XMLHttpRequest();
else if(window.ActiveXObject) { // poor alternative, but at least filelist and editing works
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
xhr.open("GET","/", true); // it may throw DLLError
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
writeerror(e);
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
writeerror(e);
}
}
}
else
{
writelog("Your browser doesn't support XMLHTTPRequest...", true);
}
return xhr;
}
var XMLHttpRequest_DONE = 4
var dropContainer = document.getElementById("dropcontainer")
dropContainer.ondragover = dropContainer.ondragenter = function(event) {
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
if(event && event.preventDefault)
event.preventDefault();
if(event.dataTransfer)
event.dataTransfer.dropEffect = 'copy';
return false;
};
dropContainer.ondrop = function(event) {
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
if(event && event.preventDefault)
event.preventDefault();
if('Promise' in window && event.dataTransfer && event.dataTransfer.items && event.dataTransfer.items[0].webkitGetAsEntry)
{
writelog("Drop event, using async mode", true);
processDTItemsAsync(event.dataTransfer.items).then(function(files){
processFiles(files);
});
}
else
{
writelog("Drop event, using sync mode (slow)", true);
processDTItems(event.dataTransfer);
}
return false;
};
function resolveFile(resolve, item, path, fileList)
{
item.file(function(file) {
file.filepath = path + file.name; //save full path
fileList.push(file);
resolve(file);
});
}
function resolveDir(resolve, item, path, fileList)
{
var dirReader = item.createReader();
dirReader.readEntries(function(entries){
var entriesPromises = [];
for (var i = 0; i < entries.length;i++)
entriesPromises.push(traverseItems(entries[i], (path ? path :"") + item.name + "/", fileList));
resolve(Promise.all(entriesPromises));
});
}
function resolveItem(resolve, item, path, fileList)
{
if (item.isFile)
resolveFile(resolve, item, path, fileList);
else if (item.isDirectory)
resolveDir(resolve, item, path, fileList);
}
function traverseItems(item, path, fileList)
{
return new Promise(function(resolve){
resolveItem(resolve, item, path, fileList);
});
}
function processDTItemsAsync(dataTransferItems) // do we ever need this???
{
var files = [];
return new Promise(function(resolve, reject){
var entriesPromises = [];
for (var i = 0; i < dataTransferItems.length;i++)
entriesPromises.push(traverseItems(dataTransferItems[i].webkitGetAsEntry(), "", files));
Promise.all(entriesPromises).then(function(entries){
resolve(files);
});
});
}
function traverseFileTree(item, path) {
path = path || "";
if (item.isFile) {
// Get file
item.file(function(file) {
file.filepath = path + file.name;
selectedfiles.push(file);
processFiles([]);
});
} else if (item.isDirectory) {
// Get folder contents
var dirReader = item.createReader();
dirReader.readEntries(function(entries) {
for (var i=0; i<entries.length; i++) {
traverseFileTree(entries[i], path + item.name + "/");
}
});
}
}
function processDTItems(dataTransfer)
{
var items = dataTransfer.items;
if(!items || !items[0].webkitGetAsEntry)
{
// this cannot handle folders at all
writelog("no DataTransder items, folders will fail...", true);
processFiles(dataTransfer.files);
return;
}
for (var i=0; i < items.length; i++) {
// this handles folders and files in async way, we'll update file list on every file (slow)
var item = dataTransfer.items[i].webkitGetAsEntry();
traverseFileTree(item);
}
}
var pendingfiles = [];
var selectedfiles = [];
var uploadingfiles = [];
var list_path = "";
function uploadFile(file)
{
uploadingfiles.push(file);
var req = getXMLHttpRequest();
var path = (file.filepath|| file.webkitRelativePath || file.name);
writelog("uploading:"+path);
req.open("PUT", "/files/"+list_path+(list_path.length >0?"/":"")+path, true);
req.onreadystatechange = function(){
//writelog("readyState("+path+"):"+req.readyState);
if (req.readyState === XMLHttpRequest_DONE) {
var status = req.status;
//writelog("status("+path+"):"+status);
if ((status === 0 || (status >= 200 && status < 400)) && req.responseText == 'OK' ) {
} else {
pendingfiles.push(file);
writelog("error:"+path, true);
}
var index = uploadingfiles.indexOf(file);
if(index >= 0)
uploadingfiles.splice(index, 1);
scheduleUpload();
}
}
req.send(file)
}
var last_update = new Date();
function updateStatus()
{
var now = new Date();
if(now - last_update > 400)
{
last_update = now;
var count = pendingfiles.length;
var status = "Files left: " + count + "\nUploading now:\n" ;
for(var i = 0; i < uploadingfiles.length; i++)
{
var file = uploadingfiles[i];
status += (file.filepath|| file.webkitRelativePath|| file.name) + "\n";
}
dropContainer.innerText = status;
synclog();
}
}
function scheduleUpload()
{
while(uploadingfiles.length < 16 && pendingfiles.length > 0)
{
uploadFile(pendingfiles.pop())
}
updateStatus();
if(uploadingfiles.length == 0 && pendingfiles.length == 0)
{
alert("upload done!");
resetSelection();
updateList();
}
}
function processFiles(files)
{
if(pendingfiles.length)
return;
if(selectedfiles.length)
selectedfiles = Array.prototype.concat(selectedfiles,Array.prototype.slice.call(files))
else if(files)
selectedfiles = Array.prototype.slice.call(files);
var len = selectedfiles.length;
uploadButton.disabled = false;
dropContainer.innerText = "" + len + " files selected, click \"Upload\" to start now!";
}
function startUpload()
{
pendingfiles = selectedfiles;
uploadButton.disabled = true;
if(oldFileList)
fileListContainer.removeChild(oldFileList);
oldFileList = null;
scheduleUpload();
}
function resetSelection()
{
dropContainer.innerText = "Drop here";
selectedFiles = [];
}
function delfile(path)
{
if(!confirm("Delete "+path))
return;
var req = getXMLHttpRequest();
req.open("DELETE", path, true);
req.onreadystatechange = function(){
//writelog("readyState("+path+"):"+req.readyState);
if (req.readyState === XMLHttpRequest.DONE) {
updateList();
}
}
req.send();
}
function folderWalk(name)
{
if(list_path.length)
list_path += '/';
list_path += name;
updateList();
}
function folderUp()
{
var i = list_path.lastIndexOf('/');
writelog(i, true);
list_path = i >= 0?list_path.substring(0,i):"";
updateList();
}
var oldFileList = null;
var fileListContainer = document.getElementById("filelist");
var pathDisplay = document.getElementById("pathdisplay");
var uploadButton = document.getElementById("upload");
var editorContainer = document.getElementById("editorcontainer");
var uploadContainer = document.getElementById("uploadcontainer");
function folderClick(event)
{
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
folderWalk(event.target.data);
}
function delClick(event)
{
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
delfile(event.target.data || event.srcElement.data);
}
var editpath = "";
function saveEdit()
{
var text = document.getElementById("editor").value;
writelog("Saving file: " + editpath, true);
var req = getXMLHttpRequest();
req.open("PUT", editpath, true);
req.onreadystatechange = function(){
writelog("readyState("+editpath+"):"+req.readyState);
if (req.readyState === XMLHttpRequest_DONE) {
var status = req.status;
//writelog("status("+path+"):"+status);
if ((status === 0 || (status >= 200 && status < 400))) {
editorContainer.style.display = 'none';
uploadContainer.style.display = 'block';
updateList();
}
}
synclog();
};
if('Blob' in window)
req.send(new Blob([text],{type:"text/plain"}));
else
req.send(text);
}
function editFile(path)
{
editpath = path;
writelog("Editing file: " + editpath, true);
var req = getXMLHttpRequest();
req.open("GET", editpath, true);
editorContainer.style.display = 'block';
uploadContainer.style.display = 'none';
req.onreadystatechange = function(){
writelog("edreadyState("+editpath+"):"+req.readyState);
if (req.readyState == XMLHttpRequest_DONE) {
var status = req.status;
writelog("edstatus():"+status);
if ((status === 0 || (status >= 200 && status < 400)) && req.responseText.length >= 0 && req.responseText.length < 65535) {
document.getElementById("editor").value = req.responseText;
}
}
synclog();
};
req.send("");
}
function editClick(event)
{
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
editFile(event.target.data);
}
function createFile()
{
editpath ="/files/"+list_path+(list_path.length >0?"/":"")+prompt("New file name", "");
editorContainer.style.display = 'block';
uploadContainer.style.display = 'none';
document.getElementById("editor").value = "";
}
function cancelEdit()
{
editorContainer.style.display = 'none';
uploadContainer.style.display = 'block';
}
function delDirClick(event)
{
}
function zipClick(event)
{
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
var a = document.createElement("a");
a.href = event.target.data;
a.appendChild(document.createTextNode("Download zip " + event.target.data));
a.target = "_blank";
dropContainer.appendChild(document.createElement("br"));
dropContainer.appendChild(a);
}
function mkdirClick()
{
var req = getXMLHttpRequest();
var path= prompt("Folder name", "");
if(!path || !path.length)
return;
req.open("MKCOL", "/files/"+list_path+(list_path.length >0?"/":"")+path+ "/", true);
req.onreadystatechange = function(){
if (req.readyState === XMLHttpRequest_DONE) {
var status = req.status;
writelog(status, true);
if ((status === 0 || (status >= 200 && status < 400))) {
updateList();
}
}
}
req.send("");
}
function moveClick(event)
{
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
var newName = prompt("New filename", event.target.data);
if(!newName || !newName.length)
return;
if(newName.indexOf("/") < 0)
newName = "/files/"+list_path+(list_path.length >0?"/":"")+newName;
var req = getXMLHttpRequest();
req.open("MOVE", event.target.data, true);
req.setRequestHeader("Destination", newName);
req.onreadystatechange = function(){
if (req.readyState === XMLHttpRequest_DONE) {
var status = req.status;
writelog(status, true);
if ((status === 0 || (status >= 200 && status < 400))) {
updateList();
}
}
}
req.send("");
}
var legacyframe = document.getElementById("legacyframe");
var enable_xhr = document.getElementById("enable_xhr");
var enable_fileapi = document.getElementById("enable_fileapi");
function updateList()
{
if(oldFileList)
fileListContainer.removeChild(oldFileList);
oldFileList = null;
var req = getXMLHttpRequest();
if(!req)
{
enable_xhr.checked = false;
enable_xhr.disabled = true;
}
if(!enable_xhr.checked)
{
legacyframe.style.display = "block";
legacyframe.src = "/index/"+list_path;
return;
}
if(list_path.length)
pathDisplay.innerText = list_path;
else
pathDisplay.innerText = "(root)";
writelog("Listing files: " + "/list/"+list_path, true);
try{
req.open("GET", "/list/"+list_path, true);
}
catch(e)
{
//enable_xhr.disabled = true;
enable_xhr.checked = false;
writeerror(e);
writelog("XHR disabled",true);
return;
}
req.onreadystatechange = function(){
if (req.readyState === XMLHttpRequest_DONE) {
var status = req.status;
writelog("status("+list_path+"):"+status, true);
try{
if ((status === -1 || status === 0 || (status >= 200 && status < 400))) {
var tbl = document.createElement("table");
tbl.setAttribute("border", "2");
var tbd = document.createElement("tbody");
var row = document.createElement("tr");
var cell = document.createElement("td");
cell.width = "100%";
if(list_path.length)
{
cell.appendChild(document.createTextNode(".."))
cell.onclick = folderUp;
}
else
cell.appendChild(document.createTextNode("(root)"));
row.appendChild(cell);
cell = document.createElement("td");
cell.appendChild(document.createTextNode("<up>"));
row.appendChild(cell);
tbd.appendChild(row);
//var str = "<a onclick=\"folderUp();\">..</a><br>"
var arr = parseJSON(req.responseText);
for(var i = 0; i < arr.length; i++)
{
var item = arr[i];
if(item.type == 1)
{
row = document.createElement("tr");
cell = document.createElement("td");
link = document.createElement("a");
link.appendChild(document.createTextNode(item.name));
link.href="/files/"+list_path+(list_path.length >0?"/":"")+item.name;
link.target="_blank";
cell.appendChild(link)
row.appendChild(cell);
cell = document.createElement("td");
cell.appendChild(document.createTextNode(item.size));
row.appendChild(cell);
cell = document.createElement("td");
link = document.createElement("button");
link.data = "/files/"+list_path+(list_path.length >0?"/":"")+item.name;
link.onclick = moveClick;
link.appendChild(document.createTextNode("mv"));
cell.appendChild(link);
row.appendChild(cell);
cell = document.createElement("td");
link = document.createElement("button");
link.data = "/files/"+list_path+(list_path.length >0?"/":"")+item.name;
link.onclick = delClick;
link.appendChild(document.createTextNode("del"));
cell.appendChild(link);
row.appendChild(cell);
cell = document.createElement("td");
link = document.createElement("button");
link.data = "/files/"+list_path+(list_path.length >0?"/":"")+item.name;
if(item.size < 65536)
link.onclick = editClick;
else
link.disabled = true;
link.appendChild(document.createTextNode("ed"));
cell.appendChild(link);
row.appendChild(cell);
tbd.appendChild(row);
}
//str += "<a href=\"/files/"+list_path+(list_path.length >0?"/":"")+item.name+"\">"+item.name+" ("+item.size+")</a><a onclick=\"delfile('/files/"+list_path+(list_path.length >0?"/":"")+item.name+"')\">del</a><br>";
else if(item.type == 0)
{
row = document.createElement("tr");
cell = document.createElement("td");
link = document.createElement("a");
link.onclick = folderClick;
link.data = item.name;
link.appendChild(document.createTextNode(item.name));
cell.appendChild(link);
row.appendChild(cell);
cell = document.createElement("td");
cell.appendChild(document.createTextNode("<dir>"));
row.appendChild(cell);
cell = document.createElement("td");
link = document.createElement("button");
link.data = "/files/"+list_path+(list_path.length >0?"/":"")+item.name;
link.onclick = moveClick;
link.appendChild(document.createTextNode("mv"));
cell.appendChild(link);
row.appendChild(cell);
cell = document.createElement("td");
link = document.createElement("button");
link.data = "/files/"+list_path+(list_path.length >0?"/":"")+item.name;
link.onclick = delDirClick;
link.appendChild(document.createTextNode("del"));
cell.appendChild(link);
row.appendChild(cell);
cell = document.createElement("td");
link = document.createElement("button");
link.data = "/zip/"+list_path+(list_path.length >0?"/":"")+item.name+".zip";
link.onclick = zipClick;
link.appendChild(document.createTextNode("zip"));
cell.appendChild(link);
row.appendChild(cell);
tbd.appendChild(row);
}
//str += "<a onclick=\"folderWalk('"+item.name+"');\">"+item.name+"</a><br>";
}
tbl.appendChild(tbd);
//document.getElementById("filelist").innerHTML=str;
legacyframe.style.display = "none";
fileListContainer.appendChild(tbl);
//fileListContainer.parentNode.removeChild(document.getElementById("legacyframe"))
oldFileList = tbl;
} else {
}
}catch(e){
writeerror(e);legacyframe.style.display = "block";}
}
}
req.send("");
}
enable_xhr.checked = true;
enable_xhr.onclick = updateList;
var filesdir = document.getElementById("filesdir")
filesdir.onchange = function(event) {
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
processFiles(event.target.files);
};
function uploadZip()
{
if(!enable_fileapi.checked)
{
try
{
document.getElementById("zipform").submit();
}
catch(e){writeerror(e);document.getElementById("uploadzip").onclick = null;}
return true;
}
var req = getXMLHttpRequest();
req.open("PUT", "/zip/"+list_path+ (list_path.length >0?"/":""), true);
document.getElementById("uploadzip").disabled = true;
req.onreadystatechange = function(){
if (req.readyState === XMLHttpRequest_DONE) {
document.getElementById("uploadzip").disabled = false;
var status = req.status;
writelog("status(zip:"+list_path+"):"+status, true);
if ((status === -1 || status === 0 || (status >= 200 && status < 400))) {
alert(req.responseText);
writelog(req.responseText);
updateList();
}
}
}
req.send(document.getElementById("zipfile").files[0]);
return false;
}
function updateFileAPI()
{
var uploadzip = document.getElementById("uploadzip");
if(enable_fileapi.checked)
{
filesdir.disabled = false;
document.getElementById("uploadlegacy").style.display = "none";
uploadzip.disabled = document.getElementById("zipfile").files && document.getElementById("zipfile").files.length == 0;
uploadzip.onclick = uploadZip;
uploadButton.unclick = startUpload;
}
else
{
filesdir.disabled = true;
uploadButton.disabled = true;
document.getElementById("uploadlegacy").style.display = "block";
uploadzip.disabled = false;
}
}
try
{
if("files" in filesdir && filesdir.files !== undefined)
{
enable_fileapi.checked = true;
enable_fileapi.disabled = false;
}
else
{
enable_fileapi.checked = false;
enable_fileapi.disabled = true;
writelog("Your browser does not support FileList API, POST request will be used");
writelog("Use ZIP files to upload folders", true);
}
updateList();
}catch(e){writeerror(e);}
try{
updateFileAPI();
}catch(e){writeerror(e);}
try{
enable_fileapi.onclick = updateFileAPI;
document.getElementById("file").onchange = function(event) {
if(!event) event = window.event;
if(!event.target)
event.target = event.srcElement;
processFiles(event.target.files);
};
document.getElementById("zipfile").onchange = function(event) {
if(enable_fileapi.checked)
document.getElementById("uploadzip").disabled = document.getElementById("zipfile").files.length == 0;
else
document.getElementById("uploadzip").disabled = false;
};
}catch(e){writeerror(e);}
</script>
</body>
</head>