-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
787 lines (720 loc) · 26.2 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>VueDisk</title>
<meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0" name="viewport" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<link rel="icon" type="image/png" href="icons/favico.png" />
<link rel="stylesheet" href="css/theme/index.css">
<link rel="stylesheet" href="fonts/Roboto/roboto.css">
<link rel="stylesheet" href="css/index.css">
<script src="js/vue.min.js"></script>
<script src="js/elementui.min.js"></script>
<script src="js/element.en.js"></script>
<script src="js/axios.min.js"></script>
<script src="js/cookies.min.js"></script>
<script src="js/vue-lazyload.js"></script>
<script src="js/v-img.min.js"></script>
<script src="/js/httpVueLoader.js"></script>
</head>
<body>
<div id="vapp">
<!-- FIRST TIME LOADER -->
<div v-show="firstTimeOpened" class="spinner"></div>
<!-- LOGIN SCREEN -->
<el-row v-cloak v-show="!firstTimeOpened && isLoggedIn == false" type="flex" class="row-bg" justify="center" style="margin-top:100px">
<el-col :xs="24" :sm="16" :md="12" :lg="8">
<el-card class="box-card">
<div slot="header" class="clearfix" style="text-align:center">
<span style="font-weight:bold">Login</span>
</div>
<el-form :label-position="'left'" label-width="80px" @submit.prevent.native>
<el-form-item label="Username">
<el-input v-model="username" @keyup.enter.native="login" type="text"></el-input>
</el-form-item>
<el-form-item label="Password">
<el-input v-model="password" @keyup.enter.native="login" type="password"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="login" @keyup.enter="login">Login</el-button>
</el-form-item>
</el-form>
</el-card>
</el-col>
</el-row>
<!-- FILE MANAGER SCREEN start -->
<el-container v-cloak class="container" v-bind:style="{maxWidth : pageWidth}" v-show="!firstTimeOpened && isLoggedIn == true">
<img v-if="isMobile" style="position:absolute;top:10px;right:10px;cursor: pointer;font-size:14px; font-weight: normal;" @click="logout()" src="icons/power_settings_new-24px.svg" alt="Logout">
<el-header class="text-center mainTitle">
<h1>File Manager
<span v-if="!isMobile" style="float:right;cursor: pointer;font-size:14px; font-weight: normal;" @click="logout()">Logout</span>
</h1>
</el-header>
<el-main>
<!-- ACTIONS BAR start-->
<el-row class="mPaddingLeft20" type="flex" class="row-bg" justify="space-between">
<el-col>
<div class="flex">
<div v-if="!isMobile">
<el-button size="small" @click="openLocalUploadDialog()" type="primary" icon="el-icon-upload">Upload</el-button>
</div>
<div v-if="isMobile">
<el-button size="small" @click="openLocalUploadDialog()" type="primary" icon="el-icon-upload"></el-button>
</div>
<div v-if="!isMobile">
<el-button type="primary" @click="openRemoteUploadDialog()" size="small" icon="el-icon-upload">Remote Upload</el-button>
</div>
<div>
<el-dropdown trigger="click" @command="handleCommand">
<el-button type="primary" size="small">
Actions<i class="el-icon-arrow-down el-icon--right"></i>
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="cut" :disabled="multipleSelection.length == 0">Cut</el-dropdown-item>
<el-dropdown-item command="copy" :disabled="multipleSelection.length == 0">Copy</el-dropdown-item>
<el-dropdown-item command="paste" :disabled="operation.parentPath.length == 0">Paste</el-dropdown-item>
<el-dropdown-item command="delete" :disabled="multipleSelection.length == 0">Delete</el-dropdown-item>
<el-dropdown-item command="rename" :disabled="multipleSelection.length != 1">Rename</el-dropdown-item>
<el-dropdown-item command="size" :disabled="multipleSelection.length == 0">Get Size</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<div v-if="!isMobile" style="display: inline-block">
<el-radio-group v-model="displayMode" size="small">
<el-radio label="list" border>List</el-radio>
<el-radio label="gallery" border>Gallery</el-radio>
</el-radio-group>
</div>
<div v-if="!isMobile"><i class="el-icon-refresh" style="font-weight: bold;font-size: 20px" @click="refresh()"></i>
</div>
<div style="flex: 1 1"></div>
<div>
<el-button style="float:right" type="primary" @click="addDirectory()" size="small" icon="el-icon-plus">New Folder</el-button>
</div>
</div>
</el-col>
</el-row>
<!-- ACTIONS BAR end -->
<!-- BREAD CRUMB BAR start-->
<el-row class="mPaddingLeft20" style="margin: 25px 0;">
<el-col :span="24">
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item>
<a @click="openDir('/')">Home</a>
</el-breadcrumb-item>
<el-breadcrumb-item v-for="(dir, index) in stack">
<a @click="openStack(index)">{{dir}}</a>
</el-breadcrumb-item>
</el-breadcrumb>
</el-col>
</el-row>
<!-- BREAD CRUMB BAR end-->
<!-- FILES LISTING start-->
<el-row class="mPaddingLeft5" type="flex" class="row-bg" justify="center">
<el-col :span="24">
<!-- FILES LISTING - LIST MODE start-->
<el-card v-show="displayMode == 'list'">
<el-table ref="multipleTable" :data="tableDataFinal" v-loading="isTableLoading" style="width: 100%" @selection-change="handleSelectionChange" size="medium" highlight-current-row>
<el-table-column type="selection" style="padding-left:0px !important" width="30">
</el-table-column>
<el-table-column label="Name">
<template slot-scope="scope">
<span v-if="scope.row.isDir" class="fonts" style="font-weight: 500;" @click="openDirFromList(scope.row.name)">{{ scope.row.name }}</span>
<span v-if="!scope.row.isDir" class="fonts" @click="download(scope.row.name)">{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column v-if="!isMobile" align="right" width="80">
<template slot-scope="scope">
<el-button v-if="!scope.row.isDir && isAudio(scope.row.name)" size="mini" @click="playAudio(scope.row.name)" style="margin-right:10px">Play</el-button>
<el-button v-if="!scope.row.isDir && isVideo(scope.row.name)" size="mini" @click="playVideo(scope.row.name)" style="margin-right:10px">Play</el-button>
<span v-if="!scope.row.isDir" style="margin-right: 10px">{{ scope.row.size }}</span>
</template>
</el-table-column>
</el-table>
<el-row type="flex" align="middle" class="row-bg" justify="space-between" style="margin-top: 20px">
<el-col style="text-align:right">
<el-checkbox v-model="hiddenFiles">Show Hidden Files</el-checkbox>
</el-col>
</el-row>
</el-card>
<!-- FILES LISTING - LIST MODE end-->
<!-- FILES LISTING - GALLERY MODE start-->
<div v-if="displayMode == 'gallery'">
<el-row style="margin-bottom:20px" v-if="totalCurrentDirs > 0">
<span style="font-family:Roboto;font-size:18px;font-weight:400;color:#555">Folders
</span>
</el-row>
<el-row v-if="totalCurrentDirs > 0">
<div v-for="row of this.tableDataFinal" @click="openDirFromList(row.name)" style="display: inline-block;margin:10px;cursor:pointer">
<div v-if="row.isDir" :title="row.name" style="width:200px;height:50px;border:1px solid #eee;font-size:13px;color:#444;padding-left:5px;margin:5px;border-radius:5px;display:table-cell;vertical-align:middle">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" style="width:20px;height:20px;fill:#555;margin:0 auto;margin-right:5px;float:left">
<path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z" />
<path d="M0 0h24v24H0z" fill="none" />
</svg>
<span style="display:inline-block;vertical-align:middle;font-size:15px;line-height:20px;color:#555;font-weight:500;max-width:175px;overflow:hidden;text-overflow:ellipsis;max-height:40px">{{row.name}}</span>
</div>
</div>
</el-row>
<el-row style="margin-bottom:20px" v-if="totalCurrentFiles > 0">
<span style="font-family:Roboto;font-size:18px;font-weight:400;color:#555">Files
</span>
</el-row>
<el-row v-if="totalCurrentFiles > 0" style="display: flex;flex-wrap: wrap;flex-flow: row wrap;justify-content: center;">
<img v-for="row of this.tableDataFinal" v-if="!row.isDir" v-lazy="'/apis/thumbnail.php?type=small&name=' + row.name + '&parent=' + encodeURIComponent(currentDir)" v-img="{group : 'gallery', title: row.name, src : '/apis/thumbnail.php?type=large&name=' + row.name + '&parent=' + encodeURIComponent(currentDir), sourceButton: 'true', sourceButtonDownloadLink: '/apis/download.php?path=' + (currentDir == '/' ? '/' : encodeURIComponent(currentDir) + '/') + row.name}" style="height:200px;margin: 5px;float:left" :title="row.name">
</el-row>
</div>
<!-- FILES LISTING - GALLERY MODE end-->
</el-col>
</el-row>
<!-- FILES LISTING end-->
</el-main>
</el-container>
<!-- FILE MANAGER SCREEN end -->
<!-- REMOTE FILE UPLOAD DIALOGUE start -->
<el-dialog v-cloak title="Remote File Upload" :visible.sync="remoteUploadDialog">
<el-form>
<el-form-item label="File Url" label-width="150">
<el-input v-model="remoteUrl" auto-complete="off"></el-input>
</el-form-item>
<el-form-item label="Name" label-width="150">
<el-input v-model="remoteUrlName" auto-complete="off"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="remoteUploadDialog = false;refresh()">Cancel</el-button>
<el-button type="primary" @click="remoteUpload()">Upload</el-button>
</span>
</el-dialog>
<!-- REMOTE FILE UPLOAD DIALOGUE end -->
<!-- VIDEO PLAYER DIALOGUE start -->
<el-dialog v-cloak :visible.sync="displayVideoPlayer">
<div style="width:100%;margin:0 auto;text-align:center">
<video width="400" controls ref="videoPlayer">
<source :src="videoSource" type="video/mp4"> Your browser does not support HTML5 video.
</video>
</div>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="closeVideoPlayer()">Close</el-button>
</span>
</el-dialog>
<!-- VIDEO PLAYER DIALOGUE end -->
<file-uploader v-on:refresh="refresh()" :bus="fileUploaderBus" v-bind:current-dir="currentDir"></file-uploader>
<!-- AUDIO PLAYER DIALOGUE start-->
<div v-cloak v-if="displayAudioPlayer && !firstTimeOpened" style="
position:fixed;
bottom:0;
width:100%;
height:45px;
padding-top:10px;
margin:auto;
text-align:center;
background: rgba(0, 0, 0, 0.1);
z-index:1000;">
<audio controls style="width:700px;" ref="audioPlayer">
<source :src="audioSource" /> Your browser does not support the audio element.
</audio>
<span style="position:absolute;color:black;padding-left:30px;top:18px;font-weight:bold;cursor:pointer" title="close" @click="closeAudioPlayer()">X</span>
</div>
<!-- AUDIO PLAYER DIALOGUE end-->
</div>
<script>
ELEMENT.locale(ELEMENT.lang.en);
Vue.use(VueLazyload);
new Vue({
el: '#vapp',
components: {
'file-uploader': httpVueLoader('/components/FileUploadComponent.html')
},
data: {
audioSource: '',
currentDir: '/',
dirBeforeLogout: '',
displayAudioPlayer: false,
displayMode: 'list',
displayVideoPlayer: false,
firstTimeOpened: true,
hiddenFiles: false,
isLoggedIn: Cookies.get("LAST_ACTIVITY") ? true : false,
isTableLoading: true,
multipleSelection: [],
operation: {
type: '',
parentPath: '',
selectedFiles: ''
},
password: '',
remoteUploadDialog: false,
remoteUrl: '',
remoteUrlName: '',
tableData: [],
totalCurrentDirs: 0,
totalCurrentFiles: 0,
username: '',
videoSource: '',
fileUploaderBus : new Vue(),
audioExtensions: ['mp3'],
videoExtensions: ['mp4'],
imageExtensions: ["jpeg", "jpg", "JPG", "JPEG", "ase", "art", "bmp", "blp", "cd5", "cit", "cpt", "cr2", "cut", "dds", "dib", "djvu", "egt", "exif", "gif", "gpl", "grf", "icns", "ico", "iff", "jng", "jfif", "jp2", "jps", "lbm", "max", "miff", "mng", "msp", "nitf", "ota", "pbm", "pc1", "pc2", "pc3", "pcf", "pcx", "pdn", "pgm", "PI1", "PI2", "PI3", "pict", "pct", "pnm", "pns", "ppm", "psb", "psd", "pdd", "psp", "px", "pxm", "pxr", "qfx", "raw", "rle", "sct", "sgi", "rgb", "int", "bw", "tga", "tiff", "tif", "vtf", "xbm", "xcf", "xpm", "3dv", "amf", "ai", "awg", "cgm", "cdr", "cmx", "dxf", "e2d", "egt", "eps", "fs", "gbr", "odg", "svg", "stl", "vrml", "x3d", "sxd", "v2d", "vnd", "wmf", "emf", "art", "xar", "png", "webp", "jxr", "hdp", "wdp", "cur", "ecw", "iff", "lbm", "liff", "nrrd", "pam", "pcx", "pgf", "sgi", "rgb", "rgba", "bw", "int", "inta", "sid", "ras", "sun", "tga"]
},
watch: {
audioSource() {
this.$refs['audioPlayer'].load();
},
videoSource() {
this.$refs['videoPlayer'].load();
}
},
computed: {
isMobile() {
if (screen.width <= 720) {
return true;
} else {
return false;
}
},
stack() {
var substring = this.currentDir;
if (this.currentDir == '/') {
return [];
}
substring = substring.substring(1);
return substring.split('/');
},
pageWidth() {
if (this.displayMode == 'gallery') {
return 'calc(100% - 120px)';
}
return '900px';
},
tableDataFinal() {
this.totalCurrentFiles = 0;
this.totalCurrentDirs = 0;
var arrDir = [];
for (var temp of this.tableData) {
if (temp.isDir && (this.hiddenFiles || !temp.name.startsWith('.'))) {
this.totalCurrentDirs++;
arrDir.push(temp);
}
}
var arrFile = [];
for (var temp of this.tableData) {
if (!temp.isDir && (this.hiddenFiles || !temp.name.startsWith('.'))) {
if (this.displayMode == 'list' || (this.displayMode == 'gallery' && this.isImage(temp.name))) {
this.totalCurrentFiles++;
arrFile.push(temp);
}
}
}
arrDir.sort((o1, o2) => {
return o1.name.localeCompare(o2.name);
});
arrFile.sort((o1, o2) => {
return o1.name.localeCompare(o2.name);
});
return arrDir.concat(arrFile);
}
},
created() {
this.addShortcutListeners();
this.extractUrlParam();
this.isLoggedIn = Cookies.get("LAST_ACTIVITY") ? true : false;
if (!this.isLoggedIn) {
this.firstTimeOpened = false;
return;
}
this.isLoggedIn = true;
this.refresh();
},
methods: {
// Add shortcut listeners
addShortcutListeners() {
document.addEventListener('keydown', (event) => {
if (!this.isLoggedIn) {
return;
}
let keyName = event.key;
if (keyName === 'Control') {
// do not alert when only Control key is pressed.
return;
}
if (event.ctrlKey) {
keyName = keyName.toUpperCase();
if (keyName == 'X') {
if (this.multipleSelection.length != 0) {
this.handleCommand('cut');
}
} else if (keyName == 'C') {
if (this.multipleSelection.length != 0) {
this.handleCommand('copy');
}
} else if (keyName == 'V') {
if (this.operation.parentPath.length != 0) {
this.handleCommand('paste');
}
}
// Even though event.key is not 'Control' (e.g., 'a' is pressed),
// event.ctrlKey may be true if Ctrl key is pressed at the same time.
// alert(`Combination of ctrlKey + ${keyName}`);
} else if (keyName == 'Delete') {
if (this.multipleSelection.length != 0) {
this.handleCommand('delete');
}
} else if (keyName == 'F2') {
if (this.multipleSelection.length == 1) {
this.handleCommand('rename');
}
} else if (event.altKey && keyName == 'N' || keyName == 'n') {
this.addDirectory();
}
}, false);
},
playAudio(name) {
this.displayAudioPlayer = true;
this.audioSource = '/apis/music.php?path=' + (this.currentDir == '/' ? '/' : encodeURIComponent(this.currentDir) + '/') + name;
},
playVideo(name) {
this.displayVideoPlayer = true;
this.videoSource = '/apis/download.php?path=' + (this.currentDir == '/' ? '/' : encodeURIComponent(this.currentDir) + '/') + name;
},
openLocalUploadDialog() {
this.fileUploaderBus.$emit("openLocalUploadDialog");
},
closeAudioPlayer() {
this.displayAudioPlayer = false;
this.audioSource = '';
this.$refs.audioPlayer.load();
},
closeVideoPlayer() {
this.displayVideoPlayer = false;
this.videoSource = '';
this.$refs.videoPlayer.load();
},
isImage(name) {
return this.imageExtensions.indexOf(name.substring(name.lastIndexOf('.') + 1)) != -1;
},
isAudio(name) {
return this.audioExtensions.indexOf(name.substring(name.lastIndexOf('.') + 1)) != -1;
},
isVideo(name) {
return this.videoExtensions.indexOf(name.substring(name.lastIndexOf('.') + 1)) != -1;
},
extractUrlParam() {
var paramsPath = location.search.substring(1);
if (paramsPath) {
var parameters = paramsPath.split("&");
if (parameters.length > 0) {
var firstParam = paramsPath;
if (firstParam.indexOf('=') != -1) {
firstParamVal = firstParam.split('=')[1];
if (firstParamVal) {
firstParamVal = unescape(firstParamVal);
if (firstParamVal) {
this.currentDir = firstParamVal;
}
}
}
}
}
},
login() {
if (!this.username || !this.password) {
this.$message({
message: 'Please fill username and password',
type: 'error',
center: true
});
return;
}
axios.post('/apis/signin.php', {
'username': this.username,
'password': this.password
}).then(result => {
if (result.data.status == 'success') {
Cookies.set('LAST_ACTIVITY', 'youcandeleteit', {
expires: 86400
}); // 1 day
this.isLoggedIn = true;
if (this.dirBeforeLogout) {
this.currentDir = this.dirBeforeLogout;
}
this.refresh();
} else {
this.password = '';
this.$message({
message: result.data.message,
type: 'error',
center: true
});
}
}).catch(error => {
this.$message({
message: 'Error while checking login details',
type: 'error',
center: true
});
});
},
logout() {
this.dirBeforeLogout = '';
window.history.replaceState('', 'File Manager', '?');
this.currentDir = '/';
this.tableData = [];
this.isTableLoading = false;
axios.post('/apis/signout.php');
Cookies.expire("LAST_ACTIVITY");
this.isLoggedIn = false;
this.firstTimeOpened = false;
},
openRemoteUploadDialog() {
this.remoteUrl = '';
this.remoteUrlName = '';
this.remoteUploadDialog = true;
},
setOpearation(type) {
this.operation.type = type;
this.operation.parentPath = this.currentDir;
this.operation.selectedFiles = this.multipleSelection;
},
handleCommand(command) {
if (command == 'cut') {
this.setOpearation('cut');
} else if (command == 'copy') {
this.setOpearation('copy');
} else if (command == 'paste') {
this.paste();
} else if (command == 'rename') {
this.rename();
} else if (command == 'size') {
this.fetchSize();
} else if (command == 'delete') {
this.delete();
}
},
fetchSize() {
var url = `/apis/size.php`;
axios.post(url, {
'parentDir': this.currentDir,
'files': JSON.stringify(this.multipleSelection)
}).then((response) => {
this.$message({
message: 'Size : ' + response.data,
center: true
});
}).catch(() => {
this.$message({
type: 'error',
message: 'Unable to fetch file(s) size',
center: true
});
});
},
paste() {
var url = `/apis/${this.operation.type}.php`;
axios.post(url, {
'sourceDir': this.operation.parentPath,
'files': JSON.stringify(this.operation.selectedFiles),
'destinationDir': this.currentDir
}).then((response) => {
this.refresh();
this.operation.parentPath = '';
}).catch(() => {
this.operation.parentPath = '';
this.$message({
type: 'error',
message: `Unable to ${this.operation.type} file(s)`,
center: true
});
});
},
rename() {
this.$prompt('Please enter new name', {
confirmButtonText: 'Ok',
cancelButtonText: 'Cancel',
inputValue: this.multipleSelection[0]
}).then(value => {
value = value.value;
if (value) {
var url = '/apis/rename.php';
axios.post(url, {
'parentDir': this.currentDir,
'newName': value,
'oldName': this.multipleSelection[0]
}).then((response) => {
this.refresh();
}).catch(() => {
this.$message({
type: 'error',
message: `Unable to rename file`,
center: true
});
});
}
}).catch(() => { });
},
delete() {
this.$confirm('Are you sure want to permanently delete ?', {
confirmButtonText: 'Yes',
cancelButtonText: 'No',
type: 'warning'
}).then(() => {
axios.post('/apis/delete.php', {
'parentDir': this.currentDir,
'files': JSON.stringify(this.multipleSelection)
}).then((response) => {
this.refresh();
}).catch(() => {
this.$message({
type: 'error',
message: 'Unable to delete files',
center: true
});
});
}).catch(() => { });
},
remoteUpload() {
this.remoteUploadDialog = false;
axios.post('/apis/remote-upload.php', {
'parentDir': this.currentDir,
'url': this.remoteUrl,
'filename': this.remoteUrlName
}).then((response) => {
this.$message({
message: response.data,
center: true
});
this.openDir(this.currentDir);
});
this.$message({
type: 'success',
message: 'Your file will soon be downloaded',
center: true
});
},
openStack(index) {
var path = '';
for (var i = 0; i <= index; i++) {
path = path + '/' + this.stack[i];
}
this.openDir(path);
},
addDirectory() {
this.$prompt('Please enter directory name', {
confirmButtonText: 'Add',
cancelButtonText: 'Cancel',
}).then(value => {
if (value) {
axios.post('/apis/dir-add.php', {
'dirname': value.value,
'parentPath': this.currentDir
})
.then((response) => {
this.$message({
type: 'success',
message: 'Directory Added',
center: true
});
this.refresh();
}).catch(() => {
this.$message({
type: 'error',
message: 'Unable to add directory',
center: true
});
});
}
}).catch(() => { });
},
refresh() {
this.openDir(this.currentDir);
},
handleSelectionChange(val) {
this.multipleSelection = val.map(obj => obj.name);
},
openDirFromList(name) {
if (this.currentDir == '/') {
this.openDir('/' + name);
} else {
this.openDir(this.currentDir + '/' + name);
}
},
openDir(path) {
this.isTableLoading = true;
window.history.replaceState('', 'File Manager', '?path=' + path);
axios.get('/apis/files-list.php?path=' + encodeURIComponent(path))
.then((response) => {
this.currentDir = path;
this.tableData = response.data;
this.isTableLoading = false;
this.firstTimeOpened = false;
})
.catch((error) => {
if (error.response.data.message == 'Login Required') {
this.logout();
this.dirBeforeLogout = path;
} else {
this.$message({
type: 'error',
message: error.response.data.message,
center: true
});
}
});
},
getThumbnailSmall(name) {
return
},
download(name) {
document.location = '/apis/download.php?path=' + encodeURIComponent((this.currentDir == '/' ? '/' : this.currentDir + '/') + name);
}
}
});
function formatSize(num, MAX) {
let suffix, d = num;
if ((d / 1073741824) >= 1) {
d = d / 1073741824;
// if max values less than 20 GB
if (MAX > 21474836480) {
d = Math.ceil(d);
} else {
d = d.toFixed(2);
}
suffix = " GB";
} else if ((d / 1048576) >= 1) {
d = d / 1048576;
if (MAX > 20971520) {
d = Math.ceil(d);
} else {
d = d.toFixed(1);
}
suffix = " MB";
} else if ((d / 1024) >= 1) {
d = d / 1024;
if (MAX > 20480) {
d = Math.ceil(d);
} else {
d = d.toFixed(1);
}
suffix = " KB";
} else {
d = Math.ceil(d);
suffix = " Bytes";
}
return d + suffix;
}
function parseTime(d) {
d = parseInt(d);
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
m = m + 1;
var hDisplay = h > 0 ? h + (h == 1 ? " Hour, " : " Hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " Minute " : " Minutes ") : "";
return hDisplay + mDisplay;
}
</script>
</body>
</html>