From 910a6ab157bee6ee028af35de05cf8edb1b49f32 Mon Sep 17 00:00:00 2001 From: upsiflu Date: Thu, 13 Feb 2025 11:55:57 +0100 Subject: [PATCH] fix(types): use auto-generated schema for NodeInfo (About pages; store instance init) --- front/src/components/About.vue | 17 +++++++++-------- front/src/components/AboutPod.vue | 5 +++-- front/src/init/instance.ts | 3 ++- front/src/types.ts | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/front/src/components/About.vue b/front/src/components/About.vue index 94bfc373e..0bf191f53 100644 --- a/front/src/components/About.vue +++ b/front/src/components/About.vue @@ -5,9 +5,10 @@ import { get } from 'lodash-es' import { humanSize } from '~/utils/filters' import { computed } from 'vue' +import type { components } from '~/generated/types.ts' + import SignupForm from '~/components/auth/SignupForm.vue' import LogoText from '~/components/LogoText.vue' -import type { NodeInfo } from '~/store/instance' import useMarkdown from '~/composables/useMarkdown' import Link from '~/components/ui/Link.vue' @@ -36,15 +37,15 @@ const stats = computed(() => { return null } - const info = nodeinfo.value ?? {} as NodeInfo + const info = nodeinfo.value ?? {} as components['schemas']['NodeInfo20'] const data = { - users: get(info, 'usage.users.activeMonth', null), - hours: get(info, 'metadata.content.local.hoursOfContent', null), - artists: get(info, 'metadata.content.local.artists.total', null), - albums: get(info, 'metadata.content.local.albums.total', null), - tracks: get(info, 'metadata.content.local.tracks.total', null), - listenings: get(info, 'metadata.usage.listenings.total', null) + users: info.usage.users.activeMonth || null, + hours: info.metadata.library.music.hours || null, + artists: info.metadata.library.artists.total || null, + albums: info.metadata.library.albums.total || null, + tracks: info.metadata.library.tracks.total || null, + listenings: info.metadata.usage?.listenings.total || null } return { users, hours, data } diff --git a/front/src/components/AboutPod.vue b/front/src/components/AboutPod.vue index ddd312ff9..790bf7327 100644 --- a/front/src/components/AboutPod.vue +++ b/front/src/components/AboutPod.vue @@ -4,8 +4,9 @@ import { useStore } from '~/store' import { get } from 'lodash-es' import { computed } from 'vue' +import type { components } from '~/generated/types.ts' + import useMarkdown from '~/composables/useMarkdown' -import type { NodeInfo } from '~/store/instance' import { useI18n } from 'vue-i18n' const store = useStore() @@ -40,7 +41,7 @@ const federationEnabled = computed(() => { const onDesktop = computed(() => window.innerWidth > 800) const stats = computed(() => { - const info = nodeinfo.value ?? {} as NodeInfo + const info = nodeinfo.value ?? {} as components['schemas']['NodeInfo20'] const data = { users: get(info, 'usage.users.activeMonth', null), diff --git a/front/src/init/instance.ts b/front/src/init/instance.ts index ef62e0677..c3e845691 100644 --- a/front/src/init/instance.ts +++ b/front/src/init/instance.ts @@ -1,4 +1,5 @@ import type { NodeInfo } from '~/store/instance' +import type { schemas } from '~/generated/types' import type { InitModule } from '~/types' import { whenever } from '@vueuse/core' @@ -15,7 +16,7 @@ export const install: InitModule = async ({ store, router }) => { const fetchNodeInfo = async () => { try { const [{ data }] = await Promise.all([ - axios.get('instance/nodeinfo/2.1/'), + axios.get('instance/nodeinfo/2.1/'), store.dispatch('instance/fetchSettings') ]) diff --git a/front/src/types.ts b/front/src/types.ts index d11c2bec0..b07b75a8d 100644 --- a/front/src/types.ts +++ b/front/src/types.ts @@ -66,7 +66,7 @@ export type Usage = components['schemas']['Usage'] export type LibraryScan = components['schemas']['LibraryScan'] export type LibraryFollow = components["schemas"]["LibraryFollow"] export type Cover = components["schemas"]["CoverField"] -export type RateLimitStatus = components["schemas"]["RateLimit"] +export type RateLimitStatus = components["schemas"]["RateLimit"]['scopes'][number] export type PaginatedAlbumList = components["schemas"]["PaginatedAlbumList"] export type SimpleArtist = components["schemas"]["SimpleArtist"]