From d7ace4d1dcd2479d78049aaf6a4bdbadf4072743 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 30 Jun 2024 15:31:27 -0500 Subject: [PATCH] Update:Media item share URL allows for sending starting time as query string #1768 --- client/pages/share/_slug.vue | 8 ++++++-- server/controllers/ShareController.js | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/client/pages/share/_slug.vue b/client/pages/share/_slug.vue index 4878481c..8fd715bd 100644 --- a/client/pages/share/_slug.vue +++ b/client/pages/share/_slug.vue @@ -21,8 +21,12 @@ import LocalAudioPlayer from '../../players/LocalAudioPlayer' export default { layout: 'blank', - async asyncData({ params, error, app }) { - const mediaItemShare = await app.$axios.$get(`/public/share/${params.slug}`).catch((error) => { + async asyncData({ params, error, app, query }) { + let endpoint = `/public/share/${params.slug}` + if (query.t && !isNaN(query.t)) { + endpoint += `?t=${query.t}` + } + const mediaItemShare = await app.$axios.$get(endpoint).catch((error) => { console.error('Failed', error) return null }) diff --git a/server/controllers/ShareController.js b/server/controllers/ShareController.js index 040a5a77..38b19479 100644 --- a/server/controllers/ShareController.js +++ b/server/controllers/ShareController.js @@ -23,6 +23,8 @@ class ShareController { */ async getMediaItemShareBySlug(req, res) { const { slug } = req.params + // Optional start time + let startTime = req.query.t && !isNaN(req.query.t) ? Math.max(0, parseInt(req.query.t)) : 0 const mediaItemShare = ShareManager.findBySlug(slug) if (!mediaItemShare) { @@ -68,8 +70,13 @@ class ShareController { return audioTrack }) + if (startTime > startOffset) { + Logger.warn(`[ShareController] Start time ${startTime} is greater than total duration ${startOffset}`) + startTime = 0 + } + const newPlaybackSession = new PlaybackSession() - newPlaybackSession.setData(oldLibraryItem, null, 'web-public', null, 0) + newPlaybackSession.setData(oldLibraryItem, null, 'web-public', null, startTime) newPlaybackSession.audioTracks = publicTracks newPlaybackSession.playMethod = PlayMethod.DIRECTPLAY newPlaybackSession.shareSessionId = uuidv4() // New share session id