]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/utils.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / utils.ts
index ce7a7fe6c966aab587867136129697d2f4ecbc17..2bb70d1fa1a99ba0118eac6647fa96f36b4ee84d 100644 (file)
@@ -1,4 +1,5 @@
 import { VideoFile } from '@shared/models'
+import { escapeHTML } from '@shared/core-utils/renderer'
 
 function toTitleCase (str: string) {
   return str.charAt(0).toUpperCase() + str.slice(1)
@@ -64,11 +65,11 @@ function buildVideoLink (options: {
 
   const url = baseUrl
     ? baseUrl
-    : window.location.origin + window.location.pathname.replace('/embed/', '/watch/')
+    : window.location.origin + window.location.pathname.replace('/embed/', '/w/')
 
   const params = generateParams(window.location.search)
 
-  if (options.startTime) {
+  if (options.startTime !== undefined && options.startTime !== null) {
     const startTimeInt = Math.floor(options.startTime)
     params.set('start', secondsToTime(startTimeInt))
   }
@@ -94,13 +95,13 @@ function buildVideoLink (options: {
 function buildPlaylistLink (options: {
   baseUrl?: string
 
-  playlistPosition: number
+  playlistPosition?: number
 }) {
   const { baseUrl } = options
 
   const url = baseUrl
     ? baseUrl
-    : window.location.origin + window.location.pathname.replace('/video-playlists/embed/', '/videos/watch/playlist/')
+    : window.location.origin + window.location.pathname.replace('/video-playlists/embed/', '/w/p/')
 
   const params = generateParams(window.location.search)
 
@@ -146,6 +147,8 @@ function timeToInt (time: number | string) {
 function secondsToTime (seconds: number, full = false, symbol?: string) {
   let time = ''
 
+  if (seconds === 0 && !full) return '0s'
+
   const hourSymbol = (symbol || 'h')
   const minuteSymbol = (symbol || 'm')
   const secondsSymbol = full ? '' : 's'
@@ -168,26 +171,16 @@ function secondsToTime (seconds: number, full = false, symbol?: string) {
   return time
 }
 
-function buildVideoOrPlaylistEmbed (embedUrl: string) {
+function buildVideoOrPlaylistEmbed (embedUrl: string, embedTitle: string) {
+  const title = escapeHTML(embedTitle)
   return '<iframe width="560" height="315" ' +
     'sandbox="allow-same-origin allow-scripts allow-popups" ' +
+    'title="' + title + '" ' +
     'src="' + embedUrl + '" ' +
     'frameborder="0" allowfullscreen>' +
     '</iframe>'
 }
 
-function copyToClipboard (text: string) {
-  const el = document.createElement('textarea')
-  el.value = text
-  el.setAttribute('readonly', '')
-  el.style.position = 'absolute'
-  el.style.left = '-9999px'
-  document.body.appendChild(el)
-  el.select()
-  document.execCommand('copy')
-  document.body.removeChild(el)
-}
-
 function videoFileMaxByResolution (files: VideoFile[]) {
   let max = files[0]
 
@@ -236,7 +229,6 @@ export {
   buildVideoOrPlaylistEmbed,
   videoFileMaxByResolution,
   videoFileMinByResolution,
-  copyToClipboard,
   isMobile,
   bytes,
   isIOS,