Skip to content

Commit

Permalink
Update:Media item share URL allows for sending starting time as query…
Browse files Browse the repository at this point in the history
… string #1768
  • Loading branch information
advplyr committed Jun 30, 2024
1 parent c309856 commit d7ace4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions client/pages/share/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
9 changes: 8 additions & 1 deletion server/controllers/ShareController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d7ace4d

Please sign in to comment.