A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
dashboard stats ui updates
aminnausin901bef69fed0
diff --git a/app/Http/Controllers/Api/V1/AnalyticsController.php b/app/Http/Controllers/Api/V1/AnalyticsController.phpindex 10e86e3d..4a7fa962 100644--- a/app/Http/Controllers/Api/V1/AnalyticsController.php+++ b/app/Http/Controllers/Api/V1/AnalyticsController.php@@ -72,4 +72,8 @@ class AnalyticsController extends Controller {return $this->error(null, 'Unable to get analytics. Error: ' . $th->getMessage(), 500);}}+++ public function getDashboardStats(Request $request) {+ }}diff --git a/app/Http/Controllers/Api/V1/PulseDashboardController.php b/app/Http/Controllers/Api/V1/PulseDashboardController.phpdeleted file mode 100644index 0baf46bc..00000000--- a/app/Http/Controllers/Api/V1/PulseDashboardController.php+++ /dev/null@@ -1,27 +0,0 @@-<?php--namespace App\Http\Controllers\Api\V1;--use App\Http\Resources\Pulse\DashboardResource;-use Illuminate\Http\Request;--class PulseDashboardController {- public function index(Request $request) {- $period = $request->query('period', '');-- return new DashboardResource(null, $period);- }-- public function show(Request $request, string $type) {- $period = $request->query('period', '');- if (array_key_exists($type, config('pulse-api.resources')->toArray())) {- return new (config('pulse-api.resources.' . $type))(null, $period);- }-- return response()->json([- 'data' => [- 'message' => 'Metric type "' . $type . '" does not exist.',- ],- ], 404);- }-}diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.phpindex 86edb377..7c9ef654 100755--- a/app/Jobs/VerifyFiles.php+++ b/app/Jobs/VerifyFiles.php@@ -18,10 +18,13 @@ use Illuminate\Support\Facades\File;use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;+use Livewire\Attributes\Title;use Ramsey\Uuid\Uuid;use Symfony\Component\Process\Exception\ProcessFailedException;use Symfony\Component\Process\Process;+use function PHPUnit\Framework\isNull;+class VerifyFiles implements ShouldQueue {use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;@@ -142,6 +145,8 @@ class VerifyFiles implements ShouldQueue {}$stored = $metadata->toArray();+ $fileUpdated = !is_null($metadata->date_scanned) && filemtime($filePath) > strtotime($metadata->date_scanned);+if (is_null($metadata->uuid)) {$changes['uuid'] = $uuid;}@@ -160,13 +165,14 @@ class VerifyFiles implements ShouldQueue {$mime_type = isset($changes['mime_type']) ? $changes['mime_type'] : $metadata->mime_type;- $audioMetadata = ((is_null($metadata->description) || (! is_null($metadata->date_scanned) && filemtime($filePath) > strtotime($metadata->date_scanned))) && is_null($metadata->season)) && str_starts_with($mime_type, 'audio') ? $this->getAudioDescription($filePath, $fileMetaData ?? null) : [];+ // if description is null and episode is null and the file is of type audio, generate description from audio tags+ $audioMetadata = is_null($metadata->description) && is_null($metadata->episode) && str_starts_with($mime_type, 'audio') ? $this->getAudioDescription($filePath, $fileMetaData ?? null) : [];if ((is_null($metadata->poster_url) || filemtime($filePath)) && $mime_type && str_starts_with($mime_type, 'audio')) {$relativePath = $video->folder->path . '/' . $metadata->id;$coverArtPath = "posters/audio/$relativePath-$uuid.png";- $coverArtUrl = $this->checkAlbumArt($filePath, $coverArtPath);+ $coverArtUrl = $this->checkAlbumArt($filePath, $coverArtPath, $fileUpdated);if ($coverArtUrl) {$changes['poster_url'] = $coverArtUrl;}@@ -204,6 +210,10 @@ class VerifyFiles implements ShouldQueue {}}+ if ((isNull($metadata->title) || $fileUpdated) && str_starts_with($mime_type, 'audio') && isset($audioMetadata['title'])) {+ $changes['title'] = $audioMetadata['title'];+ }+if (is_null($metadata->date_released)) {$changes['date_released'] = null;}@@ -313,12 +323,13 @@ class VerifyFiles implements ShouldQueue {$metadata = $this->getFileMetadata($filePath);}+ $title = $metadata['tags']['title'];$description = $metadata['tags']['artist'] ?? '';$description = ($description ? ($description . ' - ') : '') . ($metadata['tags']['album'] ?? '');$season = isset($metadata['tags']['disc']) ? (int) explode($metadata['tags']['disc'], '/')[0] ?? null : null;$episode = isset($metadata['tags']['track']) ? (int) explode($metadata['tags']['track'], '/')[0] ?? null : null;- return ['description' => $description === '' ? null : $description, 'season' => $season, 'episode' => $episode];+ return ['title' => $title, 'description' => $description === '' ? null : $description, 'season' => $season, 'episode' => $episode];}private function getPathUrl($path) {@@ -328,16 +339,19 @@ class VerifyFiles implements ShouldQueue {return Storage::disk('public')->url($path);}- private function checkAlbumArt($filePath, $coverArtPath) {- if (Storage::disk('public')->exists($coverArtPath)) {+ private function checkAlbumArt($filePath, $coverArtPath, $recentlyUpdated = false) {+ // If album art already exists and the file has not been updated since last scan date (cover art has not changed) then just return the existing image+ if (Storage::disk('public')->exists($coverArtPath) && !$recentlyUpdated) {return $this->getPathUrl($coverArtPath);- } else {- $coverGenerated = $this->extractAlbumArt($filePath, $coverArtPath);- if ($coverGenerated) {- Storage::disk('public')->put($coverArtPath, $coverGenerated);+ }- return $this->getPathUrl($coverArtPath);- }+ // If album art exists and the file was recently updated, overrite the old image++ $coverGenerated = $this->extractAlbumArt($filePath, $coverArtPath);+ if ($coverGenerated) {+ Storage::disk('public')->put($coverArtPath, $coverGenerated);++ return $this->getPathUrl($coverArtPath);}return null;diff --git a/resources/js/components/dashboard/DashboardTasks.vue b/resources/js/components/dashboard/DashboardTasks.vueindex 5a7e8c8d..533dd7a2 100644--- a/resources/js/components/dashboard/DashboardTasks.vue+++ b/resources/js/components/dashboard/DashboardTasks.vue@@ -63,7 +63,7 @@ const sortingOptions = [},];-const { stateTasks } = storeToRefs(useDashboardStore()) as { stateTasks: Ref<TaskResource[]> };+const { stateTasks, stateTaskStats } = storeToRefs(useDashboardStore()) as { stateTasks: Ref<TaskResource[]>; stateTaskStats: Ref<TaskStatsResponse> };const liveUpdate = subscribeToDaskboardTasks();@@ -75,7 +75,6 @@ const deleteModal = useModal({ title: 'Remove task from records?', submitText: 'const isScreenSmall = ref(false);const isScreenLarge = ref(false);const searchQuery = ref('');-const taskStats = ref<TaskStatsResponse>();const cachedID = ref<number | null>(null);const filteredTasks = computed(() => {@@ -172,11 +171,12 @@ const submitSubTaskDelete = async (id: number) => {};const loadData = async () => {- const { data: rawTaskStats } = await getTaskStats();+ // const { data: rawTaskStats } = await getTaskStats();- taskStats.value = rawTaskStats;+ // taskStats.value = rawTaskStats;queryClient.invalidateQueries({ queryKey: ['tasks'] });+ queryClient.invalidateQueries({ queryKey: ['taskStats'] });// const { data: rawTasks } = await getTasks();// stateTasks.value = rawTasks?.data?.length > 0 ? rawTasks.data : [];@@ -287,8 +287,8 @@ onUnmounted(() => {</ButtonText></div><div class="capitalize text-sm font-medium text-neutral-600 dark:text-neutral-300 flex flex-col gap-1 w-fit text-end">- <p class="w-fit">Running Tasks: {{ taskStats?.count_running }}</p>- <p class="w-fit">Total Tasks: {{ stateTasks.length ?? taskStats?.count_tasks }}</p>+ <p class="w-fit">Running Tasks: {{ stateTaskStats?.count_running }}</p>+ <p class="w-fit">Total Tasks: {{ stateTasks.length ?? stateTaskStats?.count_tasks }}</p></div></div><TableBasediff --git a/resources/js/components/pinesUI/ToastController.vue b/resources/js/components/pinesUI/ToastController.vueindex 99de082b..e50eb260 100755--- a/resources/js/components/pinesUI/ToastController.vue+++ b/resources/js/components/pinesUI/ToastController.vue@@ -338,7 +338,7 @@ watchEffect((onInvalidate) => {ref="container":tabIndex="-1":class="- `fixed w-full ${TOAST_WIDTH ? `sm:w-[${TOAST_WIDTH}px]` : 'sm:max-w-sm'} group z-[99] [&>*]:px-4 [&>*]:px-[${mobileViewportOffset ?? viewportOffset}] [&>*]:sm:px-6 [&>*]:sm:px-[${viewportOffset}] my-4 sm:my-6 my-[${mobileViewportOffset ?? viewportOffset}] sm:my-[${viewportOffset}] ` ++ `fixed w-full ${TOAST_WIDTH ? `sm:w-[${TOAST_WIDTH}px]` : 'sm:max-w-sm'} group z-[500] [&>*]:px-4 [&>*]:px-[${mobileViewportOffset ?? viewportOffset}] [&>*]:sm:px-6 [&>*]:sm:px-[${viewportOffset}] my-4 sm:my-6 my-[${mobileViewportOffset ?? viewportOffset}] sm:my-[${viewportOffset}] ` +`${position == 'top-right' ? 'right-0 top-0' : ''} ` +`${position == 'top-left' ? 'left-0 top-0' : ''} ` +`${position == 'top-center' ? 'left-1/2 -translate-x-1/2 top-0' : ''} ` +diff --git a/resources/js/components/video/VideoAmbientPlayer.vue b/resources/js/components/video/VideoAmbientPlayer.vueindex a9dc6c81..5f8c8ddb 100755--- a/resources/js/components/video/VideoAmbientPlayer.vue+++ b/resources/js/components/video/VideoAmbientPlayer.vue@@ -1,18 +1,21 @@<script setup lang="ts">-import VideoPlayer from './VideoPlayer.vue';-+import { onMounted, onUnmounted, ref, useTemplateRef, watch } from 'vue';+import { useAppStore } from '@/stores/AppStore';import { storeToRefs } from 'pinia';-import { useAppStore } from '../../stores/AppStore';-import { onMounted, onUnmounted, ref, watch } from 'vue';++import VideoPlayer from '@/components/video/VideoPlayer.vue';++const { lightMode, ambientMode } = storeToRefs(useAppStore());const container = ref<null | HTMLElement>(null);const player = ref<null | HTMLVideoElement>(null);+const audioPoster = ref<null | HTMLDivElement>(null);const step = ref<undefined | number>(undefined);const canvas = ref<null | HTMLCanvasElement>(null);const ctx = ref<null | CanvasRenderingContext2D>(null);-const appStore = useAppStore();-const { lightMode, ambientMode } = storeToRefs(appStore);+const videoPlayer = useTemplateRef('video-player');+const isAudio = ref(false);const draw = () => {if (!ctx.value || !player.value || !canvas.value) return;@@ -68,6 +71,11 @@ watch(},);+watch([videoPlayer, () => videoPlayer?.value?.isAudio], () => {+ if (!videoPlayer.value) return;+ isAudio.value = videoPlayer.value?.isAudio ?? false;+});+watch(player, (newVal) => {if (newVal) {newVal.addEventListener('loadedmetadata', adjustOverlayDiv);@@ -84,7 +92,7 @@ watch(player, (newVal) => {> --><canvasv-cloak- v-show="!lightMode && ambientMode"+ v-show="!lightMode && ambientMode && !isAudio"width="10"height="6"aria-hidden="true"@@ -93,8 +101,10 @@ watch(player, (newVal) => {>Canvas</canvas>+ <img v-show="isAudio" class="absolute z-10 opacity-100 blur pointer-events-none w-full h-full" :src="videoPlayer?.audioPoster ?? ''" /><!-- </span> --><VideoPlayer+ ref="video-player"class="z-10 w-full"@loadedData="draw"@seeked="draw"diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vueindex 0b0bd4d1..b33e5a67 100755--- a/resources/js/components/video/VideoPlayer.vue+++ b/resources/js/components/video/VideoPlayer.vue@@ -29,6 +29,7 @@ const progressCache = ref<{ metadata_id: number; progress: number }[]>([]);const metadata_id = ref<number>(NaN);const currentID = ref(-1);const isAudio = ref(false);+const audioPoster = ref('https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg');const player = ref<null | HTMLVideoElement>(null);// const url = ref('');@@ -147,6 +148,10 @@ const initVideoPlayer = async () => {metadata_id.value = stateVideo.value?.metadata ? stateVideo.value?.metadata.id : NaN;isAudio.value = stateVideo.value.metadata?.mime_type?.startsWith('audio') ?? false;+ audioPoster.value =+ handleStorageURL(stateVideo.value?.metadata?.poster_url) ??+ handleStorageURL(stateFolder.value.series?.thumbnail_url) ??+ 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg';// url.value = await getMediaUrl(stateVideo.value.path ?? '');};@@ -283,18 +288,20 @@ onMounted(() => {onUnmounted(() => {debouncedCacheVolume.cancel();});++defineExpose({+ isAudio,+ audioPoster,+});</script><template><div class="relative group rounded-xl overflow-clip"><divv-if="isAudio"+ id="audio-poster"class="absolute top-0 left-0 w-full h-full blur"- :style="`background: transparent url('${- handleStorageURL(stateVideo?.metadata?.poster_url) ??- handleStorageURL(stateFolder.series?.thumbnail_url) ??- 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'- }') 50% 50% / cover no-repeat`"+ :style="`background: transparent url('${audioPoster}') 50% 50% / cover no-repeat`"></div><videoid="vid-source"@@ -305,13 +312,7 @@ onUnmounted(() => {style="z-index: 3":src="stateVideo?.path ? `../${stateVideo?.path}` : ''":class="`relative focus:outline-none flex object-contain ${stateVideo?.path ? (isAudio ? 'max-h-[60vh]' : '') : 'aspect-video'}`"- :poster="- isAudio- ? (handleStorageURL(stateVideo?.metadata?.poster_url) ??- handleStorageURL(stateFolder.series?.thumbnail_url) ??- 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg')- : ''- "+ :poster="isAudio ? audioPoster : ''"@play="onPlayerPlay"@pause="onPlayerPause"@ended="onPlayerEnded"diff --git a/resources/js/service/queries.ts b/resources/js/service/queries.tsindex cc1148ec..959e347b 100644--- a/resources/js/service/queries.ts+++ b/resources/js/service/queries.ts@@ -1,7 +1,7 @@-import type { PulseResponse, SiteAnalyticsResponse } from '@/types/types.ts';+import type { PulseResponse, SiteAnalyticsResponse, TaskStatsResponse } from '@/types/types.ts';import type { Ref } from 'vue';-import { getSiteAnalytics, getPulse, getUsers, getTasks } from '@/service/siteAPI.ts';+import { getSiteAnalytics, getPulse, getUsers, getTasks, getTaskStats } from '@/service/siteAPI.ts';import { useQuery } from '@tanstack/vue-query';import mediaAPI, { getCategories } from '@/service/mediaAPI.ts';@@ -78,6 +78,16 @@ export const useGetTasks = () => {});};+export const useGetTaskStats = () => {+ return useQuery<{ data: TaskStatsResponse }>({+ queryKey: ['taskStats'],+ queryFn: async () => {+ const { data: response } = await getTaskStats();+ return response;+ },+ });+};+// export const useGetChatRoomMessagesQuery = (chat_id: number | null) => {// return useInfiniteQuery({// queryKey: ['chatroom-messages', chat_id],diff --git a/resources/js/stores/DashboardStore.ts b/resources/js/stores/DashboardStore.tsindex a16e388e..a4d3b173 100644--- a/resources/js/stores/DashboardStore.ts+++ b/resources/js/stores/DashboardStore.ts@@ -1,20 +1,34 @@-import { type CategoryResource, type TaskResource, type UserResource } from '@/types/resources';+import { type CategoryResource, type FolderResource, type TaskResource, type UserResource } from '@/types/resources';import { ref, watch, type Ref } from 'vue';-import { useGetCategories, useGetTasks, useGetUsers } from '@/service/queries';+import { useGetCategories, useGetTasks, useGetTaskStats, useGetUsers } from '@/service/queries';import { defineStore } from 'pinia';+import type { TaskStatsResponse } from '@/types/types';+import { formatFileSize } from '@/service/util';export const useDashboardStore = defineStore('Dashboard', () => {const { data: rawCategories, isLoading: isLoadingLibraries } = useGetCategories();const { data: rawUsers, isLoading: isLoadingUsers } = useGetUsers();const { data: rawTasks, isLoading: isLoadingTasks } = useGetTasks();+ const { data: rawTaskStats, isLoading: isLoadingTaskStats } = useGetTaskStats();const stateLibraries = ref<CategoryResource[]>([]);const stateTasks = ref<TaskResource[]>([]);const stateUsers = ref<UserResource[]>([]);+ const stateTaskStats = ref<TaskStatsResponse>();+ const stateTotalLibrariesSize = ref();+watch(rawCategories, (v) => {stateLibraries.value = v?.data ?? [];++ if (!v.data) return;+ let totalSize = v.data.reduce(+ (total: number, library: CategoryResource) => total + library.folders.reduce((total: number, folder: FolderResource) => total + Number(folder.total_size), 0),+ 0,+ );++ if (!isNaN(totalSize)) stateTotalLibrariesSize.value = formatFileSize(totalSize);});watch(rawUsers, (v) => {@@ -25,6 +39,11 @@ export const useDashboardStore = defineStore('Dashboard', () => {stateTasks.value = v?.data ?? [];});+ watch(rawTaskStats, (v) => {+ if (!v) return;+ stateTaskStats.value = v;+ });+const updateSingleTask = (data: TaskResource) => {if (stateTasks.value.findIndex((task) => task.id === data.id) === -1) {stateTasks.value = [data, ...stateTasks.value];@@ -45,6 +64,8 @@ export const useDashboardStore = defineStore('Dashboard', () => {stateLibraries,stateTasks,stateUsers,+ stateTaskStats,+ stateTotalLibrariesSize,isLoadingLibraries,isLoadingUsers,isLoadingTasks,@@ -54,6 +75,7 @@ export const useDashboardStore = defineStore('Dashboard', () => {stateLibraries: Ref<CategoryResource[]>;stateTasks: Ref<TaskResource[]>;stateUsers: Ref<UserResource[]>;+ stateTaskStats: Ref<TaskStatsResponse>;isLoadingLibraries: Ref<boolean>;isLoadingUsers: Ref<boolean>;isLoadingTasks: Ref<boolean>;diff --git a/resources/js/views/DashboardView.vue b/resources/js/views/DashboardView.vueindex 9a24bef0..e70546af 100644--- a/resources/js/views/DashboardView.vue+++ b/resources/js/views/DashboardView.vue@@ -1,5 +1,5 @@<script setup lang="ts">-import { onMounted, ref, watch, type Component } from 'vue';+import { computed, onMounted, ref, watch, type Component, type Ref } from 'vue';import { useAppStore } from '@/stores/AppStore';import { storeToRefs } from 'pinia';import { useRoute } from 'vue-router';@@ -22,52 +22,58 @@ import LucideUsers from '~icons/lucide/users';import DashboardActivity from '@/components/dashboard/DashboardActivity.vue';import DashboardUsers from '@/components/dashboard/DashboardUsers.vue';import DashboardTasks from '@/components/dashboard/DashboardTasks.vue';+import { useDashboardStore } from '@/stores/DashboardStore';+import type { TaskStatsResponse } from '@/types/types';-const dashboardTabs: {- name: string;- title?: string;- description?: string;- info?: { value: string; icon?: Component };- icon?: Component;-}[] = [- {- name: 'overview',- title: 'Analytics',- description: 'Website Overview',- icon: ProiconsGraph,- },- {- name: 'libraries',- description: '',- info: { value: 'Total Size: ?' },- icon: ProiconsLibrary,- },- // {- // name: 'activity',- // description: '',- // info: { value: 'Logged Events: 686' },- // icon: ProiconsHistory,- // },- {- name: 'users',- description: '',- info: { value: 'Logged In: ?' },- icon: LucideUsers,- },- {- name: 'tasks',- description: '',- info: { value: 'Currently Running: ?' },- icon: CircumServer,- },-];+const { pageTitle, selectedSideBar } = storeToRefs(useAppStore());+const { stateTaskStats, stateTotalLibrariesSize } = storeToRefs(useDashboardStore()) as { stateTaskStats: Ref<TaskStatsResponse>; stateTotalLibrariesSize: Ref<string> };+const { cycleSideBar } = useAppStore();+const route = useRoute();const dashboardTab = ref<{ name: string; title?: string; icon?: any }>();-const route = useRoute();-const AppStore = useAppStore();-const { cycleSideBar } = AppStore;-const { pageTitle, selectedSideBar } = storeToRefs(AppStore);+const dashboardTabs = computed<+ {+ name: string;+ title?: string;+ description?: string;+ info?: { value: string; icon?: Component };+ icon?: Component;+ }[]+>(() => {+ return [+ {+ name: 'overview',+ title: 'Analytics',+ description: 'Website Overview',+ icon: ProiconsGraph,+ },+ {+ name: 'libraries',+ description: '',+ info: { value: `Total Size: ${stateTotalLibrariesSize?.value ?? '?'}` },+ icon: ProiconsLibrary,+ },+ // {+ // name: 'activity',+ // description: '',+ // info: { value: 'Logged Events: 686' },+ // icon: ProiconsHistory,+ // },+ {+ name: 'users',+ description: '',+ info: { value: 'Logged In: ?' },+ icon: LucideUsers,+ },+ {+ name: 'tasks',+ description: '',+ info: { value: `Currently Running: ${stateTaskStats.value?.count_running ?? '?'}` },+ icon: CircumServer,+ },+ ];+});onMounted(async () => {cycleSideBar('dashboard', 'left-card');@@ -77,7 +83,7 @@ watch(() => route?.params?.tab,(URL_TAB) => {if (!URL_TAB) return;- let defaultTab = dashboardTabs.find((tab) => (tab.title ?? tab.name) == URL_TAB) ?? dashboardTabs[0];+ let defaultTab = dashboardTabs.value.find((tab) => (tab.title ?? tab.name) == URL_TAB) ?? dashboardTabs.value[0];pageTitle.value = defaultTab.title ?? defaultTab.name;dashboardTab.value = defaultTab;@@ -128,11 +134,7 @@ watch(<component v-if="tab.icon" :is="tab.icon" class="ml-auto w-6 h-6" /></template><template #body>- <h3- v-if="tab.description"- title="Description"- class="text-neutral-500 w-full text-wrap truncate sm:text-nowrap flex-1"- >+ <h3 v-if="tab.description" title="Description" class="text-neutral-500 w-full text-wrap truncate sm:text-nowrap flex-1">{{ tab.description }}</h3><h3 v-if="tab.info" title="Information" class="truncate text-nowrap sm:text-right text-neutral-500 w-fit">