From 41b81fee429662e7c7701a3f32f1ab40ee87e931 Mon Sep 17 00:00:00 2001 From: tobinio Date: Tue, 18 Jun 2024 16:22:52 +0200 Subject: [PATCH] feat: modpack stats --- components/Charts.vue | 10 ++++-- layouts/default.vue | 45 +++++++++++++++++++------ pages/{ => [type]}/counts/[mode].vue | 3 +- pages/{ => [type]}/downloads/[mode].vue | 3 +- server/api/counts.ts | 6 ---- server/api/downloads.ts | 7 ---- server/api/stats.ts | 14 ++++++++ server/utils/api/stats.ts | 12 +++---- server/utils/fetchData.ts | 4 +-- server/utils/statistics.ts | 29 +++++++++++++--- 10 files changed, 91 insertions(+), 42 deletions(-) rename pages/{ => [type]}/counts/[mode].vue (69%) rename pages/{ => [type]}/downloads/[mode].vue (68%) delete mode 100644 server/api/counts.ts delete mode 100644 server/api/downloads.ts create mode 100644 server/api/stats.ts diff --git a/components/Charts.vue b/components/Charts.vue index 3e367bd..4ae3162 100644 --- a/components/Charts.vue +++ b/components/Charts.vue @@ -2,9 +2,15 @@ import {Bar} from 'vue-chartjs' import type {StatExport} from "~/server/utils/api/stats"; -const props = defineProps<{ url: string, mode: string, explanation: string }>(); +const props = defineProps<{ stat: string, type: string, mode: string, explanation: string }>(); -const {data} = await useFetch(props.url, {query: {mode: props.mode}}); +const {data} = await useFetch("/api/stats", { + query: { + mode: props.mode, + type: props.type, + stat: props.stat + } +}); let downloadData = computed(() => { if (data.value) { return data.value diff --git a/layouts/default.vue b/layouts/default.vue index 0e4e9ae..650d3f7 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -5,16 +5,28 @@ async function onUpdateData() { await $fetch("/api/update") } -const downloadUrls = [ - {title: "Major Versions", url: "/downloads/major"}, - {title: "Minor Versions", url: "/downloads/minor"}, - {title: "All Versions", url: "/downloads/all"}, +const modDownloadUrls = [ + {title: "Major Versions", url: "/mod/downloads/major"}, + {title: "Minor Versions", url: "/mod/downloads/minor"}, + {title: "All Versions", url: "/mod/downloads/all"}, ] -const countUrls = [ - {title: "Major Versions", url: "/counts/major"}, - {title: "Minor Versions", url: "/counts/minor"}, - {title: "All Versions", url: "/counts/all"}, +const modCountUrls = [ + {title: "Major Versions", url: "/mod/counts/major"}, + {title: "Minor Versions", url: "/mod/counts/minor"}, + {title: "All Versions", url: "/mod/counts/all"}, +] + +const modpackDownloadUrls = [ + {title: "Major Versions", url: "/modpack/downloads/major"}, + {title: "Minor Versions", url: "/modpack/downloads/minor"}, + {title: "All Versions", url: "/modpack/downloads/all"}, +] + +const modpackCountUrls = [ + {title: "Major Versions", url: "/modpack/counts/major"}, + {title: "Minor Versions", url: "/modpack/counts/minor"}, + {title: "All Versions", url: "/modpack/counts/all"}, ] @@ -25,8 +37,14 @@ const countUrls = [ Modrinth Statistics