filesafe/dist/js/player.js

3 lines
3.2 KiB
JavaScript

var lsKeys={},page={urlPrefix:null,urlIdentifier:null,urlInput:document.querySelector("#identifier"),reloadBtn:document.querySelector("#reloadBtn"),downloadBtn:document.querySelector("#downloadBtn"),uploadRoot:null,titleFormat:null,videoContainer:document.querySelector("#player-container"),player:null};window.HELP_IMPROVE_VIDEOJS=!1,page.onAxiosError=function(e){var t={520:"Unknown Error",521:"Web Server Is Down",522:"Connection Timed Out",523:"Origin Is Unreachable",524:"A Timeout Occurred",525:"SSL Handshake Failed",526:"Invalid SSL Certificate",527:"Railgun Error",530:"Origin DNS Error"}[e.response.status]||e.response.statusText,a=e.response.data&&e.response.data.description?e.response.data.description:"";return swal(e.response.status+" "+t,a,"error")},page.toggleReloadBtn=function(e){e?(page.reloadBtn.classList.remove("is-loading"),page.reloadBtn.removeAttribute("disabled")):(page.reloadBtn.classList.add("is-loading"),page.reloadBtn.setAttribute("disabled",!0))},page.reloadVideo=function(){if(page.urlInput.value){page.toggleReloadBtn(!1);var e=page.uploadRoot+"/"+page.urlInput.value+"?_="+Math.round(Date.now()/1e3);axios.head(e).then((function(t){if(200!==t.status&&304!==t.status)return page.toggleReloadBtn(!0),page.onAxiosError(t);if(!t.headers["content-type"].startsWith("video/"))return page.toggleReloadBtn(!0),swal("An error occurred!","The requested upload does not appear to be a video file.","error");page.player&&(page.player.dispose(),page.videoContainer.innerHTML="");var a=document.createElement("video-js");a.id="video-js",a.className="video-js vjs-default-skin vjs-fluid vjs-big-play-centered",a.setAttribute("controls",!0),a.setAttribute("preload","auto");var o=document.createElement("source");o.src=e,o.type=t.headers["content-type"],a.appendChild(o),page.videoContainer.appendChild(a),page.player=videojs("video-js",{language:"en",playbackRates:[.25,.5,.75,1,1.25,1.5,1.75,2],responsive:!0}),page.player.seekButtons({forward:10,back:10}),page.titleFormat&&(document.title=page.titleFormat.replace(/%identifier%/g,page.urlInput.value)),page.downloadBtn&&page.downloadBtn.setAttribute("href",e),window.history.pushState(null,null,page.urlPrefix+page.urlInput.value),page.toggleReloadBtn(!0)})).catch((function(e){page.toggleReloadBtn(!0),page.onAxiosError(e)}))}},window.addEventListener("DOMContentLoaded",(function(){var e=document.querySelector("#mainScript");if(e&&void 0!==e.dataset.uploadRoot){page.uploadRoot=e.dataset.uploadRoot,page.titleFormat=e.dataset.titleFormat;var t=window.location.protocol+"//"+window.location.host,a=window.location.pathname.match(/.*\/(.*)$/);if(!a||!a[1])return swal("An error occurred!","Failed to parse upload identifier from URL.","error");if(page.urlIdentifier=a[1],t+=window.location.pathname.substring(0,window.location.pathname.indexOf(a[1])),page.urlPrefix=t,page.urlInput){page.urlInput.value=page.urlIdentifier;var o=document.querySelector("#inputForm");o.addEventListener("submit",(function(e){e.preventDefault()})),page.videoContainer&&(page.reloadBtn=document.querySelector("#reloadBtn"),page.reloadBtn&&page.reloadBtn.addEventListener("click",(function(e){o.checkValidity()&&page.reloadVideo()})),page.reloadVideo())}}}));
//# sourceMappingURL=player.js.map