From 92be4504ccb8f6d918013e5c33870858cd22376a Mon Sep 17 00:00:00 2001
From: Zephyrrus <krisztian1997@gmail.com>
Date: Sat, 4 Jul 2020 03:26:35 +0300
Subject: feat: refactor most of the album components to use store for
 presentation and actions

---
 src/site/pages/dashboard/admin/file/_id.vue | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'src/site/pages/dashboard/admin/file/_id.vue')

diff --git a/src/site/pages/dashboard/admin/file/_id.vue b/src/site/pages/dashboard/admin/file/_id.vue
index 5821292..5853770 100644
--- a/src/site/pages/dashboard/admin/file/_id.vue
+++ b/src/site/pages/dashboard/admin/file/_id.vue
@@ -130,6 +130,7 @@ export default {
 	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()
 			});
@@ -142,6 +143,7 @@ export default {
 		},
 		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()
 			});
-- 
cgit v1.2.3


From ad852de51a0d2dd5d29c08838d5a430c58849e74 Mon Sep 17 00:00:00 2001
From: Zephyrrus <krisztian1997@gmail.com>
Date: Wed, 8 Jul 2020 04:00:12 +0300
Subject: chore: linter the entire project using the new rules

---
 src/site/pages/dashboard/admin/file/_id.vue | 82 ++++++++++++++++++-----------
 1 file changed, 52 insertions(+), 30 deletions(-)

(limited to 'src/site/pages/dashboard/admin/file/_id.vue')

diff --git a/src/site/pages/dashboard/admin/file/_id.vue b/src/site/pages/dashboard/admin/file/_id.vue
index 5853770..34fcd01 100644
--- a/src/site/pages/dashboard/admin/file/_id.vue
+++ b/src/site/pages/dashboard/admin/file/_id.vue
@@ -9,74 +9,90 @@
 					<Sidebar />
 				</div>
 				<div class="column">
-					<h2 class="subtitle">File details</h2>
+					<h2 class="subtitle">
+						File details
+					</h2>
 					<hr>
 
 					<div class="columns">
 						<div class="column is-6">
-							<b-field label="ID"
+							<b-field
+								label="ID"
 								horizontal>
 								<span>{{ file.id }}</span>
 							</b-field>
 
-							<b-field label="Name"
+							<b-field
+								label="Name"
 								horizontal>
 								<span>{{ file.name }}</span>
 							</b-field>
 
-							<b-field label="Original Name"
+							<b-field
+								label="Original Name"
 								horizontal>
 								<span>{{ file.original }}</span>
 							</b-field>
 
-							<b-field label="IP"
+							<b-field
+								label="IP"
 								horizontal>
 								<span class="underline">{{ file.ip }}</span>
 							</b-field>
 
-							<b-field label="Link"
+							<b-field
+								label="Link"
 								horizontal>
-								<a :href="file.url"
+								<a
+									:href="file.url"
 									target="_blank">{{ file.url }}</a>
 							</b-field>
 
-							<b-field label="Size"
+							<b-field
+								label="Size"
 								horizontal>
 								<span>{{ formatBytes(file.size) }}</span>
 							</b-field>
 
-							<b-field label="Hash"
+							<b-field
+								label="Hash"
 								horizontal>
 								<span>{{ file.hash }}</span>
 							</b-field>
 
-							<b-field label="Uploaded"
+							<b-field
+								label="Uploaded"
 								horizontal>
 								<span><timeago :since="file.createdAt" /></span>
 							</b-field>
 						</div>
 						<div class="column is-6">
-							<b-field label="User Id"
+							<b-field
+								label="User Id"
 								horizontal>
 								<span>{{ user.id }}</span>
 							</b-field>
 
-							<b-field label="Username"
+							<b-field
+								label="Username"
 								horizontal>
 								<span>{{ user.username }}</span>
 							</b-field>
 
-							<b-field label="Enabled"
+							<b-field
+								label="Enabled"
 								horizontal>
 								<span>{{ user.enabled }}</span>
 							</b-field>
 
