Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Added "last" and a reversed ?playlistPosition in playlist URL (#3974)

Florian CUNYe771e82dfac5
diff --git a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts
index a70167da51..0a4d6bfd11 100644
--- a/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch-playlist.component.ts
@@ -118,6 +118,9 @@ export class VideoWatchPlaylistComponent {
updatePlaylistIndex (position: number) {
if (this.playlistElements.length === 0 || !position) return
+ // Handle the reverse index
+ if (position < 0) position = this.playlist.videosLength + position + 1
+
for (const playlistElement of this.playlistElements) {
// >= if the previous videos were not valid
if (playlistElement.video && playlistElement.position >= position) {
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index 5530dc8ada..1078268242 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -188,7 +188,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
})
this.queryParamsSub = this.route.queryParams.subscribe(queryParams => {
- this.playlistPosition = queryParams[ 'playlistPosition' ]
+ // Handle the ?playlistPosition
+ const positionParam = queryParams[ 'playlistPosition' ]
+
+ this.playlistPosition = positionParam === 'last'
+ ? -1 // Handle the "last" index
+ : parseInt(positionParam, 10)
+
+ if (isNaN(this.playlistPosition)) {
+ console.error(`playlistPosition query param '${positionParam}' was parsed as NaN, defaulting to 1.`)
+ this.playlistPosition = 1
+ }
+
this.videoWatchPlaylist.updatePlaylistIndex(this.playlistPosition)
const start = queryParams[ 'start' ]