A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: improve storage info layout
aminnausinc0da81ee3b2c
diff --git a/app/Http/Controllers/Api/V1/Server/DiskUsageController.php b/app/Http/Controllers/Api/V1/Server/DiskUsageController.phpindex c14c9d85..fd2cc9e2 100644--- a/app/Http/Controllers/Api/V1/Server/DiskUsageController.php+++ b/app/Http/Controllers/Api/V1/Server/DiskUsageController.php@@ -18,8 +18,7 @@ use RecursiveIteratorIterator;class DiskUsageController extends Controller {private const SIZE_CACHE_TTL = 3600;- public function __construct(private ServerConfigService $config) {- }+ public function __construct(private ServerConfigService $config) {}public function index(Request $request): JsonResponse {$refresh = $request->boolean('refresh');@@ -79,8 +78,8 @@ class DiskUsageController extends Controller {$cachePath = $this->resolve($private, $this->config->get('cache_path', 'storage/cache'));$locations = [- ['metadata.videos', 'File Thumbnails', 'images', "$metadataPath/metadata"],- ['metadata.series', 'Folder Thumbnails', 'images', "$metadataPath/series"],+ ['metadata.videos', 'Media', 'images', "$metadataPath/metadata"],+ ['metadata.series', 'Folders', 'images', "$metadataPath/series"],['legacy.thumbnails', 'Thumbnails', 'legacy', $this->normalise($public->path('thumbnails'))],['legacy.posters', 'Posters', 'legacy', $this->normalise($public->path('posters'))],['legacy.previews', 'Previews', 'legacy', $this->normalise($public->path('previews'))],@@ -94,7 +93,7 @@ class DiskUsageController extends Controller {$mediaRoot = $this->normalise($public->path('media'));$libraries = Category::query()- ->when(! $hasFullAccess, fn($query) => $query->where('is_private', false))+ ->when(! $hasFullAccess, fn ($query) => $query->where('is_private', false))->with('folders.series')->orderBy('name')->get();@@ -106,7 +105,7 @@ class DiskUsageController extends Controller {'library',"$mediaRoot/$library->name",$library->folders->sum(- fn($folder) => $folder->series?->total_size ?? 0,+ fn ($folder) => $folder->series?->total_size ?? 0,),];}diff --git a/resources/js/components/cards/server/DiskUsageCard.vue b/resources/js/components/cards/server/StorageStatsCard.vuesimilarity index 66%rename from resources/js/components/cards/server/DiskUsageCard.vuerename to resources/js/components/cards/server/StorageStatsCard.vueindex 2402a950..8a3a59dd 100644--- a/resources/js/components/cards/server/DiskUsageCard.vue+++ b/resources/js/components/cards/server/StorageStatsCard.vue@@ -3,10 +3,12 @@ import type { DiskCategory, DiskLocation } from '@/contracts/server';import { useGetDiskUsage, useRefreshDiskUsage } from '@/service/server/queries';import { formatFileSize } from '@/service/util';+import { computed, ref } from 'vue';import { ButtonBase } from '@/components/cedar-ui/button';-import { computed } from 'vue';+import { cn } from '@aminnausin/cedar-ui';import TranscriptStatus from '@/components/video/transcript/TranscriptStatus.vue';+import DiskUsageCard from '@/components/cards/server/storage/DiskCard.vue';import DashboardCard from '@/components/cards/layout/DashboardCard.vue';import ProiconsAlertTriangle from '~icons/proicons/alert-triangle';@@ -19,13 +21,19 @@ import IconServer from '@/components/icons/IconServer.vue';const panel = 'data-card pulse-card flex gap-3 flex-col';const skeleton = 'animate-pulse motion-reduce:animate-none bg-neutral-200 dark:bg-neutral-700';-const categories: Record<DiskCategory, { label: string; color: string }> = {- library: { label: 'Libraries', color: 'bg-primary' },- images: { label: 'Images', color: 'bg-primary' },- subtitles: { label: 'Subtitles', color: 'bg-rose-500' },- cache: { label: 'Cache', color: 'bg-blue-500' },- logs: { label: 'Logs', color: 'bg-slate-400' },- legacy: { label: 'Legacy', color: 'bg-yellow-500' },+const categories: Record<DiskCategory, { label: string; colour: string }> = {+ library: { label: 'Libraries', colour: 'bg-primary' },+ images: { label: 'Images', colour: 'bg-primary' },+ subtitles: { label: 'Subtitles', colour: 'bg-rose-500' },+ cache: { label: 'Cache', colour: 'bg-blue-500' },+ logs: { label: 'Logs', colour: 'bg-slate-400' },+ legacy: { label: 'Legacy', colour: 'bg-yellow-500' },+};++const diskKinds = {+ library: { label: 'Libraries', colour: 'bg-primary' },+ app: { label: 'App data', colour: 'bg-cyan-500' },+ other: { label: 'Other', colour: 'bg-neutral-400/60' },};const categoryOrder = Object.keys(categories) as DiskCategory[];@@ -53,25 +61,54 @@ const appData = computed(() => {return { groups, total, segments: groups.map((g) => ({ ...g, percent: (g.bytes / total) * 100 })) };});+const libraries = computed(() => {const items = sized.value.filter((l) => l.category === 'library');- return { items, total: sumGroupSize(items) };+ return { items, total: sumGroupSize(items), max: items[0]?.bytes ?? 0 };});const disks = computed(() =>(data.value?.filesystems ?? []).map((fs, index, all) => {- const names = categoryOrder.filter((c) => data.value!.locations.some((l) => l.filesystem === fs.id && l.category === c)).map((c) => categories[c].label);- const percentUsed = fs.totalSpace ? Math.round((fs.usedSpace / fs.totalSpace) * 100) : 0;+ const onDisk = (data.value?.locations ?? []).filter((l) => l.filesystem === fs.id).sort((a, b) => (b.bytes ?? 0) - (a.bytes ?? 0));+ const libs = onDisk.filter((l) => l.category === 'library');+ const appData = onDisk.filter((l) => l.category !== 'library');++ const libBytes = sumGroupSize(libs);+ const appBytes = sumGroupSize(appData);+ const otherBytes = Math.max(0, fs.usedSpace - libBytes - appBytes);++ const toPercent = (bytes: number) => (fs.totalSpace ? (bytes / fs.totalSpace) * 100 : 0);+ const percentUsed = Math.round(toPercent(fs.usedSpace));++ const segments = (+ [+ { key: 'library', bytes: libBytes },+ { key: 'app', bytes: appBytes },+ { key: 'other', bytes: otherBytes },+ ] as const+ )+ .filter((s) => s.bytes > 0)+ .map((s) => ({ ...s, ...diskKinds[s.key], percent: toPercent(s.bytes) }));++ const top = libs.slice(0, 3).map((l) => l.label);+ const rest = libs.length - top.length;return {...fs,title: all.length > 1 ? `Disk ${index + 1}` : 'Disk',- names: names.join(' · '),percentUsed,- color: percentUsed >= 90 ? 'bg-danger-2' : percentUsed >= 75 ? 'bg-warning-2' : 'bg-success',+ segments,+ contents: [appData.length > 0 && 'app data', , ...top, rest > 0 ? `+${rest} more` : ''].filter(Boolean).join(' · '),+ libraryNames: libs.map((l) => l.label).join(', '),+ colour: percentUsed >= 90 ? 'bg-danger-2' : percentUsed >= 75 ? 'bg-warning-2' : 'bg-success',};}),);++const LIBRARY_PREVIEW = 5;+const showAllLibraries = ref(false);++const visibleLibraries = computed(() => (showAllLibraries.value ? libraries.value.items : libraries.value.items.slice(0, LIBRARY_PREVIEW)));</script><template>@@ -160,24 +197,7 @@ const disks = computed(() =><template v-else><section :class="panelClass">- <div class="flex items-center gap-2 text-base">- <ProiconsDatabase class="text-foreground-2 size-4" />- <h3 class="text-foreground-2">Disks</h3>- </div>-- <div v-for="disk in disks" :key="disk.id" class="flex flex-col gap-1.5">- <div class="flex items-baseline gap-2">- <h3 class="text-sm">{{ disk.title }}</h3>- <span class="text-foreground-2 truncate text-xs">{{ disk.names }}</span>- <span class="ml-auto shrink-0 text-sm">- {{ formatFileSize(disk.freeSpace) }} free- <span class="text-foreground-2 text-xs">of {{ formatFileSize(disk.totalSpace) }}</span>- </span>- </div>- <div class="h-1.5 w-full overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700" role="img" :aria-label="`${disk.percentUsed}% used`">- <div :class="disk.color" class="h-full" :style="{ width: `${disk.percentUsed}%` }"></div>- </div>- </div>+ <DiskUsageCard :version="3" :disks="disks" :disk-kinds="diskKinds"></DiskUsageCard></section><section v-if="appData.total" :class="panelClass">@@ -187,14 +207,23 @@ const disks = computed(() =><span class="ml-auto">{{ formatFileSize(appData.total) }}</span></div>- <div class="flex h-4 w-full gap-px overflow-hidden rounded-sm">- <div v-for="segment in appData.segments" :key="segment.key" :class="segment.color" class="min-w-0.5" :style="{ width: `${segment.percent}%` }"></div>+ <div class="flex h-1.5 w-full gap-px overflow-hidden rounded-sm">+ <div+ v-for="segment in appData.segments"+ :key="segment.key"+ :class="+ cn(segment.colour, 'flex min-w-6 items-center ps-2 text-center text-xs text-white tabular-nums', {+ 'text-foreground-i dark': segment.label === 'Legacy',+ })+ "+ :style="{ width: `${segment.percent}%` }"+ ></div></div>- <ul class="flex flex-col gap-2 text-sm">+ <ul class="grid grid-cols-1 gap-3 lg:grid-cols-2"><li v-for="group in appData.groups" :key="group.key"><div class="flex items-center gap-2">- <span :class="group.color" class="h-2 w-2 shrink-0 rounded-full"></span>+ <span :class="group.colour" class="h-2 w-2 shrink-0 rounded-full"></span><span>{{ group.label }}</span><span class="ml-auto">{{ formatFileSize(group.bytes) }}</span></div>@@ -211,15 +240,19 @@ const disks = computed(() =><section v-if="libraries.total" :class="[panelClass, 'text-foreground-2']"><div class="flex items-center gap-2 text-base"><ProiconsLibrary class="size-4.5" />- <h3 class="text-foreground-0">Libraries</h3>+ <h3>Libraries</h3><span class="text-foreground-0 ml-auto">{{ formatFileSize(libraries.total) }}</span></div>- <ul class="flex flex-col gap-1.5 text-sm">- <li v-for="library in libraries.items" :key="library.key" class="flex items-center gap-2">- <span :class="categories.library.color" class="h-2 w-2 shrink-0 rounded-full"></span>- <span class="truncate" :title="library.path">{{ library.label }}</span>- <span class="ml-auto">{{ formatFileSize(library.bytes!) }}</span>+ <ul class="grid grid-cols-2 gap-x-4 gap-y-3 sm:grid-cols-4">+ <li v-for="library in libraries.items" :key="library.key" class="flex min-w-0 flex-col gap-1">+ <RouterLink :to="`/${library.label}`">+ <span class="text-foreground-0 hover:text-primary cursor-pointer truncate" :title="library.path">{{ library.label }}</span>+ </RouterLink>+ <span class="text-xs">{{ formatFileSize(library.bytes!) }}</span>+ <div class="h-1 w-full overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700">+ <div :class="categories.library.colour" class="h-full" :style="{ width: `${(library.bytes! / libraries.max) * 100}%` }"></div>+ </div></li></ul></section>diff --git a/resources/js/components/cards/server/storage/DiskCard.vue b/resources/js/components/cards/server/storage/DiskCard.vuenew file mode 100644index 00000000..9a36fa10--- /dev/null+++ b/resources/js/components/cards/server/storage/DiskCard.vue@@ -0,0 +1,128 @@+<script setup lang="ts">+import type { DiskFilesystem } from '@/contracts/server';++import { formatFileSize } from '@/service/util';++import ProiconsDatabase from '~icons/proicons/database';++withDefaults(+ defineProps<{+ version?: 1 | 2 | 3;+ disks: (DiskFilesystem & {+ title: string;+ percentUsed: number;+ segments: {+ percent: number;+ label: string;+ colour: string;+ key: any;+ bytes: number;+ }[];+ contents: string;+ libraryNames: string;+ colour: string;+ })[];+ diskKinds: Record<string, { label: string; colour: string }>;+ }>(),+ { version: 3 },+);+</script>+<template>+ <template v-if="version === 1">+ <div class="flex items-center gap-2 text-base">+ <ProiconsDatabase class="text-foreground-2 size-4" />+ <h3 class="text-foreground-2">Disks</h3>+ <div class="text-foreground-2 ml-auto flex items-center gap-3 text-xs">+ <span v-for="kind in diskKinds" :key="kind.label" class="flex items-center gap-1.5">+ <span :class="kind.colour" class="size-2 rounded-full"></span>{{ kind.label }}+ </span>+ </div>+ </div>++ <div class="grid grid-cols-1 gap-3">+ <div v-for="disk in disks" :key="disk.id" class="flex flex-col gap-2 rounded-lg p-3 ring-1 ring-neutral-500/20">+ <div class="flex items-center gap-2 text-sm">+ <h3>{{ disk.title }}</h3>+ <span class="text-foreground-2 ml-auto flex items-center gap-1.5 text-xs">+ <span :class="disk.colour" class="size-2 rounded-full"></span>+ {{ disk.percentUsed }}% used+ </span>+ </div>++ <p class="text-lg leading-none">+ {{ formatFileSize(disk.freeSpace) }}+ <span class="text-foreground-2 text-xs">free of {{ formatFileSize(disk.totalSpace) }}</span>+ </p>++ <div class="flex h-2 w-full gap-px overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700" role="img" :aria-label="`${disk.percentUsed}% used`">+ <div+ v-for="segment in disk.segments"+ :key="segment.key"+ :class="segment.colour"+ class="min-w-0.5"+ :style="{ width: `${segment.percent}%` }"+ :title="`${segment.label} ${formatFileSize(segment.bytes)}`"+ ></div>+ </div>++ <p v-if="disk.contents" class="text-foreground-2 text-xs" :title="disk.libraryNames">{{ disk.contents }}</p>+ </div>+ </div>+ </template>++ <template v-else-if="version === 2">+ <div class="flex items-center gap-2 text-base">+ <ProiconsDatabase class="text-foreground-2 size-4" />+ <h3 class="text-foreground-2">Disks</h3>+ </div>+ <div v-for="disk in disks" :key="disk.id" class="flex flex-col gap-1.5">+ <div class="flex items-baseline gap-2">+ <h3 class="text-sm">{{ disk.title }}</h3>+ <span class="text-foreground-2 truncate text-xs">{{ disk.contents }}</span>+ <span class="ml-auto shrink-0 text-sm">+ {{ formatFileSize(disk.freeSpace) }} free+ <span class="text-foreground-2 text-xs">of {{ formatFileSize(disk.totalSpace) }}</span>+ </span>+ </div>+ <div class="h-1.5 w-full overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700" role="img" :aria-label="`${disk.percentUsed}% used`">+ <div :class="disk.colour" class="h-full" :style="{ width: `${disk.percentUsed}%` }"></div>+ </div>+ </div>+ </template>++ <template v-else-if="version === 3">+ <div class="flex items-center gap-2 text-base">+ <ProiconsDatabase class="text-foreground-2 size-4" />++ <h3 class="text-foreground-2">Disks</h3>+ <div class="text-foreground-2 ml-auto flex items-center gap-3 text-xs">+ <span v-for="kind in diskKinds" :key="kind.label" class="flex items-center gap-1.5">+ <span :class="kind.colour" class="size-2 rounded-full"></span>{{ kind.label }}+ </span>+ </div>+ </div>++ <div v-for="disk in disks" :key="disk.id" class="flex flex-col gap-1.5 rounded-lg">+ <div class="flex items-baseline gap-2">+ <h3 class="text-nowrap tabular-nums" :title="disk.id">{{ disk.title }}</h3>+ <span class="text-foreground-2 truncate text-xs lowercase" :title="disk.libraryNames || 'No libraries'">{{ disk.contents }}</span>+ <span class="ml-auto shrink-0">+ {{ formatFileSize(disk.freeSpace) }} free+ <span class="text-foreground-2 text-xs">of {{ formatFileSize(disk.totalSpace) }}</span>+ </span>+ <span :class="[disk.colour, 'size-2 shrink-0 rounded-full']" :title="`${disk.percentUsed}% used`"></span>+ </div>++ <div class="flex h-1.5 w-full gap-px overflow-hidden rounded-full bg-neutral-200 dark:bg-neutral-700" :aria-label="`${disk.percentUsed}% used`">+ <div+ v-for="segment in disk.segments"+ :key="segment.key"+ :class="segment.colour"+ class="min-w-0.5"+ :style="{ width: `${segment.percent}%` }"+ :title="`${segment.label} ${formatFileSize(segment.bytes)}`"+ ></div>+ </div>+ </div>+ </template>+</template>diff --git a/resources/js/components/dashboard/DashboardAnalytics.vue b/resources/js/components/dashboard/DashboardAnalytics.vueindex 1e06f0e3..55ccd979 100644--- a/resources/js/components/dashboard/DashboardAnalytics.vue+++ b/resources/js/components/dashboard/DashboardAnalytics.vue@@ -17,7 +17,7 @@ import PulseSlowRequests from '@/components/cards/pulse/PulseSlowRequests.vue';import PulseSlowQueries from '@/components/cards/pulse/PulseSlowQueries.vue';import ServerActivityCard from '@/components/cards/server/ServerActivityCard.vue';import PulseExceptions from '@/components/cards/pulse/PulseExceptions.vue';-import DiskUsageCard from '@/components/cards/server/DiskUsageCard.vue';+import StorageStatsCard from '@/components/cards/server/StorageStatsCard.vue';import PulseRequests from '@/components/cards/pulse/PulseRequests.vue';import PulseSlowJobs from '@/components/cards/pulse/PulseSlowJobs.vue';import PulseServers from '@/components/cards/pulse/PulseServers.vue';@@ -114,7 +114,7 @@ onMounted(() => {<PulseServers :pulseData="pulseData" :isLoading="pulseLoading" cols="6" :rows="1" /><ServerActivityCard :period="period" /><PulseUsage :pulseData="pulseData" :isLoading="pulseLoading" :period="period" :rows="1" class="lg:col-span-6 2xl:col-span-2 2xl:col-start-5! 2xl:row-start-3" />- <DiskUsageCard :rows="1" cols="6" class="lg:col-span-6 2xl:col-span-4" />+ <StorageStatsCard :rows="1" cols="6" class="lg:col-span-6 2xl:col-span-4" /><PulseQueues :pulseData="pulseData" :isLoading="pulseLoading" :period="period" :rows="2" /><PulseRequests v-if="pulseData" :pulseData="pulseData" :isLoading="pulseLoading" :period="period" :rows="2" />