-							<b-field label="Registered"
+							<b-field
+								label="Registered"
 								horizontal>
 								<span><timeago :since="user.createdAt" /></span>
 							</b-field>
 
-							<b-field label="Files"
+							<b-field
+								label="Files"
 								horizontal>
 								<span>
 									<nuxt-link :to="`/dashboard/admin/user/${user.id}`">{{ user.fileCount }}</nuxt-link>
@@ -86,10 +102,16 @@
 					</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>
+						<button
+							class="button is-danger"
+							@click="promptBanIP">
+							Ban IP
+						</button>
+						<button
+							class="button is-danger"
+							@click="promptDisableUser">
+							Disable user
+						</button>
 					</div>
 				</div>
 			</div>
@@ -102,14 +124,14 @@ import Sidebar from '~/components/sidebar/Sidebar.vue';
 
 export default {
 	components: {
-		Sidebar
+		Sidebar,
 	},
 	middleware: ['auth', 'admin'],
 	data() {
 		return {
 			options: {},
 			file: null,
-			user: null
+			user: null,
 		};
 	},
 	async asyncData({ $axios, route }) {
@@ -117,13 +139,13 @@ export default {
 			const response = await $axios.$get(`file/${route.params.id}`);
 			return {
 				file: response.file ? response.file : null,
-				user: response.user ? response.user : null
+				user: response.user ? response.user : null,
 			};
 		} catch (error) {
 			console.error(error);
 			return {
 				file: null,
-				user: null
+				user: null,
 			};
 		}
 	},
@@ -132,12 +154,12 @@ export default {
 			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()
+				onConfirm: () => this.disableUser(),
 			});
 		},
 		async disableUser() {
 			const response = await this.$axios.$post('admin/users/disable', {
-				id: this.user.id
+				id: this.user.id,
 			});
 			this.$buefy.toast.open(response.message);
 		},
@@ -145,12 +167,12 @@ export default {
 			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()
+				onConfirm: () => this.banIP(),
 			});
 		},
 		async banIP() {
 			const response = await this.$axios.$post('admin/ban/ip', {
-				ip: this.file.ip
+				ip: this.file.ip,
 			});
 			this.$buefy.toast.open(response.message);
 		},
@@ -163,8 +185,8 @@ export default {
 
 			const i = Math.floor(Math.log(bytes) / Math.log(k));
 
-			return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
-		}
-	}
+			return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
+		},
+	},
 };
 </script>
-- 
cgit v1.2.3


From 0f66d807035d3e32a66c7dc9bf55fb3be99aedac Mon Sep 17 00:00:00 2001
From: Zephyrrus <krisztian1997@gmail.com>
Date: Fri, 10 Jul 2020 01:13:51 +0300
Subject: refactor: finish refactoring all the components to use vuex

---
 src/site/pages/dashboard/admin/file/_id.vue | 85 ++++++++++++-----------------
 1 file changed, 34 insertions(+), 51 deletions(-)

(limited to 'src/site/pages/dashboard/admin/file/_id.vue')

diff --git a/src/site/pages/dashboard/admin/file/_id.vue b/src/site/pages/dashboard/admin/file/_id.vue
index 34fcd01..89afa47 100644
--- a/src/site/pages/dashboard/admin/file/_id.vue
+++ b/src/site/pages/dashboard/admin/file/_id.vue
@@ -19,99 +19,101 @@
 							<b-field
 								label="ID"
 								horizontal>
-								<span>{{ file.id }}</span>
+								<span>{{ admin.file.id }}</span>
 							</b-field>
 
 							<b-field
 								label="Name"
 								horizontal>
-								<span>{{ file.name }}</span>
+								<span>{{ admin.file.name }}</span>
 							</b-field>
 
 							<b-field
 								label="Original Name"
 								horizontal>
-								<span>{{ file.original }}</span>
+								<span>{{ admin.file.original }}</span>
 							</b-field>
 
 							<b-field
 								label="IP"
 								horizontal>
-								<span class="underline">{{ file.ip }}</span>
+								<span class="underline">{{ admin.file.ip }}</span>
 							</b-field>
 
 							<b-field
 								label="Link"
 								horizontal>
 								<a
