A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
chore: code smells
aminnausin498aadf1747a
diff --git a/resources/js/components/dashboard/DashboardAnalytics.vue b/resources/js/components/dashboard/DashboardAnalytics.vueindex b5965b8d..0f2dee9f 100644--- a/resources/js/components/dashboard/DashboardAnalytics.vue+++ b/resources/js/components/dashboard/DashboardAnalytics.vue@@ -28,6 +28,7 @@ import PulseSlowJobs from '../pulseCards/PulseSlowJobs.vue';import PulseSlowOutgoingRequests from '../pulseCards/PulseSlowOutgoingRequests.vue';import PulseSlowQueries from '../pulseCards/PulseSlowQueries.vue';import PulseCache from '../pulseCards/PulseCache.vue';+import PulseServersPlaceholder from '../pulse/PulseServersPlaceholder.vue';const validPeriods: { key: string; value: string }[] = [{ key: '1h', value: '1_hour' },@@ -99,7 +100,6 @@ watch(</div><span class="mx-auto grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-6 gap-6 w-full"><PulseServers :pulseData="pulseData" :isLoading="pulseLoading" cols="6" :rows="1" />-<DashboardCard cols="2" :rows="4" :title="'Data changes over time'" :name="'Data Changes'" :details="`past ${periodForHumans(period)}`"><template #icon><LucideChartNoAxesCombined class="w-6 h-6" />diff --git a/resources/js/components/pulse/PulseNoResults.vue b/resources/js/components/pulse/PulseNoResults.vueindex 75e47188..0b760791 100644--- a/resources/js/components/pulse/PulseNoResults.vue+++ b/resources/js/components/pulse/PulseNoResults.vue@@ -1,9 +1,18 @@<script setup lang="ts">import IconNoPulse from '@/components/icons/IconNoPulse.vue';+defineProps<{ isLoading?: boolean }>();</script><template>- <div class="h-full flex flex-col items-center justify-center p-4">+ <div+ :class="[+ 'h-full flex flex-col items-center justify-center p-4',+ {+ 'animate-pulse': isLoading,+ },+ ]"+ >+ {{ isLoading }}<IconNoPulse class="h-8 w-8 stroke-gray-300 dark:stroke-gray-600" /><p class="mt-2 text-sm text-gray-400 dark:text-gray-500">No results</p></div>diff --git a/resources/js/components/pulse/PulseSelect.vue b/resources/js/components/pulse/PulseSelect.vuedeleted file mode 100644index e5bc2eb3..00000000--- a/resources/js/components/pulse/PulseSelect.vue+++ /dev/null@@ -1,19 +0,0 @@-@use('Illuminate\Support\Str')-@props([- 'id' => 'select-'.Str::random(),- 'label',- 'options',-])-<div {{ $attributes->only('class')->merge(['class' => 'flex border border-gray-200 dark:border-gray-700 overflow-hidden rounded-md focus-within:ring']) }}>- <label- for="{{ $id }}" class="px-3 flex items-center border-r border-gray-200 dark:border-gray-700 text-xs sm:text-sm text-gray-600 dark:text-gray-300 whitespace-nowrap bg-gray-100 dark:bg-gray-800/50">{{ $label }}</label>- <select- id="{{ $id }}"- {{ $attributes->except('class') }}- class="overflow-ellipsis w-full border-0 pl-3 pr-8 py-1 bg-gray-50 dark:bg-gray-800 text-gray-700 dark:text-gray-300 text-xs sm:text-sm shadow-none focus:ring-0"- >- @foreach ($options as $value => $label)- <option value="{{ $value }}">{{ $label }}</option>- @endforeach- </select>-</div>diff --git a/resources/js/components/pulse/PulseSelectLabel.vue b/resources/js/components/pulse/PulseSelectLabel.vuenew file mode 100644index 00000000..f31e8f43--- /dev/null+++ b/resources/js/components/pulse/PulseSelectLabel.vue@@ -0,0 +1,7 @@+<template>+ <label+ class="capitalize whitespace-nowrap h-10 flex items-center justify-between w-full py-2 p-3 text-left rounded-l-md shadow-sm text-sm ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 text-neutral-900 dark:text-neutral-100 bg-primary-800 dark:bg-neutral-900"+ >+ <slot></slot>+ </label>+</template>diff --git a/resources/js/components/pulse/PulseServersPlaceholder.vue b/resources/js/components/pulse/PulseServersPlaceholder.vueindex b5084482..26ad36e3 100644--- a/resources/js/components/pulse/PulseServersPlaceholder.vue+++ b/resources/js/components/pulse/PulseServersPlaceholder.vue@@ -1,10 +1,22 @@-@php-$cols = ! empty($cols) ? $cols : 'full';-$rows = ! empty($rows) ? $rows : 1;-@endphp-<section class="h-[52px] flex items-center justify-between default:col-span-full default:lg:col-span-{{ $cols }} default:row-span-{{ $rows }} {{ $class ?? '' }}">- <div class="mt-4 h-8 w-1/12 bg-gray-100 dark:bg-gray-900 rounded animate-pulse"></div>- <div class="mt-4 h-8 w-3/12 bg-gray-100 dark:bg-gray-900 rounded animate-pulse"></div>- <div class="mt-4 h-8 w-3/12 bg-gray-100 dark:bg-gray-900 rounded animate-pulse"></div>- <div class="mt-4 h-8 w-2/12 bg-gray-100 dark:bg-gray-900 rounded animate-pulse"></div>-</section>+<script setup lang="ts">+withDefaults(+ defineProps<{+ cols?: number | string;+ rows?: number;+ }>(),+ {+ cols: 'full',+ rows: 1,+ },+);++const placeholderClass = 'mt-4 h-8 bg-white dark:bg-primary-dark-800 rounded-md ring-1 ring-gray-900/5 shadow-sm';+</script>+<template>+ <section :class="`h-[52px] flex items-center justify-between default:col-span-full default:lg:col-span-${cols} default:row-span-${rows} animate-pulse`">+ <div :class="['w-1/12', placeholderClass]"></div>+ <div :class="['w-3/12', placeholderClass]"></div>+ <div :class="['w-3/12', placeholderClass]"></div>+ <div :class="['w-2/12', placeholderClass]"></div>+ </section>+</template>diff --git a/resources/js/components/pulseCards/PulseCache.vue b/resources/js/components/pulseCards/PulseCache.vueindex 60250dd2..e45c075a 100644--- a/resources/js/components/pulseCards/PulseCache.vue+++ b/resources/js/components/pulseCards/PulseCache.vue@@ -61,7 +61,7 @@ const config = computed(() => {</template><PulseScroll :expand="false" :loading="isLoading ?? false">- <PulseNoResults v-if="pulseData.cache.allCacheInteractions.hits === 0 && pulseData.cache.allCacheInteractions.misses === 0" />+ <PulseNoResults :isLoading="isLoading" v-if="pulseData.cache.allCacheInteractions.hits === 0 && pulseData.cache.allCacheInteractions.misses === 0" /><div class="flex flex-col gap-6" v-else><div class="grid grid-cols-3 gap-3 text-center"><div class="flex flex-col justify-center @sm:block">diff --git a/resources/js/components/pulseCards/PulseExceptions.vue b/resources/js/components/pulseCards/PulseExceptions.vueindex 2fb69876..83f796c5 100644--- a/resources/js/components/pulseCards/PulseExceptions.vue+++ b/resources/js/components/pulseCards/PulseExceptions.vue@@ -88,7 +88,7 @@ const exceptions = computed(() => {<PulseScroll :expand="false" :loading="isLoading ?? false"><div class="min-h-full flex flex-col">- <PulseNoResults v-if="exceptions.length === 0" />+ <PulseNoResults :isLoading="isLoading" v-if="exceptions.length === 0" /><PulseTable v-else><colgroup><col class="w-full" />diff --git a/resources/js/components/pulseCards/PulseQueues.vue b/resources/js/components/pulseCards/PulseQueues.vueindex 9bcfb5fd..60b39f98 100644--- a/resources/js/components/pulseCards/PulseQueues.vue+++ b/resources/js/components/pulseCards/PulseQueues.vue@@ -71,7 +71,7 @@ function scale(data: { [key: string]: any }) {</template><PulseScroll :expand="true" :loading="isLoading ?? true">- <PulseNoResults v-if="!queues || (Object.keys(queues)?.length ?? 0) == 0" />+ <PulseNoResults :isLoading="isLoading" v-if="!queues || (Object.keys(queues)?.length ?? 0) == 0" /><div v-else-if="queues" class="grid gap-3 mx-px mb-px"><div v-for="queue in Object.keys(queues)" :key="queue"><h3 class="font-bold text-neutral-700 dark:text-neutral-300">diff --git a/resources/js/components/pulseCards/PulseRequests.vue b/resources/js/components/pulseCards/PulseRequests.vueindex ab0f31c6..5dbdcc7d 100644--- a/resources/js/components/pulseCards/PulseRequests.vue+++ b/resources/js/components/pulseCards/PulseRequests.vue@@ -76,7 +76,7 @@ function scale(data: { [key: string]: any }) {</template><PulseScroll :expand="true" :loading="isLoading ?? true">- <PulseNoResults v-if="!requests || (Object.keys(requests)?.length ?? 0) == 0" />+ <PulseNoResults :isLoading="isLoading" v-if="!requests || (Object.keys(requests)?.length ?? 0) == 0" /><div v-else-if="requests" class="grid gap-3 mx-px mb-px"><div v-for="request in Object.keys(requests)" :key="request"><div class="mt-3 relative">diff --git a/resources/js/components/pulseCards/PulseServers.vue b/resources/js/components/pulseCards/PulseServers.vueindex dff50715..e056a3ab 100644--- a/resources/js/components/pulseCards/PulseServers.vue+++ b/resources/js/components/pulseCards/PulseServers.vue@@ -9,6 +9,7 @@ import PulseDoughnutChart from '@/components/charts/PulseDoughnutChart.vue';import IconSignalSlash from '@/components/icons/IconSignalSlash.vue';import PulseLineChart from '@/components/charts/PulseLineChart.vue';import IconServer from '@/components/icons/IconServer.vue';+import PulseServersPlaceholder from '../pulse/PulseServersPlaceholder.vue';const props = withDefaults(defineProps<{@@ -38,11 +39,15 @@ watch(<template><section- :class="`overflow-x-auto overflow-y-hidden scrollbar-minimal-x scrollbar-thumb:bg-gray-300 dark:scrollbar-thumb:bg-gray-500/50 scrollbar-track:rounded scrollbar-track:bg-gray-100 dark:scrollbar-track:bg-gray-500/10 supports-scrollbars- max-w-full pb-2 default:col-span-full default:lg:col-span-${props.cols} default:row-span-${props.rows} ${isLoading ? 'opacity-25 animate-pulse ' : ''}${props.class ?? ''}`"+ :class="[+ `overflow-x-auto overflow-y-hidden scrollbar-minimal-x scrollbar-thumb:bg-gray-300 dark:scrollbar-thumb:bg-gray-500/50 scrollbar-track:rounded scrollbar-track:bg-gray-100 dark:scrollbar-track:bg-gray-500/10 supports-scrollbars+ max-w-full pb-2`,+ `default:col-span-full default:lg:col-span-${props.cols} default:row-span-${props.rows}`,+ props.class,+ ]"><div- v-if="servers"+ v-if="servers && !isLoading"class="max-w-full grid grid-cols-[max-content,minmax(max-content,1fr),max-content,minmax(min-content,2fr),max-content,minmax(min-content,2fr),minmax(max-content,1fr)]"><div></div>@@ -260,5 +265,6 @@ watch(</div></template></div>+ <PulseServersPlaceholder cols="6" :rows="1" v-else /></section></template>diff --git a/resources/js/components/pulseCards/PulseSlowJobs.vue b/resources/js/components/pulseCards/PulseSlowJobs.vueindex 011d8725..40cafbbb 100644--- a/resources/js/components/pulseCards/PulseSlowJobs.vue+++ b/resources/js/components/pulseCards/PulseSlowJobs.vue@@ -5,6 +5,7 @@ import { format_number, periodForHumans } from '@/service/pulseUtil';import { computed, ref } from 'vue';import { sortObject } from '@/service/sort/baseSort';+import PulseSelectLabel from '@/components/pulse/PulseSelectLabel.vue';import IconCommandLine from '@/components/icons/IconCommandLine.vue';import PulseNoResults from '@/components/pulse/PulseNoResults.vue';import DashboardCard from '@/components/cards/DashboardCard.vue';@@ -71,10 +72,7 @@ const config = computed(() => {</template><template #actions>- <label- class="capitalize whitespace-nowrap h-10 flex items-center justify-between w-full py-2 p-3 text-left rounded-l-md shadow-sm text-sm ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 text-neutral-900 dark:text-neutral-100 bg-primary-800 dark:bg-neutral-900"- >Sort By</label- >+ <PulseSelectLabel> Sort By </PulseSelectLabel><InputSelect:placeholder="'None'":options="exceptionOptions"@@ -87,7 +85,7 @@ const config = computed(() => {<PulseScroll :expand="false" :loading="isLoading ?? false"><div class="min-h-full flex flex-col">- <PulseNoResults v-if="slowJobs.length === 0" />+ <PulseNoResults :isLoading="isLoading" v-if="slowJobs.length === 0" /><PulseTable v-else><colgroup><col class="w-full" />diff --git a/resources/js/components/pulseCards/PulseSlowOutgoingRequests.vue b/resources/js/components/pulseCards/PulseSlowOutgoingRequests.vueindex d0af6fa1..95d25960 100644--- a/resources/js/components/pulseCards/PulseSlowOutgoingRequests.vue+++ b/resources/js/components/pulseCards/PulseSlowOutgoingRequests.vue@@ -8,6 +8,7 @@ import { sortObject } from '@/service/sort/baseSort';import IconInformationCircle from '@/components/icons/IconInformationCircle.vue';import PulseHttpMethodBadge from '@/components/pulse/PulseHttpMethod-Badge.vue';import IconCloudArrowUp from '@/components/icons/IconCloudArrowUp.vue';+import PulseSelectLabel from '@/components/pulse/PulseSelectLabel.vue';import PulseNoResults from '@/components/pulse/PulseNoResults.vue';import DashboardCard from '@/components/cards/DashboardCard.vue';import PulseScroll from '@/components/pulse/PulseScroll.vue';@@ -86,10 +87,7 @@ function getDomainFromUrl(input: string): string | null {><IconInformationCircle class="w-5 h-5 stroke-gray-400 dark:stroke-gray-600" /></button>- <label- class="capitalize whitespace-nowrap h-10 flex items-center justify-between w-full py-2 p-3 text-left rounded-l-md shadow-sm text-sm ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 text-neutral-900 dark:text-neutral-100 bg-primary-800 dark:bg-neutral-900"- >Sort By</label- >+ <PulseSelectLabel> Sort By </PulseSelectLabel><InputSelect:placeholder="'None'":options="exceptionOptions"@@ -102,7 +100,7 @@ function getDomainFromUrl(input: string): string | null {<PulseScroll :expand="false" :loading="isLoading ?? false"><div class="min-h-full flex flex-col">- <PulseNoResults v-if="slowOutgoingRequests.length === 0" />+ <PulseNoResults :isLoading="isLoading" v-if="slowOutgoingRequests.length === 0" /><PulseTable v-else><colgroup><col class="w-0" />diff --git a/resources/js/components/pulseCards/PulseSlowQueries.vue b/resources/js/components/pulseCards/PulseSlowQueries.vueindex fff50da8..aab09ae0 100644--- a/resources/js/components/pulseCards/PulseSlowQueries.vue+++ b/resources/js/components/pulseCards/PulseSlowQueries.vue@@ -5,6 +5,7 @@ import { format_number, periodForHumans } from '@/service/pulseUtil';import { computed, ref } from 'vue';import { sortObject } from '@/service/sort/baseSort';+import PulseSelectLabel from '@/components/pulse/PulseSelectLabel.vue';import IconCircleStack from '@/components/icons/IconCircleStack.vue';import PulseNoResults from '@/components/pulse/PulseNoResults.vue';import DashboardCard from '@/components/cards/DashboardCard.vue';@@ -71,11 +72,8 @@ const config = computed(() => {</template><template #actions>- <label- class="capitalize whitespace-nowrap h-10 flex items-center justify-between w-full py-2 p-3 text-left rounded-l-md shadow-sm text-sm ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 text-neutral-900 dark:text-neutral-100 bg-primary-800 dark:bg-neutral-900"- >- Sort By- </label>+ <PulseSelectLabel> Sort By </PulseSelectLabel>+<InputSelect:placeholder="'None'":options="exceptionOptions"@@ -88,7 +86,7 @@ const config = computed(() => {<PulseScroll :expand="false" :loading="isLoading ?? false"><div class="min-h-full flex flex-col">- <PulseNoResults v-if="slowQueries.length === 0" />+ <PulseNoResults :isLoading="isLoading" v-if="slowQueries.length === 0" /><PulseTable v-else><colgroup><col class="w-full" />diff --git a/resources/js/components/pulseCards/PulseSlowRequests.vue b/resources/js/components/pulseCards/PulseSlowRequests.vueindex ea492d4e..a2fdb53c 100644--- a/resources/js/components/pulseCards/PulseSlowRequests.vue+++ b/resources/js/components/pulseCards/PulseSlowRequests.vue@@ -7,6 +7,7 @@ import { sortObject } from '@/service/sort/baseSort';import PulseHttpMethodBadge from '@/components/pulse/PulseHttpMethod-Badge.vue';import IconArrowsLeftRight from '@/components/icons/IconArrowsLeftRight.vue';+import PulseSelectLabel from '@/components/pulse/PulseSelectLabel.vue';import PulseNoResults from '@/components/pulse/PulseNoResults.vue';import DashboardCard from '@/components/cards/DashboardCard.vue';import PulseScroll from '@/components/pulse/PulseScroll.vue';@@ -72,10 +73,8 @@ const config = computed(() => {</template><template #actions>- <label- class="capitalize whitespace-nowrap h-10 flex items-center justify-between w-full py-2 p-3 text-left rounded-l-md shadow-sm text-sm ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 text-neutral-900 dark:text-neutral-100 bg-primary-800 dark:bg-neutral-900"- >Sort By</label- >+ <PulseSelectLabel> Sort By </PulseSelectLabel>+<InputSelect:placeholder="'None'":options="exceptionOptions"@@ -88,7 +87,7 @@ const config = computed(() => {<PulseScroll :expand="false" :loading="isLoading ?? false"><div class="min-h-full flex flex-col">- <PulseNoResults v-if="requests.length === 0" />+ <PulseNoResults :isLoading="isLoading" v-if="requests.length === 0" /><PulseTable v-else><colgroup><col class="w-0" />diff --git a/resources/js/components/pulseCards/PulseUsage.vue b/resources/js/components/pulseCards/PulseUsage.vueindex a615560b..f3306081 100644--- a/resources/js/components/pulseCards/PulseUsage.vue+++ b/resources/js/components/pulseCards/PulseUsage.vue@@ -102,7 +102,7 @@ const sampleRate = () => {</template><PulseScroll :expand="false" :loading="isLoading ?? false">- <PulseNoResults v-if="userRequestCounts?.length === 0" />+ <PulseNoResults :isLoading="isLoading" v-if="userRequestCounts?.length === 0" /><div v-else class="grid grid-cols-1 @lg:grid-cols-2 @3xl:grid-cols-3 6xl:grid-cols-2 gap-2 overflow-visible"><PulseUserCard v-for="userRequestCount in userRequestCounts" :key="userRequestCount.key" :user="userRequestCount.user"><template #stats>diff --git a/resources/js/service/siteAPI.ts b/resources/js/service/siteAPI.tsindex a6c8b96a..1de8041d 100644--- a/resources/js/service/siteAPI.ts+++ b/resources/js/service/siteAPI.ts@@ -8,11 +8,13 @@import { API } from './api';export function getSiteAnalytics(period?: string) {- return API.get(`/analytics${period ? `?period=${period}` : ''}`);+ const parsedPeriod = period ? `?period=${period}` : '';+ return API.get(`/analytics${parsedPeriod}`);}export function getPulse(req?: { type?: string; period?: string }) {- return API.get(`/pulse${req?.type ? `/${req?.type}` : ''}${req?.period ? `?period=${req?.period}` : ''}`);+ const parsedPeriod = req?.period ? `?period=${req.period}` : '';+ return API.get(`/pulse/${req?.type ?? ''}${parsedPeriod}`);}export function getUsers() {diff --git a/resources/js/service/sort/baseSort.test.ts b/resources/js/service/sort/baseSort.test.tsindex da41f19b..6daa136b 100644--- a/resources/js/service/sort/baseSort.test.ts+++ b/resources/js/service/sort/baseSort.test.ts@@ -6,18 +6,18 @@ import { expect, test } from 'vitest';test('CompareStrategies.episode sorts by season and episode', () => {const videos: VideoResource[] = [- { id: 1, name: '1', path: '/1', date: '', video_tags: [], season: 2, episode: 2 },- { id: 3, name: '3', path: '/3', date: '', video_tags: [], season: 2, episode: 1 },- { id: 2, name: '2', path: '/2', date: '', video_tags: [], season: 1, episode: 1 },- { id: 4, name: '4', path: '/4', date: '', video_tags: [], season: 1, episode: 2 },+ { id: 1, name: '1', path: '/1', date: '', video_tags: [], season: 2, episode: 2, date_created: '' },+ { id: 3, name: '3', path: '/3', date: '', video_tags: [], season: 2, episode: 1, date_created: '' },+ { id: 2, name: '2', path: '/2', date: '', video_tags: [], season: 1, episode: 1, date_created: '' },+ { id: 4, name: '4', path: '/4', date: '', video_tags: [], season: 1, episode: 2, date_created: '' },];videos.sort(sortObjectNew([{ compareFn: CompareStrategies.episode }]));expect(videos).toEqual([- { id: 2, name: '2', path: '/2', date: '', video_tags: [], season: 1, episode: 1 },- { id: 4, name: '4', path: '/4', date: '', video_tags: [], season: 1, episode: 2 },- { id: 3, name: '3', path: '/3', date: '', video_tags: [], season: 2, episode: 1 },- { id: 1, name: '1', path: '/1', date: '', video_tags: [], season: 2, episode: 2 },+ { id: 2, name: '2', path: '/2', date: '', video_tags: [], season: 1, episode: 1, date_created: '' },+ { id: 4, name: '4', path: '/4', date: '', video_tags: [], season: 1, episode: 2, date_created: '' },+ { id: 3, name: '3', path: '/3', date: '', video_tags: [], season: 2, episode: 1, date_created: '' },+ { id: 1, name: '1', path: '/1', date: '', video_tags: [], season: 2, episode: 2, date_created: '' },]);});