forked from jameszah/CameraWebServerRecorder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathESPxWebFlMgrWp.h
541 lines (457 loc) · 12.5 KB
/
ESPxWebFlMgrWp.h
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
// mods by James Zahary Dec 28, 2021 https://github.com/jameszah/ESPxWebFlMgr
// Jan 12, 2022 - adds dates/times to display
// based on https://github.com/holgerlembke/ESPxWebFlMgr
// inline guard. Did I mention that c/c++ is broken by design?
#ifndef ESPxWebFlMgrWp_h
#define ESPxWebFlMgrWp_h
// this file has been created by makeESPxWebFlMgrWp\do.cmd
//*****************************************************************************************************
static const char ESPxWebFlMgrWpindexpage[] PROGMEM = R"==x==(
<!DOCTYPE html>
<html lang="en">
<head>
<title>FileManager</title>
<meta charset="utf-8"/>
<link rel="stylesheet" type="text/css" href="/bg.css">
<link rel="stylesheet" type="text/css" href="/fm.css">
<script src="/fm.js"></script>
<script src="/gzipper.js"></script>
</head>
<body class="background">
<div id="gc">
<div class="o1"> </div>
<div class="o2"> </div>
<div class="o3" id="o3"> </div>
<div class="o4"> </div>
<div class="m1">
<div class="s11"> </div>
<div class="s12">
<div class="s13 background"> </div>
</div>
</div>
<div class="m2" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);">
File<br />
Drop<br />
Zone<br />
</div>
<div class="m3">
<div class="s31"> </div>
<div class="s32">
<div class="s33 background"> </div>
</div>
</div>
<div class="u1"> </div>
<div class="u2" onclick="downloadall();">Download all files</div>
<div class="u3" id="msg">Loading...</div>
<div class="u4"> </div>
<div class="c" id="fi">
File list should appear here.
</div>
</div>
</body>
</html>
)==x==";
static const char ESPxWebFlMgrWpjavascript[] PROGMEM = R"==x==(
function compressurlfile(source) {
msgline("Fetching file...");
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
var data = this.responseText;
var gzip = require('gzip-js'), options = { level: 9, name: source, timestamp: parseInt(Date.now() / 1000, 10) };
var out = gzip.zip(data, options);
var bout = new Uint8Array(out); // out is 16 bits...
msgline("Sending compressed file...");
var sendback = new XMLHttpRequest();
sendback.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
getfileinsert();
}
};
sendback.open('POST', '/r');
var formdata = new FormData();
var blob = new Blob([bout], { type: "application/octet-binary" });
formdata.append(source + '.gz', blob, source + '.gz');
sendback.send(formdata);
}
};
request.open('GET', source, true);
request.send(null);
}
var subdir;
function getfileinsert() {
msgline("Fetching files infos...");
subdir = '/';
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
var res = this.responseText.split("##");
document.getElementById('fi').innerHTML = res[0];
document.getElementById("o3").innerHTML = res[1];
msgline("");
}
};
request.open('GET', '/i', true);
request.send(null);
}
function getfileinsert2(strddd) {
msgline("Fetching files infos...");
subdir = strddd;
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
var res = this.responseText.split("##");
document.getElementById('fi').innerHTML = res[0];
document.getElementById("o3").innerHTML = res[1];
msgline("");
}
};
request.open('GET', '/i?subdir=' + strddd, true); // must send the subdir variable to get that folder //jz
request.send(null);
}
function executecommand(command) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
getfileinsert2(subdir);
}
};
xhr.open('GET', '/c?' + command, true);
xhr.send(null);
}
function downloadfile(filename) {
window.location.href = "/c?dwn=" + filename;
}
function opendirectory(filename) {
getfileinsert2(filename);
}
function deletefile(filename) {
if (confirm("Really delete " + filename)) {
msgline("Refresh when done deleting..."); //jz msgline("Please wait. Delete in progress...");
executecommand("del=" + filename);
}
}
function renamefile(filename) {
var newname = prompt("new name for " + filename, filename);
if (newname != null) {
msgline("Refresh when done renaming ..."); //jz msgline("Please wait. Rename in progress...");
executecommand("ren=" + filename + "&new=" + newname);
}
}
var editxhr;
function editfile(filename) {
msgline("Please wait. Creating editor...");
editxhr = new XMLHttpRequest();
editxhr.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
document.getElementById('fi').innerHTML = editxhr.responseText;
document.getElementById("o3").innerHTML = "Edit " + filename;
msgline("");
}
};
editxhr.open('GET', '/e?edit=' + filename, true);
editxhr.send(null);
}
function sved(filename) {
var content = document.getElementById('tect').value;
// utf-8
content = unescape(encodeURIComponent(content));
var xhr = new XMLHttpRequest();
xhr.open("POST", "/r", true);
var boundary = '-----whatever';
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
var body = "" +
'--' + boundary + '\r\n' +
'Content-Disposition: form-data; name="uploadfile"; filename="' + filename + '"' + '\r\n' +
'Content-Type: text/plain' + '\r\n' +
'' + '\r\n' +
content + '\r\n' +
'--' + boundary + '--\r\n' + // \r\n fixes upload delay in ESP8266WebServer
'';
// ajax does not do xhr.setRequestHeader("Content-length", body.length);
xhr.onreadystatechange = function () {
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
getfileinsert();
}
}
xhr.send(body);
}
function abed() {
getfileinsert();
}
var uploaddone = true; // hlpr for multiple file uploads
function uploadFile(file, islast) {
uploaddone = false;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
// console.log(xhr.status);
var DONE = this.DONE || 4;
if (this.readyState === DONE) {
if (islast) {
getfileinsert2(subdir);
console.log('last file');
}
uploaddone = true;
}
};
xhr.open('POST', '/r');
var formdata = new FormData();
//var newname = subdir + '/' + file.name; //jz didnt work, so do it in c++
//file.name = newname;
formdata.append('uploadfile', file);
// not sure why, but with that the upload to esp32 is stable.
formdata.append('dummy', 'dummy');
xhr.send(formdata);
}
var globaldropfilelisthlpr = null; // read-only-list, no shift()
var transferitem = 0;
var uploadFileProzessorhndlr = null;
function uploadFileProzessor() {
if (uploaddone) {
if (transferitem==globaldropfilelisthlpr.length) {
clearInterval(uploadFileProzessorhndlr);
} else {
var file = globaldropfilelisthlpr[transferitem];
msgline("Please wait. Transferring file "+file.name+"...");
console.log('process file ' + file.name);
transferitem++;
uploadFile(file,transferitem==globaldropfilelisthlpr.length);
}
}
}
/*
function dropHandlerALT(ev) {
console.log('File(s) dropped');
document.getElementById('msg').innerHTML = "Please wait. Transferring file...";
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
if (ev.dataTransfer.items) {
// Use DataTransferItemList interface to access the file(s)
for (var i = 0; i < ev.dataTransfer.items.length; i++) {
// If dropped items aren't files, reject them
if (ev.dataTransfer.items[i].kind === 'file') {
var file = ev.dataTransfer.items[i].getAsFile();
uploadFile(file);
console.log('.1. file[' + i + '].name = ' + file.name);
}
}
} else {
// Use DataTransfer interface to access the file(s)
for (var i = 0; i < ev.dataTransfer.files.length; i++) {
console.log('.2. file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
}
}
}
*/
function dropHandler(ev) {
console.log('File(s) dropped');
globaldropfilelisthlpr = ev.dataTransfer;
transferitem = 0;
msgline("Please wait. Transferring file...");
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
if (ev.dataTransfer.items) {
var data = ev.dataTransfer;
globaldropfilelisthlpr = data.files;
uploadFileProzessorhndlr = setInterval(uploadFileProzessor,1000);
console.log('Init upload list.');
} else {
// Use DataTransfer interface to access the file(s)
for (var i = 0; i < ev.dataTransfer.files.length; i++) {
console.log('.2. file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
}
}
}
function dragOverHandler(ev) {
console.log('File(s) in drop zone');
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
}
function msgline(msg) {
document.getElementById('msg').innerHTML = msg;
}
function downloadall() {
msgline("Sending all files in one zip.");
window.location.href = "/c?za=all";
msgline("");
}
//->
window.onload = getfileinsert;
)==x==";
//*****************************************************************************************************
static const char ESPxWebFlMgrWpcss[] PROGMEM = R"==g==(
div {
margin: 1px;
padding: 0px;
font-family: 'Segoe UI', Verdana, sans-serif;
}
#gc {
display: grid;
grid-template-columns: 80px 25% auto 30px;
grid-template-rows: 20px 30px auto 30px 20px;
grid-template-areas: "o1 o2 o3 o4" "m1 c c c" "m2 c c c" "m3 c c c" "u1 u2 u3 u4";
}
.o1 {
grid-area: o1;
background-color: #9999CC;
border-top-left-radius: 20px;
margin-bottom: 0px;
}
.o2 {
grid-area: o2;
background-color: #9999FF;
margin-bottom: 0px;
}
.o3 {
grid-area: o3;
background-color: #CC99CC;
margin-bottom: 0px;
white-space: nowrap;
}
.o4 {
grid-area: o4;
background-color: #CC6699;
border-radius: 0 10px 10px 0;
margin-bottom: 0px;
}
.m1 {
grid-area: m1;
margin-top: 0px;
background-color: #9999CC;
display: grid;
grid-template-columns: 60px 20px;
grid-template-rows: 20px;
grid-template-areas: "s11 s12";
}
.s12 {
margin: 0px;
background-color: #9999CC;
}
.s13 {
margin: 0px;
border-top-left-radius: 20px;
height: 30px;
}
.m2 {
display: flex;
justify-content: center;
align-items: center;
grid-area: m2;
background-color: #CC6699;
width: 60px;
}
.m3 {
grid-area: m3;
margin-bottom: 0px;
background-color: #9999CC;
display: grid;
grid-template-columns: 60px 20px;
grid-template-rows: 20px;
grid-template-areas: "s31 s32";
}
.s32 {
margin: 0px;
background-color: #9999CC;
}
.s33 {
margin: 0px;
border-bottom-left-radius: 20px;
height: 30px;
}
.u1 {
grid-area: u1;
background-color: #9999CC;
border-bottom-left-radius: 20px;
margin-top: 0px;
}
.u2 {
grid-area: u2;
cursor: pointer;
background-color: #CC6666;
margin-top: 0px;
padding-left: 10px;
vertical-align: middle;
font-size: 80%;
}
.u2:hover {
background-color: #9999FF;
color: white;
}
.u3 {
grid-area: u3;
padding-left: 10px;
background-color: #FF9966;
font-size: 80%;
margin-top: 0px;
}
.u4 {
grid-area: u4;
background-color: #FF9900;
border-radius: 0 10px 10px 0;
margin-top: 0px;
}
.c {
grid-area: c;
}
#fi .b {
background-color: Transparent;
border: 1px solid #9999FF;
border-radius: 1px;
padding: 0px;
width: 30px;
cursor: pointer;
}
#fi .b:hover {
background-color: #9999FF;
color: white;
}
.cc {
width: min-content;
margin: 10px 0px;
}
.gc div {
padding: 1px;
}
.ccg {
height: 1.5em;
background-color: #A5A5FF;
}
.ccu {
height: 1.5em;
background-color: #FE9A00;
}
.ccd {
height: 1.5em;
background-color: #e8e2d8;
}
.ccl {
border-radius: 5px 0 0 5px;
cursor: pointer;
}
.ccl:hover {
border-radius: 5px 0 0 5px;
color: white;
cursor: pointer;
}
.ccr {
border-radius: 0 5px 5px 0;
}
.cct {
text-align: right;
}
.ccz {
text-align: right;
}
.gc {
display: grid;
grid-template-columns: repeat(4, max-content);
}
)==g==";
#endif