mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-26 16:39:41 -05:00
convert it to composition API + ts
This commit is contained in:
4 files changed
+1890
-1820
No files matched your search
@@ -143,6 +143,7 @@ import {
|
||||
writeMobileLyricsOpen,
|
||||
} from "@/composables/player/playerStorage.ts";
|
||||
import { useAudioVisualizer } from "@/composables/player/useAudioVisualizer.ts";
|
||||
import { useEmbeddedArtwork } from "@/composables/player/useEmbeddedArtwork.ts";
|
||||
import { useDoubleTapSeek } from "@/composables/player/useDoubleTapSeek.ts";
|
||||
import { useFullscreenState } from "@/composables/player/useFullscreenState.ts";
|
||||
import { useGestureState } from "@/composables/player/useGestureState.ts";
|
||||
@@ -205,8 +206,6 @@ const audioElement = useTemplateRef<HTMLAudioElement>("audioElement");
|
||||
const gestureRoot = useTemplateRef<HTMLElement>("gestureRoot");
|
||||
|
||||
// --- Metadata and album art ---
|
||||
const metadata = ref<AudioMetadata | null>(null);
|
||||
const albumArtUrl = ref<string | null>(null);
|
||||
// Storage keys (plyrAlbumArtSize, plyrShowDesktopPanel, plyrShowMobileLyrics) keep the legacy prefix so saved preferences survive.
|
||||
const albumArtSize = ref(readAlbumArtSize());
|
||||
const isHovering = ref(false);
|
||||
@@ -217,6 +216,10 @@ const isMobile = computed(() => getters.isMobile());
|
||||
const filetype = computed(() => getTypeFromMime(props.req.type || ""));
|
||||
const formattedArtist = computed(() => formatArtist(metadata.value?.artist ?? ""));
|
||||
const fileName = computed(() => (props.req.name ? props.req.name.replace(/\.[^/.]+$/, "") : ""));
|
||||
const { metadata, albumArtUrl, loadMediaMetadata, cleanupAlbumArt } = useEmbeddedArtwork({
|
||||
getMetadata: () => props.req.metadata,
|
||||
getFileName: () => fileName.value,
|
||||
});
|
||||
const artworkUrl = computed(() => albumArtUrl.value || undefined);
|
||||
const desktopPanelToggleLabel = computed(() =>
|
||||
showDesktopPanel.value ? t("player.closePanel") : t("player.openPanel"),
|
||||
@@ -240,33 +243,6 @@ function onAlbumArtScroll(event: WheelEvent): void {
|
||||
albumArtSize.value = Math.max(10, Math.min(50, albumArtSize.value + scrollDelta));
|
||||
}
|
||||
|
||||
/** Reads the metadata the parent already fetched from the backend. */
|
||||
function loadMediaMetadata(): void {
|
||||
const meta = props.req.metadata;
|
||||
metadata.value = {
|
||||
title: meta?.title || fileName.value, // Fallback to filename
|
||||
artist: meta?.artist,
|
||||
album: meta?.album,
|
||||
year: meta?.year,
|
||||
};
|
||||
if (!meta?.albumArt) return;
|
||||
try {
|
||||
const bytes = Uint8Array.from(atob(meta.albumArt), (c) => c.charCodeAt(0));
|
||||
albumArtUrl.value = URL.createObjectURL(new Blob([bytes], { type: "image/jpeg" }));
|
||||
} catch (error) {
|
||||
console.error("Failed to decode album art:", error);
|
||||
albumArtUrl.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupAlbumArt(): void {
|
||||
if (albumArtUrl.value?.startsWith("blob:")) {
|
||||
URL.revokeObjectURL(albumArtUrl.value);
|
||||
}
|
||||
albumArtUrl.value = null;
|
||||
metadata.value = null;
|
||||
}
|
||||
|
||||
watch(showDesktopPanel, writeDesktopPanelOpen);
|
||||
watch(albumArtSize, writeAlbumArtSize);
|
||||
watch(showMobileLyrics, writeMobileLyricsOpen);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,48 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
export interface EmbeddedMetadata {
|
||||
title?: string;
|
||||
artist?: string;
|
||||
album?: string;
|
||||
year?: string | number;
|
||||
}
|
||||
|
||||
interface EmbeddedArtworkOptions {
|
||||
/** `req.metadata` as returned by the backend; `albumArt` is base64 encoded. */
|
||||
getMetadata: () => (EmbeddedMetadata & { albumArt?: string }) | undefined;
|
||||
getFileName: () => string;
|
||||
}
|
||||
|
||||
/** Title/artist/album and the embedded cover art of the current file, shared by the audio and video players. */
|
||||
export function useEmbeddedArtwork({ getMetadata, getFileName }: EmbeddedArtworkOptions) {
|
||||
const metadata = ref<EmbeddedMetadata | null>(null);
|
||||
const albumArtUrl = ref<string | null>(null);
|
||||
|
||||
function loadMediaMetadata(): void {
|
||||
const meta = getMetadata();
|
||||
metadata.value = {
|
||||
title: meta?.title || getFileName(), // Fallback to filename
|
||||
artist: meta?.artist,
|
||||
album: meta?.album,
|
||||
year: meta?.year,
|
||||
};
|
||||
if (!meta?.albumArt) return;
|
||||
try {
|
||||
const bytes = Uint8Array.from(atob(meta.albumArt), (c) => c.charCodeAt(0));
|
||||
albumArtUrl.value = URL.createObjectURL(new Blob([bytes], { type: "image/jpeg" }));
|
||||
} catch (error) {
|
||||
console.error("Failed to decode album art:", error);
|
||||
albumArtUrl.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupAlbumArt(): void {
|
||||
if (albumArtUrl.value?.startsWith("blob:")) {
|
||||
URL.revokeObjectURL(albumArtUrl.value);
|
||||
}
|
||||
albumArtUrl.value = null;
|
||||
metadata.value = null;
|
||||
}
|
||||
|
||||
return { metadata, albumArtUrl, loadMediaMetadata, cleanupAlbumArt };
|
||||
}
|
||||
@@ -28,8 +28,7 @@
|
||||
/>
|
||||
<VideoPlayer v-else
|
||||
:key="viewerKey"
|
||||
ref="viewerRef"
|
||||
:previewType="previewType"
|
||||
ref="videoRef"
|
||||
:raw="raw"
|
||||
:subtitlesList="subtitlesList"
|
||||
:req="req"
|
||||
@@ -140,7 +139,7 @@ interface SubtitleSource {
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const viewerRef = useTemplateRef<{ destroyPlyr?: () => void }>("viewerRef");
|
||||
const videoRef = useTemplateRef<{ destroy?: () => void }>("videoRef");
|
||||
const audioRef = useTemplateRef<{ destroy?: () => void }>("audioRef");
|
||||
|
||||
const subtitlesList = ref<SubtitleSource[]>([]);
|
||||
@@ -167,7 +166,7 @@ const {
|
||||
} = usePreviewNavigation({
|
||||
onBeforeTeardown: () => {
|
||||
audioRef.value?.destroy?.();
|
||||
viewerRef.value?.destroyPlyr?.();
|
||||
videoRef.value?.destroy?.();
|
||||
disposeTranscodePlaybackController();
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user