Handle playlist position in URL

pull/3047/head
Chocobozzz 2020-08-05 14:00:36 +02:00 committed by Chocobozzz
parent fb13852d30
commit 2a71d286ce
1 changed files with 25 additions and 2 deletions

View File

@ -179,6 +179,8 @@ export class PeerTubeEmbed {
const errorText = document.getElementById('error-content') const errorText = document.getElementById('error-content')
errorText.innerHTML = translatedText errorText.innerHTML = translatedText
this.wrapperElement.style.display = 'none'
} }
videoNotFound (translations?: Translations) { videoNotFound (translations?: Translations) {
@ -561,7 +563,28 @@ export class PeerTubeEmbed {
const playlistElementResult = await res.videosResponse.json() const playlistElementResult = await res.videosResponse.json()
this.playlistElements = await this.loadAllPlaylistVideos(playlistId, playlistElementResult) this.playlistElements = await this.loadAllPlaylistVideos(playlistId, playlistElementResult)
this.currentPlaylistElement = this.playlistElements[0] const params = new URL(window.location.toString()).searchParams
const playlistPositionParam = this.getParamString(params, 'playlistPosition')
let position = 1
if (playlistPositionParam) {
position = parseInt(playlistPositionParam + '', 10)
}
this.currentPlaylistElement = this.playlistElements.find(e => e.position === position)
if (!this.currentPlaylistElement || !this.currentPlaylistElement.video) {
console.error('Current playlist element is not valid.', this.currentPlaylistElement)
this.currentPlaylistElement = this.getNextPlaylistElement()
}
if (!this.currentPlaylistElement) {
console.error('This playlist does not have any valid element.')
const serverTranslations = await this.translationsPromise
this.playlistFetchError(serverTranslations)
return
}
videoId = this.currentPlaylistElement.video.uuid videoId = this.currentPlaylistElement.video.uuid
} else { } else {
videoId = this.getResourceId() videoId = this.getResourceId()