{"version":3,"sources":["player.js"],"names":["const","lsKeys","page","urlPrefix","urlIdentifier","urlInput","document","querySelector","reloadBtn","downloadBtn","uploadRoot","titleFormat","videoContainer","player","cloudflareErrors","window","HELP_IMPROVE_VIDEOJS","onError","error","console","content","createElement","innerHTML","toString","swal","title","icon","onAxiosError","response","statusText","status","description","data","toggleReloadBtn","enabled","classList","remove","removeAttribute","add","setAttribute","reloadVideo","value","src","axios","head","then","includes","type","headers","isvideo","startsWith","isaudio","dispose","videoElement","id","className","appendChild","options","language","playbackRates","responsive","plugins","wavesurfer","videojs","let","message","getPluginVersion","WaveSurfer","log","seekButtons","forward","back","videoJSButton","getComponent","loopButtonText","loop","loopButton","extend","constructor","apply","this","arguments","addClass","controlText","handleClick","toggleClass","registerComponent","getChild","addChild","replace","history","pushState","catch","addEventListener","mainScript","dataset","location","protocol","host","match","pathname","substring","indexOf","form","event","preventDefault","checkValidity"],"mappings":"AAGAA,IAAMC,OAAS,CAAA,EAETC,KAAO,CACXC,UAAW,KACXC,cAAe,KAEfC,SAAUC,SAASC,cAAc,eACjCC,UAAWF,SAASC,cAAc,cAClCE,YAAaH,SAASC,cAAc,gBACpCG,WAAY,KACZC,YAAa,KAEbC,eAAgBN,SAASC,cAAc,oBACvCM,OAAQ,KAGRC,iBAAkB,CAChB,IAAK,gBACL,IAAK,qBACL,IAAK,uBACL,IAAK,wBACL,IAAK,qBACL,IAAK,uBACL,IAAK,0BACL,IAAK,gBACL,IAAK,qBAKTC,OAAOC,sBAAuB,EAG9Bd,KAAKe,QAAO,SAAGC,GACbC,QAAQD,MAAMA,GAEdlB,IAAMoB,EAAUd,SAASe,cAAc,OAKvC,OAJAD,EAAQE,UAAY,kBACPJ,EAAMK,WAAU,8EAGtBC,KAAK,CACVC,MAAO,qBACPC,KAAM,QAFNN,QAGAA,GADJ,EAMAlB,KAAKyB,aAAY,SAAGT,GAClB,IAAKA,EAAMU,SACT,OAAO1B,KAAKe,QAAQC,GAGtBlB,IAAM6B,EAAa3B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8F,EAAaxF,SAASC,cAAc,eAC1C,GAAKuF,QAAuD,IAAlCA,EAAWC,QAAQrF,WAA7C,CAEAR,KAAKQ,WAAaoF,EAAWC,QAAQrF,WACrCR,KAAKS,YAAcmF,EAAWC,QAAQpF,YAEtCqD,IAAI7D,EAAYY,OAAOiF,SAASC,SAAW,KAAOlF,OAAOiF,SAASE,KAC5DC,EAAQpF,OAAOiF,SAASI,SAASD,MAAM,aAC7C,IAAKA,IAAUA,EAAM,GACnB,OAAO3E,KAAK,qBAAsB,8CAA+C,SAOnF,GAJAtB,KAAKE,cAAgB+F,EAAM,GAC3BhG,GAAaY,OAAOiF,SAASI,SAASC,UAAU,EAAGtF,OAAOiF,SAASI,SAASE,QAAQH,EAAM,KAC1FjG,KAAKC,UAAYA,EAEZD,KAAKG,SAAV,CACAH,KAAKG,SAASoC,MAAQvC,KAAKE,cAG3BJ,IAAMuG,EAAOjG,SAASC,cAAc,cACpCgG,EAAKV,iBAAiB,UAAQ,SAAEW,GAC9BA,EAAMC,gBAFR,IAKKvG,KAAKU,iBAEVV,KAAKM,UAAYF,SAASC,cAAc,cACpCL,KAAKM,WACPN,KAAKM,UAAUqF,iBAAiB,SAAO,SAAEW,GAClCD,EAAKG,iBACVxG,KAAKsC,aAFP,IAMFtC,KAAKsC,cAnBe,CAfqD,CAgC3E","file":"player.js","sourcesContent":["/* global swal, axios, videojs, WaveSurfer */\n\n// eslint-disable-next-line no-unused-vars\nconst lsKeys = {}\n\nconst page = {\n  urlPrefix: null,\n  urlIdentifier: null,\n\n  urlInput: document.querySelector('#identifier'),\n  reloadBtn: document.querySelector('#reloadBtn'),\n  downloadBtn: document.querySelector('#downloadBtn'),\n  uploadRoot: null,\n  titleFormat: null,\n\n  videoContainer: document.querySelector('#playerContainer'),\n  player: null,\n\n  // Better Cloudflare errors\n  cloudflareErrors: {\n    520: 'Unknown Error',\n    521: 'Web Server Is Down',\n    522: 'Connection Timed Out',\n    523: 'Origin Is Unreachable',\n    524: 'A Timeout Occurred',\n    525: 'SSL Handshake Failed',\n    526: 'Invalid SSL Certificate',\n    527: 'Railgun Error',\n    530: 'Origin DNS Error'\n  }\n}\n\n// Disable video.js telemetry (should already be disabled by default since v7 though)\nwindow.HELP_IMPROVE_VIDEOJS = false\n\n// Handler for regular JS errors\npage.onError = error => {\n  console.error(error)\n\n  const content = document.createElement('div')\n  content.innerHTML = `\n    <p><code>${error.toString()}</code></p>\n    <p>Please check your console for more information.</p>\n  `\n  return swal({\n    title: 'An error occurred!',\n    icon: 'error',\n    content\n  })\n}\n\n// Handler for Axios errors\npage.onAxiosError = error => {\n  if (!error.response) {\n    return page.onError(error)\n  }\n\n  const statusText = page.cloudflareErrors[error.response.status] || error.response.statusText\n\n  const description = error.response.data && error.response.data.description\n    ? error.response.data.description\n    : ''\n  return swal(`${error.response.status} ${statusText}`, description, 'error')\n}\n\npage.toggleReloadBtn = enabled => {\n  if (enabled) {\n    page.reloadBtn.classList.remove('is-loading')\n    page.reloadBtn.removeAttribute('disabled')\n  } else {\n    page.reloadBtn.classList.add('is-loading')\n    page.reloadBtn.setAttribute('disabled', 'disabled')\n  }\n}\n\npage.reloadVideo = () => {\n  if (!page.urlInput.value) return\n\n  page.toggleReloadBtn(false)\n  const src = `${page.uploadRoot}/${page.urlInput.value}`\n\n  axios.head(src).then(response => {\n    if (![200, 304].includes(response.status)) {\n      page.toggleReloadBtn(true)\n      return page.onAxiosError(response)\n    }\n\n    const type = response.headers['content-type'] || ''\n    const isvideo = type.startsWith('video/')\n    const isaudio = type.startsWith('audio/')\n    if (!isvideo && !isaudio) {\n      page.toggleReloadBtn(true)\n      return swal('An error occurred!', 'The requested upload does not appear to be a media file.', 'error')\n    }\n\n    page.urlIdentifier = page.urlInput.value\n\n    if (page.player) {\n      page.player.dispose()\n      page.videoContainer.innerHTML = ''\n    }\n\n    const videoElement = document.createElement('video-js')\n    videoElement.id = 'video-js'\n    videoElement.className = 'video-js vjs-default-skin vjs-fluid vjs-big-play-centered'\n    videoElement.setAttribute('controls', true)\n    videoElement.setAttribute('preload', 'auto')\n\n    page.videoContainer.appendChild(videoElement)\n\n    const options = {\n      language: 'en',\n      playbackRates: [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2],\n      responsive: true,\n      plugins: {}\n    }\n\n    if (isaudio) {\n      options.plugins.wavesurfer = {\n        responsive: true\n      }\n    }\n\n    page.player = videojs('video-js', options, () => {\n      let message = `Using video.js ${videojs.VERSION}`\n      if (isaudio) {\n        message += ` with videojs-wavesurfer ${videojs.getPluginVersion('wavesurfer')} and wavesurfer.js ${WaveSurfer.VERSION}`\n      }\n      videojs.log(message)\n      page.player.src({ src, type })\n    })\n    page.player.seekButtons({ forward: 10, back: 10 })\n\n    const videoJSButton = videojs.getComponent('Button')\n    const loopButtonText = () => page.player.loop()\n      ? 'Disable loop'\n      : 'Enable loop'\n    const loopButton = videojs.extend(videoJSButton, {\n      constructor () {\n        videoJSButton.apply(this, arguments)\n        this.addClass('vjs-loop-button')\n        this.controlText(loopButtonText())\n      },\n      handleClick () {\n        page.player.loop(!page.player.loop())\n        this.toggleClass('vjs-loop-enabled', page.player.loop())\n        this.controlText(loopButtonText())\n      }\n    })\n    videojs.registerComponent('loopButton', loopButton)\n    page.player.getChild('controlBar').addChild('loopButton')\n\n    if (page.titleFormat) {\n      document.title = page.titleFormat.replace(/%identifier%/g, page.urlIdentifier)\n    }\n\n    if (page.downloadBtn) {\n      page.downloadBtn.setAttribute('href', src)\n    }\n\n    window.history.pushState(null, null, page.urlPrefix + page.urlIdentifier)\n    page.toggleReloadBtn(true)\n  }).catch(error => {\n    page.toggleReloadBtn(true)\n    if (typeof error.response !== 'undefined') page.onAxiosError(error)\n    else page.onError(error)\n  })\n}\n\nwindow.addEventListener('DOMContentLoaded', () => {\n  const mainScript = document.querySelector('#mainScript')\n  if (!mainScript || typeof mainScript.dataset.uploadRoot === 'undefined') return\n\n  page.uploadRoot = mainScript.dataset.uploadRoot\n  page.titleFormat = mainScript.dataset.titleFormat\n\n  let urlPrefix = window.location.protocol + '//' + window.location.host\n  const match = window.location.pathname.match(/.*\\/(.*)$/)\n  if (!match || !match[1]) {\n    return swal('An error occurred!', 'Failed to parse upload identifier from URL.', 'error')\n  }\n\n  page.urlIdentifier = match[1]\n  urlPrefix += window.location.pathname.substring(0, window.location.pathname.indexOf(match[1]))\n  page.urlPrefix = urlPrefix\n\n  if (!page.urlInput) return\n  page.urlInput.value = page.urlIdentifier\n\n  // Prevent default form's submit actio\n  const form = document.querySelector('#inputForm')\n  form.addEventListener('submit', event => {\n    event.preventDefault()\n  })\n\n  if (!page.videoContainer) return\n\n  page.reloadBtn = document.querySelector('#reloadBtn')\n  if (page.reloadBtn) {\n    page.reloadBtn.addEventListener('click', event => {\n      if (!form.checkValidity()) return\n      page.reloadVideo()\n    })\n  }\n\n  page.reloadVideo()\n})\n"]}