-									:href="file.url"
-									target="_blank">{{ file.url }}</a>
+									:href="admin.file.url"
+									target="_blank">{{ admin.file.url }}</a>
 							</b-field>
 
 							<b-field
 								label="Size"
 								horizontal>
-								<span>{{ formatBytes(file.size) }}</span>
+								<span>{{ formatBytes(admin.file.size) }}</span>
 							</b-field>
 
 							<b-field
 								label="Hash"
 								horizontal>
-								<span>{{ file.hash }}</span>
+								<span>{{ admin.file.hash }}</span>
 							</b-field>
 
 							<b-field
 								label="Uploaded"
 								horizontal>
-								<span><timeago :since="file.createdAt" /></span>
+								<span><timeago :since="admin.file.createdAt" /></span>
 							</b-field>
 						</div>
 						<div class="column is-6">
 							<b-field
 								label="User Id"
 								horizontal>
-								<span>{{ user.id }}</span>
+								<span>{{ admin.user.id }}</span>
 							</b-field>
 
 							<b-field
 								label="Username"
 								horizontal>
-								<span>{{ user.username }}</span>
+								<span>{{ admin.user.username }}</span>
 							</b-field>
 
 							<b-field
 								label="Enabled"
 								horizontal>
-								<span>{{ user.enabled }}</span>
+								<span>{{ admin.user.enabled }}</span>
 							</b-field>
 
 							<b-field
 								label="Registered"
 								horizontal>
-								<span><timeago :since="user.createdAt" /></span>
+								<span><timeago :since="admin.user.createdAt" /></span>
 							</b-field>
 
 							<b-field
 								label="Files"
 								horizontal>
 								<span>
-									<nuxt-link :to="`/dashboard/admin/user/${user.id}`">{{ user.fileCount }}</nuxt-link>
+									<nuxt-link :to="`/dashboard/admin/user/${admin.user.id}`">{{ admin.user.fileCount }}</nuxt-link>
 								</span>
 							</b-field>
 						</div>
 					</div>
 
 					<div class="mb2 mt2 text-center">
-						<button
-							class="button is-danger"
+						<b-button
+							v-if="admin.user.id !== auth.user.id"
+							type="is-danger"
 							@click="promptBanIP">
 							Ban IP
-						</button>
-						<button
-							class="button is-danger"
+						</b-button>
+						<b-button
+							v-if="admin.user.id !== auth.user.id"
+							type="is-danger"
 							@click="promptDisableUser">
 							Disable user
-						</button>
+						</b-button>
 					</div>
 				</div>
 			</div>
@@ -120,35 +122,22 @@
 </template>
 
 <script>
+import { mapState } from 'vuex';
 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 }) {
+	middleware: ['auth', 'admin', ({ route, store }) => {
 		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,
-			};
+			store.dispatch('admin/fetchFile', route.params.id);
+		} catch (e) {
+			// eslint-disable-next-line no-console
+			console.error(e);
 		}
-	},
+	}],
+	computed: mapState(['admin', 'auth']),
 	methods: {
 		promptDisableUser() {
 			this.$buefy.dialog.confirm({
@@ -157,11 +146,8 @@ export default {
 				onConfirm: () => this.disableUser(),
 			});
 		},
-		async disableUser() {
-			const response = await this.$axios.$post('admin/users/disable', {
-				id: this.user.id,
-			});
-			this.$buefy.toast.open(response.message);
+		disableUser() {
+			this.$handler.executeAction('admin/disableUser', this.user.id);
 		},
 		promptBanIP() {
 			this.$buefy.dialog.confirm({
@@ -170,11 +156,8 @@ export default {
 				onConfirm: () => this.banIP(),
 			});
 		},
-		async banIP() {
-			const response = await this.$axios.$post('admin/ban/ip', {
-				ip: this.file.ip,
-			});
-			this.$buefy.toast.open(response.message);
+		banIP() {
+			this.$handler.executeAction('admin/banIP', this.file.ip);
 		},
 		formatBytes(bytes, decimals = 2) {
 			if (bytes === 0) return '0 Bytes';
-- 
cgit v1.2.3

