Skip to content

A self-hosted media server and file management system

feat: share at timestamp

aminnausin7998fe6e28ec
diff --git a/resources/js/components/modals/ShareModal.vue b/resources/js/components/modals/ShareModal.vue
index 23746cf1..ccf4d547 100644
--- a/resources/js/components/modals/ShareModal.vue
+++ b/resources/js/components/modals/ShareModal.vue
@@ -1,15 +1,70 @@
<script setup lang="ts">
+import { toFormattedDuration } from '@/service/util';
import { CopyToClipboard } from '@/components/cedar-ui/clipboard';
import { useModalStore } from '@/stores/ModalStore';
+import { computed, ref } from 'vue';
import { BaseModal } from '@/components/cedar-ui/modal';
+import { TextInput } from '../cedar-ui/input';
+import { FormLabel } from '../cedar-ui/form';
+
+import ToggleBase from '../inputs/ToggleBase.vue';
+import { cn } from '@aminnausin/cedar-ui';
const modalStore = useModalStore();
+
+const timestampFormatted = ref();
+const timestampSeconds = ref();
+const useTimestamp = ref(false);
+
+const shareLink = computed(() => {
+ return useTimestamp.value && timestampSeconds.value ? `${modalStore.props.shareLink}&t=${timestampSeconds.value}` : modalStore.props.shareLink;
+});
+
+const formatTimestamp = (value: string) => {
+ if (!value) {
+ timestampFormatted.value = toFormattedDuration(0, true, 'digital');
+ return;
+ }
+ const parts = value
+ .split(':')
+ .reverse()
+ .map((p) => parseInt(p) || 0);
+ const multipliers = [1, 60, 3600];
+
+ const seconds = parts.reduce((total, part, i) => total + part * (multipliers[i] ?? 0), 0);
+ timestampSeconds.value = seconds;
+ timestampFormatted.value = toFormattedDuration(seconds, true, 'digital');
+};
+
+formatTimestamp(`${modalStore.props.defaultTimestamp}`);
</script>
<template>
<BaseModal>
<template #title>{{ modalStore.props.title }}</template>
<template #description> Copy link to clipboard to share it.</template>
- <CopyToClipboard :text="modalStore.props.shareLink" />
+ <CopyToClipboard :text="shareLink" />
+ <div v-if="modalStore.props.defaultTimestamp !== undefined" class="flex items-center gap-1 text-sm">
+ <ToggleBase
+ v-model="useTimestamp"
+ :name="'use-share-timestamp'"
+ class="mr-2 h-6 w-12 shrink-0 rounded-full dark:border-neutral-700/70 dark:has-checked:border-neutral-700"
+ />
+ <FormLabel :text="'Start at'" :for="'use-share-timestamp'" class="text-nowrap" />
+ <TextInput
+ :class="
+ cn(
+ 'h-6 w-auto rounded-none bg-transparent! px-0 font-mono shadow-none ring-0!',
+ 'focus:border-foreground-0 mt-0.5 border-0 border-b border-solid border-b-transparent text-center transition-colors focus-within:border-b',
+ 'disabled:opacity-disabled',
+ )
+ "
+ :style="{ width: `${timestampFormatted?.length + 1 || 6}ch`, 'min-width': '6ch' }"
+ id="share-timestamp"
+ v-model="timestampFormatted"
+ :disabled="!useTimestamp"
+ @blur="formatTimestamp(timestampFormatted)"
+ />
+ </div>
</BaseModal>
</template>
diff --git a/resources/js/components/video/VideoAmbientPlayer.vue b/resources/js/components/video/VideoAmbientPlayer.vue
index ebcda83a..4deef090 100755
--- a/resources/js/components/video/VideoAmbientPlayer.vue
+++ b/resources/js/components/video/VideoAmbientPlayer.vue
@@ -225,6 +225,10 @@ watch(
if (next?.id !== prev.id) drawPause(true);
},
);
+
+defineExpose({
+ getCurrentTime: () => videoPlayer.value?.getCurrentTime() ?? 0,
+});
</script>
<template>
diff --git a/resources/js/components/video/VideoInfoPanel.vue b/resources/js/components/video/VideoInfoPanel.vue
index f385cd83..308ed204 100755
--- a/resources/js/components/video/VideoInfoPanel.vue
+++ b/resources/js/components/video/VideoInfoPanel.vue
@@ -33,6 +33,8 @@ import CircumEdit from '~icons/circum/edit';
const defaultDescription = `No description yet.`;
+const props = defineProps<{ getCurrentTime: () => number }>();
+
const { stateVideo, stateFolder } = storeToRefs(useContentStore());
const { userData } = storeToRefs(useAuthStore());
const { title, description: parsedDescription, views } = useMetaData(stateVideo);
@@ -92,7 +94,11 @@ const handleShare = () => {
return;
}
- modal.open(ShareModal, { title: `Share ${mediaTypeDescription.value}`, shareLink: `${document.location.origin}${route.path}?video=${stateVideo.value.id}` });
+ modal.open(ShareModal, {
+ title: `Share ${mediaTypeDescription.value}`,
+ shareLink: `${document.location.origin}${route.path}?video=${stateVideo.value.id}`,
+ defaultTimestamp: props.getCurrentTime(),
+ });
};
const handleEdit = () => {
diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vue
index 41ed4795..7a7b098a 100755
--- a/resources/js/components/video/VideoPlayer.vue
+++ b/resources/js/components/video/VideoPlayer.vue
@@ -115,8 +115,8 @@ const { updateViewCount } = useContentStore();
const { setContextMenu } = useAppStore();
const { createRecord } = useRecord();
-const { userData } = storeToRefs(useAuthStore());
const { stateVideo, stateFolder, nextVideoURL, previousVideoURL } = storeToRefs(useContentStore());
+const { userData } = storeToRefs(useAuthStore());
// API Cache
const progressCache = ref<{ metadata_id: number; progress: number }[]>([]);
@@ -1196,6 +1196,7 @@ defineExpose({
isPictureInPicture,
audioPoster,
viewMode,
+ getCurrentTime: () => player.value?.currentTime ?? 0,
});
//#endregion
</script>
diff --git a/resources/js/views/VideoView.vue b/resources/js/views/VideoView.vue
index f29dfb4a..88935a39 100755
--- a/resources/js/views/VideoView.vue
+++ b/resources/js/views/VideoView.vue
@@ -4,7 +4,7 @@ import type { VideoResource } from '@/types/resources';
import type { ComputedRef } from 'vue';
import type { SortDir } from '@/service/sort/types';
-import { computed, nextTick, onMounted, ref, watch } from 'vue';
+import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from 'vue';
import { useContentStore } from '@/stores/ContentStore';
import { useModalStore } from '@/stores/ModalStore';
import { toParamNumber } from '@/util/route';
@@ -28,6 +28,8 @@ const { selectedSideBar, pageTitle } = storeToRefs(useAppStore());
const { getFolder, getCategory, playlistFind, playlistSort, updateVideoData } = useContentStore();
const { searchQuery, stateFilteredPlaylist, stateDirectory, stateVideo, stateFolder } = storeToRefs(useContentStore());
+const ambientPlayer = useTemplateRef('ambientPlayer');
+
const isLoading = ref(false);
const modal = useModalStore();
@@ -211,8 +213,8 @@ watch(() => stateVideo.value, setVideoAsDocumentTitle, { immediate: true });
<template v-slot:content>
<section id="content-video" class="flex flex-col gap-3">
<div id="video-container" class="flex flex-col gap-3">
- <VideoAmbientPlayer />
- <VideoInfoPanel />
+ <VideoAmbientPlayer ref="ambientPlayer" />
+ <VideoInfoPanel :getCurrentTime="ambientPlayer ? ambientPlayer.getCurrentTime : () => 0" />
</div>
<TableBase