forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.vue
More file actions
123 lines (110 loc) · 4.13 KB
/
FileManager.vue
File metadata and controls
123 lines (110 loc) · 4.13 KB
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
<template>
<div>
<div v-if="loading">
<div class="spinner spinner-xl blue"></div>
</div>
<div class="filemanager" v-else>
<div class="header">
<div class="flex-none w-8"></div>
<div class="flex-1">Name</div>
<div class="flex-1 text-right">Size</div>
<div class="flex-1 text-right">Modified</div>
<div class="flex-none w-1/6">Actions</div>
</div>
<div class="row" v-for="folder in folders">
<div class="flex-none icon"><folder-icon/></div>
<div class="flex-1">{{folder.name}}</div>
<div class="flex-1 text-right text-grey-dark"></div>
<div class="flex-1 text-right text-grey-dark">{{formatDate(folder.modified)}}</div>
<div class="flex-none w-1/6"></div>
</div>
<div class="row" v-for="file in files">
<div class="flex-none icon">
<file-text-icon v-if="!file.symlink"/>
<link2-icon v-else/>
</div>
<div class="flex-1">{{file.name}}</div>
<div class="flex-1 text-right text-grey-dark">{{readableSize(file.size)}}</div>
<div class="flex-1 text-right text-grey-dark">{{formatDate(file.modified)}}</div>
<div class="flex-none w-1/6"></div>
</div>
</div>
</div>
</template>
<script>
import filter from 'lodash/filter';
import format from 'date-fns/format';
import { mapState } from 'vuex';
import { FileTextIcon, FolderIcon, Link2Icon } from 'vue-feather-icons';
export default {
name: 'file-manager-page',
components: { FileTextIcon, FolderIcon, Link2Icon },
computed: {
...mapState('server', ['server', 'credentials']),
},
data: function () {
return {
directory: '/',
loading: true,
files: [],
folders: [],
};
},
mounted: function () {
this.listDirectory();
},
methods: {
/**
* List the contents of a directory.
*/
listDirectory: function () {
window.axios.get(`${this.credentials.node}/v1/server/directory/${this.directory}`, {
headers: {
'X-Access-Server': this.server.uuid,
'X-Access-Token': this.credentials.key,
}
})
.then((response) => {
this.files = filter(response.data, function (o) {
return o.file;
});
this.folders = filter(response.data, function (o) {
return o.directory;
});
})
.catch(console.error)
.finally(() => {
this.loading = false;
});
},
/**
* Return the human readable filesize for a given number of bytes. This
* uses 1024 as the base, so the response is denoted accordingly.
*
* @param {Number} bytes
* @return {String}
*/
readableSize: function (bytes) {
if (Math.abs(bytes) < 1024) {
return `${bytes} Bytes`;
}
let u = -1;
const units = ['KiB', 'MiB', 'GiB', 'TiB'];
do {
bytes /= 1024;
u++;
} while (Math.abs(bytes) >= 1024 && u < units.length - 1);
return `${bytes.toFixed(1)} ${units[u]}`
},
/**
* Format the given date as a human readable string.
*
* @param {String} date
* @return {String}
*/
formatDate: function (date) {
return format(date, 'MMM D, YYYY [at] HH:MM');
},
}
};
</script>