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
|
<style lang="scss" scoped>
.underline { text-decoration: underline; }
</style>
<template>
<section class="section is-fullheight dashboard">
<div class="container">
<div class="columns">
<div class="column is-narrow">
<Sidebar />
</div>
<div class="column">
<h2 class="subtitle">
File details
</h2>
<hr>
<div class="columns">
<div class="column is-6">
<b-field
label="ID"
horizontal>
<span>{{ file.id }}</span>
</b-field>
<b-field
label="Name"
horizontal>
<span>{{ file.name }}</span>
</b-field>
<b-field
label="Original Name"
horizontal>
<span>{{ file.original }}</span>
</b-field>
<b-field
label="IP"
horizontal>
<span class="underline">{{ file.ip }}</span>
</b-field>
<b-field
label="Link"
horizontal>
<a
:href="file.url"
target="_blank">{{ file.url }}</a>
</b-field>
<b-field
label="Size"
horizontal>
<span>{{ formatBytes(file.size) }}</span>
</b-field>
<b-field
label="Hash"
horizontal>
<span>{{ file.hash }}</span>
</b-field>
<b-field
label="Uploaded"
horizontal>
<span><timeago :since="file.createdAt" /></span>
</b-field>
</div>
<div class="column is-6">
<b-field
label="User Id"
horizontal>
<span>{{ user.id }}</span>
</b-field>
<b-field
label="Username"
horizontal>
<span>{{ user.username }}</span>
</b-field>
<b-field
label="Enabled"
horizontal>
<span>{{ user.enabled }}</span>
</b-field>
<b-field
label="Registered"
horizontal>
<span><timeago :since="user.createdAt" /></span>
</b-field>
<b-field
label="Files"
horizontal>
<span>
<nuxt-link :to="`/dashboard/admin/user/${user.id}`">{{ user.fileCount }}</nuxt-link>
</span>
</b-field>
</div>
</div>
<div class="mb2 mt2 text-center">
<button
class="button is-danger"
@click="promptBanIP">
Ban IP
</button>
<button
class="button is-danger"
@click="promptDisableUser">
Disable user
</button>
</div>
</div>
</div>
</div>
</section>
</template>
<script>
import Sidebar from '~/components/sidebar/Sidebar.vue';
export default {
components: {
Sidebar,
},
middleware: ['auth', 'admin'],
data() {
return {
options: {},
file: null,
user: null,
};
},
async asyncData({ $axios, route }) {
try {
const response = await $axios.$get(`file/${route.params.id}`);
return {
file: response.file ? response.file : null,
user: response.user ? response.user : null,
};
} catch (error) {
console.error(error);
return {
file: null,
user: null,
};
}
},
methods: {
promptDisableUser() {
this.$buefy.dialog.confirm({
type: 'is-danger',
message: 'Are you sure you want to disable the account of the user that uploaded this file?',
onConfirm: () => this.disableUser(),
});
},
async disableUser() {
const response = await this.$axios.$post('admin/users/disable', {
id: this.user.id,
});
this.$buefy.toast.open(response.message);
},
promptBanIP() {
this.$buefy.dialog.confirm({
type: 'is-danger',
message: 'Are you sure you want to ban the IP this file was uploaded from?',
onConfirm: () => this.banIP(),
});
},
async banIP() {
const response = await this.$axios.$post('admin/ban/ip', {
ip: this.file.ip,
});
this.$buefy.toast.open(response.message);
},
formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
},
},
};
</script>
|