Skip to content

A self-hosted media server and file management system

feat: better thumbnail preview and responsiveness on small screens

aminnausin197717662cb9
diff --git a/resources/js/components/cards/data/VideoCard.vue b/resources/js/components/cards/data/VideoCard.vue
index 3c692fdd..2cc1bc8e 100644
--- a/resources/js/components/cards/data/VideoCard.vue
+++ b/resources/js/components/cards/data/VideoCard.vue
@@ -2,10 +2,10 @@
import type { ContextMenuItem } from '@/types/types';
import type { VideoResource } from '@/types/resources';
-import { formatFileSize, handleStorageURL, toFormattedDate, toPlural } from '@/service/util';
+import { formatFileSize, handleStorageURL, toFormattedDate, toFormattedDuration, toPlural } from '@/service/util';
import { getMediaDateDescription } from '@/service/media/mediaFormatter';
-import { computed, provide, toRef, type HTMLAttributes } from 'vue';
import { useContentStore } from '@/stores/ContentStore';
+import { computed, toRef } from 'vue';
import { useAuthStore } from '@/stores/AuthStore';
import { storeToRefs } from 'pinia';
import { useAppStore } from '@/stores/AppStore';
@@ -17,7 +17,6 @@ import { cn } from '@aminnausin/cedar-ui';
import TablerSubtitles from '@/components/icons/TablerSubtitles.vue';
import VideoPreview from '@/components/video/VideoPreview.vue';
import useMetaData from '@/composables/useMetaData';
-import LazyImage from '@/components/lazy/LazyImage.vue';
import MediaTag from '@/components/labels/MediaTag.vue';
import TablerMicrophone2 from '~icons/tabler/microphone-2';
@@ -41,7 +40,7 @@ const isAudio = computed(() => {
});
const posterUrl = computed(() => {
- const url = videoData.metadata?.poster_image?.path ?? handleStorageURL(videoData?.metadata?.poster_url);
+ const url = videoData.metadata?.poster_image?.path ?? handleStorageURL(videoData.metadata?.poster_url) ?? undefined;
const audioFallback = handleStorageURL(stateFolder.value.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp';
return isAudio.value ? (url ?? audioFallback) : url;
@@ -79,64 +78,42 @@ const contextMenuItems = computed(() => {
});
const dateInformation = computed(() => getMediaDateDescription(videoData));
-
-const generatePosterStyle = (): HTMLAttributes['style'] => {
- if (!posterUrl.value) return {};
-
- return {
- backgroundImage: `url("${posterUrl.value}")`,
- backgroundPosition: 'center',
- backgroundSize: 'cover',
- backgroundRepeat: 'no-repeat',
- };
-};
-
-provide('isAudio', isAudio);
</script>
<template>
<RouterLink
:to="encodeURI(`/${stateDirectory.name}/${stateFolder.name}?video=${videoData.id}${resumeOffset}`)"
- @contextmenu="
- (e: any) => {
- setContextMenu(e, { items: contextMenuItems });
- }
- "
:class="
cn(
'dark:hover:bg-primary-active/70 dark:bg-primary-dark-800/70 dark:odd:bg-primary-dark-600 hover:bg-primary/5 bg-neutral-50 odd:bg-neutral-100',
'relative flex rounded-md',
- 'data-card hover:data-card-hover overflow-clip shadow-sm focus-within:outline-none',
+ 'data-card hover:data-card-hover max-w-full overflow-clip shadow-sm focus-within:outline-none',
)
"
>
- <template v-if="posterUrl">
- <div v-if="isAudio" :class="['pointer-events-none relative z-0 size-24 overflow-clip']">
- <div id="audio-poster" :class="['transition-scale absolute inset-0 -z-1 scale-105 blur-sm ease-in-out']" :style="generatePosterStyle()"></div>
- <LazyImage
- :src="posterUrl"
- alt="album art"
- wrapper-class="flex items-center justify-center"
- :class="['mx-auto object-contain select-none md:h-screen']"
- loading="eager"
- fetchpriority="high"
- />
- </div>
- <div v-else :class="cn('relative flex items-center overflow-clip')">
- <img :src="posterUrl" class="absolute top-0 h-full object-cover blur-xs" />
- <VideoPreview
- :data="data"
- :data-active="currentID === videoData.id"
- :poster-url="data.metadata?.poster_image?.path ?? data.metadata?.poster_url"
- class="aspect-video h-24 shrink-0"
- />
- </div>
- </template>
+ <VideoPreview
+ :data="data"
+ :data-active="currentID === videoData.id"
+ :poster-url="posterUrl"
+ :is-audio="isAudio"
+ :is-folder-majority-audio="stateFolder.is_majority_audio"
+ :class="cn('shrink-0', stateFolder.is_majority_audio ? 'h-24' : 'h-20 sm:h-24')"
+ />
- <div class="flex flex-1 flex-col">
- <div class="flex flex-1 flex-col justify-between gap-x-8 gap-y-4 p-3">
- <div class="flex w-full items-center justify-between gap-4 overflow-hidden">
- <h3 class="line-clamp-1 min-w-8 break-all" :title="`Title: ${videoData.title}${videoData.name !== videoData.title ? `\nFile: ${videoData.name}` : ''}`">
+ <div
+ class="flex flex-1 flex-col text-xs sm:text-sm"
+ @contextmenu="
+ (e: any) => {
+ setContextMenu(e, { items: contextMenuItems });
+ }
+ "
+ >
+ <div class="flex flex-1 flex-col justify-between gap-x-8 gap-y-4 p-3 pb-2">
+ <div class="flex w-full items-center justify-between gap-x-4 gap-y-1 overflow-hidden">
+ <h3
+ class="line-clamp-1 min-w-8 text-sm break-all sm:text-base"
+ :title="`Title: ${videoData.title}${videoData.name !== videoData.title ? `\nFile: ${videoData.name}` : ''}`"
+ >
{{ title }}
</h3>
<div class="-ms-2 flex flex-1 gap-1">
@@ -149,12 +126,15 @@ provide('isAudio', isAudio);
:hover-card-leave-delay="300"
>
<template #trigger>
- <ProiconsComment class="my-auto size-5 shrink-0 opacity-100 transition-opacity duration-300 hover:opacity-20" title="Description" />
+ <ProiconsComment class="my-auto size-4 shrink-0 opacity-100 transition-opacity duration-300 hover:opacity-20 sm:size-5" title="Description" />
</template>
</HoverCard>
<HoverCard class="xs:block hidden" v-if="videoData.metadata?.lyrics" :content-title="'Has Lyrics'" :hover-card-delay="400" :hover-card-leave-delay="300">
<template #trigger>
- <TablerMicrophone2 class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Has Lyrics" />
+ <TablerMicrophone2
+ class="size-4 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20 sm:size-5"
+ title="Has Lyrics"
+ />
</template>
</HoverCard>
<HoverCard
@@ -165,7 +145,10 @@ provide('isAudio', isAudio);
:hover-card-leave-delay="300"
>
<template #trigger>
- <TablerSubtitles class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Has Subtitles" />
+ <TablerSubtitles
+ class="size-4 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20 sm:size-5"
+ title="Has Subtitles"
+ />
</template>
</HoverCard>
@@ -177,12 +160,15 @@ provide('isAudio', isAudio);
:hover-card-leave-delay="300"
>
<template #trigger>
- <ProiconsCheckmark class="size-5 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20" title="Completed" />
+ <ProiconsCheckmark
+ class="size-4 shrink-0 opacity-100 transition-opacity duration-300 *:stroke-[1.4px] hover:opacity-20 sm:size-5"
+ title="Completed"
+ />
</template>
</HoverCard>
</div>
- <div class="text-foreground-1 flex min-w-fit gap-1 text-sm uppercase *:text-nowrap">
+ <div class="text-foreground-1 xms:flex hidden gap-1 overflow-clip uppercase *:text-nowrap sm:min-w-fit">
<span v-if="videoData.file_size" :title="`File Size: ${formatFileSize(videoData.file_size)}`">
{{ formatFileSize(videoData.file_size) }}
</span>
@@ -198,22 +184,20 @@ provide('isAudio', isAudio);
</span>
</div>
</div>
- <div class="group text-foreground-1 flex w-full flex-wrap items-start justify-between gap-x-4 gap-y-2 overflow-x-clip text-sm sm:w-auto">
- <div class="flex items-center gap-2">
- <div class="flex gap-1">
- <span class="min-w-fit" :title="`View Count: ${views}`">
- {{ views }}
- </span>
+ <div class="group text-foreground-1 flex w-full flex-wrap items-start justify-between gap-2 overflow-x-clip sm:w-auto sm:gap-x-4">
+ <div class="flex items-center gap-1">
+ <span class="min-w-fit" :title="`View Count: ${views}`">
+ {{ views }}
+ </span>
- <span>|</span>
- <span class="text-nowrap" :title="`Duration: ${duration}`">
- {{ duration }}
- </span>
- </div>
+ <span>|</span>
+ <span class="text-nowrap" :title="`Duration: ${duration}`">
+ {{ toFormattedDuration(data.metadata?.duration ?? 0, false, 'analog', true) }}
+ </span>
</div>
<span
v-if="videoData.video_tags.length"
- class="order-3 flex w-full flex-wrap gap-1 overflow-clip [overflow-clip-margin:4px] sm:order-0 sm:h-5.5 sm:flex-1 sm:gap-y-2"
+ class="-order-1 w-full flex-wrap gap-1 overflow-clip [overflow-clip-margin:4px] *:w-fit *:text-xs sm:order-0 sm:flex sm:h-5.5 sm:flex-1 sm:gap-y-2 sm:*:text-sm"
title="Tags"
>
<MediaTag v-for="(tag, index) in videoData.video_tags" :key="index" :label="tag.name" />
@@ -221,7 +205,16 @@ provide('isAudio', isAudio);
<HoverCard class="text-end text-nowrap" :hover-card-delay="400" :hover-card-leave-delay="300" :content="dateInformation">
<template #trigger>
- {{ toFormattedDate(videoData.file_modified_at) }}
+ {{
+ toFormattedDate(videoData.file_modified_at, false, {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+ hour: 'numeric',
+ minute: '2-digit',
+ hour12: true,
+ })
+ }}
</template>
</HoverCard>
</div>
@@ -251,29 +244,30 @@ provide('isAudio', isAudio);
></div>
</div>
</div>
- <div
- v-if="videoData.progress_percentage"
- :class="
- cn(
- 'playback-progress-bar flex h-1',
- 'duration-input mt-auto bg-neutral-300 opacity-80 transition-[translate,opacity,margin] dark:bg-neutral-700 dark:opacity-60',
- {
- 'me-0.5 -translate-y-0.5 opacity-100 dark:opacity-100': currentID === videoData.id,
- 'in-focus:me-0.5 in-focus:-translate-y-0.5': currentID !== videoData.id,
- },
- )
- "
- :title="`Progress: ${videoData.progress_percentage}s`"
- >
+ <div :class="cn('duration-input opacity-0 transition-opacity', { 'opacity-100': videoData.progress_percentage })">
<div
:class="
- cn('bg-foreground-3 duration-input mt-auto h-full w-full transition-[background-color]', {
- 'bg-primary-muted dark:in-focus:bg-primary dark:bg-primary-active': currentID === videoData.id,
- 'playback-progress-fill': currentID !== videoData.id,
- })
+ cn(
+ 'playback-progress-bar flex h-1',
+ 'duration-input mt-auto bg-neutral-300 opacity-80 transition-[translate,opacity,margin] dark:bg-neutral-700 dark:opacity-60',
+ {
+ 'me-0.5 -translate-y-0.5 opacity-100 dark:opacity-100': currentID === videoData.id,
+ 'in-focus:me-0.5 in-focus:-translate-y-0.5': currentID !== videoData.id,
+ },
+ )
"
- :style="{ width: `${videoData.progress_percentage}%` }"
- ></div>
+ :title="`Progress: ${videoData.progress_percentage}s`"
+ >
+ <div
+ :class="
+ cn('bg-foreground-3 duration-input mt-auto h-full w-full transition-[background-color]', {
+ 'bg-primary-muted dark:in-focus:bg-primary dark:bg-primary-active': currentID === videoData.id,
+ 'playback-progress-fill': currentID !== videoData.id,
+ })
+ "
+ :style="{ width: `${videoData.progress_percentage}%` }"
+ ></div>
+ </div>
</div>
<div
:class="
diff --git a/resources/js/components/video/VideoPreview.vue b/resources/js/components/video/VideoPreview.vue
index 19bbaf5b..f372882e 100644
--- a/resources/js/components/video/VideoPreview.vue
+++ b/resources/js/components/video/VideoPreview.vue
@@ -1,4 +1,5 @@
<script setup lang="ts">
+import type { HTMLAttributes } from 'vue';
import type { StoryboardCue } from '@/service/storyboard/types';
import type { VideoResource } from '@/contracts/media';
@@ -8,6 +9,7 @@ import { toFormattedDuration } from '@/service/util';
import { cn } from '@aminnausin/cedar-ui';
import VideoControlWrapper from '@/components/video/VideoControlWrapper.vue';
+import ProIconsPhotoOff from '@/components/icons/ProIconsPhotoOff.vue';
import LazyImage from '@/components/lazy/LazyImage.vue';
const PREVIEW_FRAME_COUNT = 10;
@@ -16,9 +18,13 @@ const props = defineProps<{
data: VideoResource;
dataActive: boolean;
posterUrl?: string;
+ isAudio?: boolean;
+ isFolderMajorityAudio?: boolean;
}>();
const scrubContainer = useTemplateRef('scrubContainer');
+
+const containerRect = ref<DOMRect | null>(null);
const hoverProgress = ref(0);
const hovered = ref(false);
@@ -27,7 +33,7 @@ const previewCues = computed<StoryboardCue[]>(() => {
const durationSeconds = props.data.duration;
const storyboard = props.data.storyboard;
- if (!storyboard || !uuid || !durationSeconds) return [];
+ if (props.isAudio || !storyboard || !uuid || !durationSeconds) return [];
const storyboardCues = buildStoryboardCues(uuid, durationSeconds, storyboard);
@@ -51,73 +57,146 @@ const activeCue = computed<StoryboardCue | undefined>(() => {
return previewCues.value[index];
});
-const spriteStyle = computed(() => {
+const spriteStyle = computed<HTMLAttributes['style']>(() => {
+ if (props.isAudio) return {};
+
const c = activeCue.value;
const storyboard = props.data.storyboard;
if (!c || c.x === undefined || !storyboard || !scrubContainer.value) return undefined;
- const containerWidth = scrubContainer.value.getBoundingClientRect().width;
- const scale = containerWidth / c.w;
+ const { width: maxWidth, height: maxHeight } = containerRect.value ?? scrubContainer.value.getBoundingClientRect();
+
+ const scaleX = maxWidth / c.w;
+ const scaleY = maxHeight / c.h;
+ const scale = Math.min(scaleX, scaleY);
return {
backgroundImage: `url(${c.image})`,
backgroundPosition: `-${c.x * scale}px -${c.y * scale}px`,
backgroundSize: `${c.w * storyboard.tile_cols * scale}px ${c.h * storyboard.tile_rows * scale}px`,
+ width: `${c.w * scale}px`,
+ height: `${c.h * scale}px`,
};
});
const timestamp = computed(() => {
- if (!props.data.duration) return '';
+ if (props.isAudio || !props.data.duration) return '';
return `${toFormattedDuration(hoverProgress.value, false, 'digital', true)}`;
});
+function onTouchStart(e: TouchEvent) {
+ if (props.isAudio) return;
+ hovered.value = true;
+ updateProgressFromX(e.touches[0].clientX);
+}
+
+function onTouchMove(e: TouchEvent) {
+ if (props.isAudio) return;
+ updateProgressFromX(e.touches[0].clientX);
+}
+
+function onTouchEnd() {
+ hovered.value = false;
+ hoverProgress.value = 0;
+}
+
+function updateProgressFromX(clientX: number) {
+ const rect = scrubContainer.value!.getBoundingClientRect();
+ const ratio = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
+ hoverProgress.value = ratio * (props.data.duration ?? 0);
+}
+
// Could debounce
function onMouseMove(e: MouseEvent) {
- const el = e.currentTarget as HTMLElement;
- const rect = el.getBoundingClientRect();
- const ratio = (e.clientX - rect.left) / rect.width;
- const duration = props.data.duration ?? 0;
- hoverProgress.value = ratio * duration;
+ if (props.isAudio) return;
+ updateProgressFromX(e.clientX);
}
+
+function onMouseEnter() {
+ hovered.value = true;
+ containerRect.value = scrubContainer.value?.getBoundingClientRect() ?? null;
+}
+
+// I could use blur hash instead
+const generatePosterStyle = (url?: string): HTMLAttributes['style'] => {
+ if (!url) return {};
+
+ return {
+ backgroundImage: `url("${url}")`,
+ backgroundPosition: 'center',
+ backgroundSize: 'cover',
+ backgroundRepeat: 'no-repeat',
+ };
+};
+
+defineOptions({
+ inheritAttrs: false,
+});
</script>
<template>
<div
- :class="['group relative aspect-video size-full', $attrs.class]"
- :style="spriteStyle"
- @mouseenter="hovered = true"
+ :class="cn('group relative flex items-center overflow-clip')"
+ @mouseenter="onMouseEnter"
@mouseleave="hovered = false"
@mousemove="onMouseMove"
+ @touchstart.passive="onTouchStart"
+ @touchmove.passive="onTouchMove"
+ @touchend="onTouchEnd"
ref="scrubContainer"
>
- <LazyImage
- :src="posterUrl"
- alt="poster"
- :class="
- cn('absolute inset-0 size-full cursor-crosshair object-cover opacity-100', {
- 'transition-opacity group-hover:opacity-0': activeCue,
- })
- "
- />
- </div>
-
- <div
- v-if="hovered && activeCue && data.duration"
- :class="
- cn('duration-input pointer-events-none absolute inset-0 z-3 flex flex-col justify-end gap-1 opacity-0 transition-[translate,opacity,margin]', {
- 'opacity-100': hovered,
- 'ms-0.5 -translate-y-0.5': dataActive,
- })
- "
- >
- <VideoControlWrapper class="ml-1 w-fit">
- <p :class="cn('font-figtree px-1 text-xs text-white tabular-nums text-shadow-lg')">
- {{ timestamp }}
- </p>
- </VideoControlWrapper>
- <div :class="cn('h-1 w-full bg-white/20')">
- <div class="h-full bg-white" :style="{ width: `${(hoverProgress / data.duration) * 100}%` }" />
+ <template v-if="posterUrl">
+ <div :class="[isFolderMajorityAudio ? 'aspect-square' : 'aspect-video', 'size-full', $attrs.class]">
+ <div class="absolute inset-0 scale-120 blur-sm" :style="generatePosterStyle(posterUrl)"></div>
+
+ <LazyImage
+ :src="posterUrl"
+ alt="poster"
+ :animate="true"
+ loading="eager"
+ fetchpriority="high"
+ :wrapper-class="
+ cn('transition-opacity duration-input', {
+ 'opacity-0': hovered && activeCue,
+ })
+ "
+ :class="cn('absolute inset-0 size-full cursor-crosshair object-contain')"
+ />
+ <div
+ :class="
+ cn('duration-input absolute inset-0 flex items-center justify-center opacity-0 transition-opacity', {
+ 'opacity-100': hovered && activeCue,
+ })
+ "
+ >
+ <div class="h-full w-fit bg-cover" :style="spriteStyle"></div>
+ </div>
+ </div>
+
+ <!-- Overlay -->
+ <div
+ v-if="hovered && activeCue && data.duration"
+ :class="
+ cn('duration-input pointer-events-none absolute inset-0 z-3 flex flex-col justify-end gap-1 opacity-0 transition-[translate,opacity,margin]', {
+ 'opacity-100': hovered,
+ 'ms-0.5 -translate-y-0.5': dataActive,
+ })
+ "
+ >
+ <VideoControlWrapper class="ml-1 w-fit">
+ <p :class="cn('font-figtree px-1 text-xs text-white tabular-nums text-shadow-lg')">
+ {{ timestamp }}
+ </p>
+ </VideoControlWrapper>
+ <div :class="cn('h-1 w-full bg-white/20')">
+ <div class="h-full bg-white" :style="{ width: `${(hoverProgress / data.duration) * 100}%` }" />
+ </div>
+ </div>
+ </template>
+
+ <div v-else :class="cn('bg-surface-3 flex aspect-video h-24 shrink-0 items-center justify-center dark:bg-neutral-900/80', { 'w-24': isFolderMajorityAudio })">
+ <ProIconsPhotoOff class="text-foreground-1 size-5" />
</div>
</div>
</template>