diff --git a/app/rice-box.go b/app/rice-box.go index 4235101..29e5485 100644 --- a/app/rice-box.go +++ b/app/rice-box.go @@ -37,7 +37,7 @@ func init() { // define dirs dir1 := &embedded.EmbeddedDir{ Filename: "", - DirModTime: time.Unix(1585462766, 0), + DirModTime: time.Unix(1585653575, 0), ChildFiles: []*embedded.EmbeddedFile{ file2, // "base.html" file3, // "import.html" @@ -53,7 +53,7 @@ func init() { // register embeddedBox embedded.RegisterEmbeddedBox(`../templates`, &embedded.EmbeddedBox{ Name: `../templates`, - Time: time.Unix(1585462766, 0), + Time: time.Unix(1585653575, 0), Dirs: map[string]*embedded.EmbeddedDir{ "": dir1, }, @@ -95,9 +95,9 @@ func init() { } fileb := &embedded.EmbeddedFile{ Filename: "import.js", - FileModTime: time.Unix(1585463456, 0), + FileModTime: time.Unix(1585651354, 0), - Content: string("// common variables\nlet iBytesImported = 0\nlet iBytesTotal = 0\nlet iPreviousBytesLoaded = 0\nlet iMaxFilesize = 104857600 // 100MB\nlet timer = 0\nlet importInProgress = 'n/a'\nlet isProcessing = false\nlet url = null\n\n/* CACHED ELEMENTS */\n\nconst importForm = document.getElementById('import-form')\nconst importInput = document.getElementById('import-input')\nconst importMessageLabel = document.getElementById('import-message')\nconst importButtonWrapper = document.getElementById('import-button-wrapper')\nconst importButton = document.getElementById('import-button')\nconst importProgressContainer = document.getElementById('import-progress-container')\nconst importProgressBar = document.getElementById('import-progress')\nconst importProgressLabel = document.getElementById('import-progress-label')\nconst importStopped = document.getElementById('import-stopped')\nconst importStarted = document.getElementById('import-started')\n\n/* HELPERS */\n\nconst setProgress = (_progress) => {\n importProgressContainer.style.display = _progress > 0 ? 'flex' : 'none'\n importProgressBar.style.width = `${_progress}%`\n importProgressLabel.innerText = _progress >= 15 ? `${_progress}%` : ''\n}\n\nconst setMessage = (_message, isError) => {\n importMessageLabel.style.display = _message ? 'block' : 'none'\n importMessageLabel.innerHTML = _message\n if (isError) {\n importMessageLabel.classList.add('error')\n } else {\n importMessageLabel.classList.remove('error')\n }\n}\n\nconst setImportState = (_importInProgress) => {\n importInProgress = _importInProgress\n\n importStarted.style.display = _importInProgress ? 'inline-block' : 'none'\n importStopped.style.display = _importInProgress ? 'none' : 'block'\n\n if (_importInProgress) {\n importButton.classList.add('transparent')\n timer = setInterval(doInnerUpdates, 300)\n } else {\n importButton.classList.remove('transparent')\n clearInterval(timer)\n }\n}\n\nconst secondsToTime = (secs) => {\n let hr = Math.floor(secs / 3600)\n let min = Math.floor((secs - (hr * 3600)) / 60)\n let sec = Math.floor(secs - (hr * 3600) - (min * 60))\n if (hr < 10) hr = `0${hr}`\n if (min < 10) min = `0${min}`\n if (sec < 10) sec = `0${sec}`\n if (hr) hr = '00'\n return `${hr}:${min}:${sec}`\n}\n\nconst bytesToSize = (bytes) => {\n const sizes = ['Bytes', 'KB', 'MB']\n if (bytes == 0) return 'n/a'\n const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))\n return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]\n}\n\n/* MAIN */\n\ndocument.addEventListener('DOMContentLoaded', () => {\n importInput.addEventListener(\"keyup\", (e) => {\n if (e.keyCode === 13) {\n e.preventDefault();\n importButton.click();\n }\n });\n}, false)\n\nconst labelClicked = (e) => {\n if (importInProgress === true) {\n e.preventDefault()\n return false\n }\n}\n\nconst urlSelected = (_url) => {\n url = _url || importInput.value\n\n setMessage('')\n setProgress(0)\n \n importButtonWrapper.style.display = 'block'\n setImportState(false)\n}\n\nconst startImporting = () => {\n if (importInProgress === true) return\n if (!url) return\n\n isProcessing = false\n iPreviousBytesLoaded = 0\n setMessage('')\n setProgress(0)\n setImportState(true)\n\n const formData = new FormData()\n formData.append('url', url)\n const xhr = new XMLHttpRequest()\n\n xhr.upload.addEventListener('progress', importProgress, false)\n xhr.addEventListener('load', importFinish, false)\n xhr.addEventListener('error', importError, false)\n xhr.addEventListener('abort', importAbort, false)\n\n xhr.open('POST', '/import')\n xhr.send(formData)\n\n timer = setInterval(doInnerUpdates, 300)\n}\n\nconst doInnerUpdates = () => { // we will use this function to display import speed\n if (isProcessing) {\n clearInterval(timer)\n return\n }\n\n let iDiff = iBytesImported - iPreviousBytesLoaded\n // if nothing new loaded - exit\n if (iDiff == 0)\n return\n iPreviousBytesLoaded = iBytesImported\n iDiff = iDiff * 2\n const iBytesRem = iBytesTotal - iPreviousBytesLoaded\n const secondsRemaining = iBytesRem / iDiff\n // update speed info\n let iSpeed = iDiff.toString() + 'B/s'\n if (iDiff > 1024 * 1024) {\n iSpeed = (Math.round(iDiff * 100/(1024*1024))/100).toString() + 'MB/s'\n } else if (iDiff > 1024) {\n iSpeed = (Math.round(iDiff * 100/1024)/100).toString() + 'KB/s'\n }\n\n const speedMessage = `${iSpeed} | ${secondsToTime(secondsRemaining)}`\n setMessage(speedMessage)\n}\n\nfunction importProgress(e) { // import process in progress\n if (e.lengthComputable) {\n iBytesImported = e.loaded\n iBytesTotal = e.total\n\n const iPercentComplete = Math.round(iBytesImported / iBytesTotal * 100)\n setProgress(iPercentComplete)\n if (iPercentComplete === 100) {\n isProcessing = true\n setMessage('Processing video... please wait')\n }\n } else {\n setMessage('Unable to compute progress.')\n }\n}\n\nconst importFinish = (e) => { // import successfully finished\n const message = e.target.responseText\n const isSuccess = e.target.status < 400\n\n setProgress(isSuccess ? 100 : 0)\n setMessage(message, !isSuccess)\n setImportState(false)\n if (isSuccess) removeFile(null, true)\n}\n\nconst importError = () => { // import error\n setMessage('An error occurred while importing the url.', true)\n setProgress(0)\n setImportState(false)\n}\n\nconst importAbort = () => { // import abort\n setMessage('The import has been canceled by the user or the browser dropped the connection.', true)\n setProgress(0)\n setImportState(false)\n}\n"), + Content: string("// common variables\nlet iBytesImported = 0\nlet iBytesTotal = 0\nlet iPreviousBytesLoaded = 0\nlet iMaxFilesize = 104857600 // 100MB\nlet timer = 0\nlet importInProgress = 'n/a'\nlet isProcessing = false\nlet url = null\n\n/* CACHED ELEMENTS */\n\nconst importForm = document.getElementById('import-form')\nconst importInput = document.getElementById('import-input')\nconst importMessageLabel = document.getElementById('import-message')\nconst importButtonWrapper = document.getElementById('import-button-wrapper')\nconst importButton = document.getElementById('import-button')\nconst importProgressContainer = document.getElementById('import-progress-container')\nconst importProgressBar = document.getElementById('import-progress')\nconst importProgressLabel = document.getElementById('import-progress-label')\nconst importStopped = document.getElementById('import-stopped')\nconst importStarted = document.getElementById('import-started')\n\n/* HELPERS */\n\nconst setProgress = (_progress) => {\n importProgressContainer.style.display = _progress > 0 ? 'flex' : 'none'\n importProgressBar.style.width = `${_progress}%`\n importProgressLabel.innerText = _progress >= 15 ? `${_progress}%` : ''\n}\n\nconst setMessage = (_message, isError) => {\n importMessageLabel.style.display = _message ? 'block' : 'none'\n importMessageLabel.innerHTML = _message\n if (isError) {\n importMessageLabel.classList.add('error')\n } else {\n importMessageLabel.classList.remove('error')\n }\n}\n\nconst setImportState = (_importInProgress) => {\n importInProgress = _importInProgress\n\n importStarted.style.display = _importInProgress ? 'inline-block' : 'none'\n importStopped.style.display = _importInProgress ? 'none' : 'block'\n\n if (_importInProgress) {\n importButton.classList.add('transparent')\n timer = setInterval(doInnerUpdates, 300)\n } else {\n importButton.classList.remove('transparent')\n clearInterval(timer)\n }\n}\n\nconst secondsToTime = (secs) => {\n let hr = Math.floor(secs / 3600)\n let min = Math.floor((secs - (hr * 3600)) / 60)\n let sec = Math.floor(secs - (hr * 3600) - (min * 60))\n if (hr < 10) hr = `0${hr}`\n if (min < 10) min = `0${min}`\n if (sec < 10) sec = `0${sec}`\n if (hr) hr = '00'\n return `${hr}:${min}:${sec}`\n}\n\nconst bytesToSize = (bytes) => {\n const sizes = ['Bytes', 'KB', 'MB']\n if (bytes == 0) return 'n/a'\n const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))\n return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]\n}\n\n/* MAIN */\n\ndocument.addEventListener('DOMContentLoaded', () => {\n importInput.addEventListener(\"keypress\", (e) => {\n if (e.keyCode == 9) {\n urlSelected();\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n\n if (e.keyCode === 13 || e.keyCode == 10) {\n e.preventDefault();\n e.stopPropagation();\n urlSelected();\n importButton.click();\n return;\n }\n });\n}, false)\n\nconst labelClicked = (e) => {\n if (importInProgress === true) {\n e.preventDefault()\n return false\n }\n}\n\nconst urlSelected = (_url) => {\n url = _url || importInput.value\n\n setMessage('')\n setProgress(0)\n \n importButtonWrapper.style.display = 'block'\n setImportState(false)\n}\n\nconst startImporting = () => {\n if (importInProgress === true) return\n if (!url) return\n\n isProcessing = false\n iPreviousBytesLoaded = 0\n setMessage('')\n setProgress(0)\n setImportState(true)\n\n const formData = new FormData()\n formData.append('url', url)\n const xhr = new XMLHttpRequest()\n\n xhr.upload.addEventListener('progress', importProgress, false)\n xhr.addEventListener('load', importFinish, false)\n xhr.addEventListener('error', importError, false)\n xhr.addEventListener('abort', importAbort, false)\n\n xhr.open('POST', '/import')\n xhr.send(formData)\n\n timer = setInterval(doInnerUpdates, 300)\n}\n\nconst doInnerUpdates = () => { // we will use this function to display import speed\n if (isProcessing) {\n clearInterval(timer)\n return\n }\n\n let iDiff = iBytesImported - iPreviousBytesLoaded\n // if nothing new loaded - exit\n if (iDiff == 0)\n return\n iPreviousBytesLoaded = iBytesImported\n iDiff = iDiff * 2\n const iBytesRem = iBytesTotal - iPreviousBytesLoaded\n const secondsRemaining = iBytesRem / iDiff\n // update speed info\n let iSpeed = iDiff.toString() + 'B/s'\n if (iDiff > 1024 * 1024) {\n iSpeed = (Math.round(iDiff * 100/(1024*1024))/100).toString() + 'MB/s'\n } else if (iDiff > 1024) {\n iSpeed = (Math.round(iDiff * 100/1024)/100).toString() + 'KB/s'\n }\n\n const speedMessage = `${iSpeed} | ${secondsToTime(secondsRemaining)}`\n setMessage(speedMessage)\n}\n\nfunction importProgress(e) { // import process in progress\n if (e.lengthComputable) {\n iBytesImported = e.loaded\n iBytesTotal = e.total\n\n const iPercentComplete = Math.round(iBytesImported / iBytesTotal * 100)\n setProgress(iPercentComplete)\n if (iPercentComplete === 100) {\n isProcessing = true\n setMessage('Processing video... please wait')\n }\n } else {\n setMessage('Unable to compute progress.')\n }\n}\n\nconst importFinish = (e) => { // import successfully finished\n const message = e.target.responseText\n const isSuccess = e.target.status < 400\n\n setProgress(isSuccess ? 100 : 0)\n setMessage(message, !isSuccess)\n setImportState(false)\n if (isSuccess) removeFile(null, true)\n}\n\nconst importError = () => { // import error\n setMessage('An error occurred while importing the url.', true)\n setProgress(0)\n setImportState(false)\n}\n\nconst importAbort = () => { // import abort\n setMessage('The import has been canceled by the user or the browser dropped the connection.', true)\n setProgress(0)\n setImportState(false)\n}\n"), } filec := &embedded.EmbeddedFile{ Filename: "theme.css", @@ -119,15 +119,15 @@ func init() { } filef := &embedded.EmbeddedFile{ Filename: "upload.js", - FileModTime: time.Unix(1585341743, 0), + FileModTime: time.Unix(1585653781, 0), - Content: string("// common variables\nlet iBytesUploaded = 0\nlet iBytesTotal = 0\nlet iPreviousBytesLoaded = 0\nlet iMaxFilesize = 104857600 // 100MB\nlet timer = 0\nlet uploadInProgress = 'n/a'\nlet isProcessing = false\nlet file = null\n\n/* CACHED ELEMENTS */\n\nconst uploadForm = document.getElementById('upload-form')\nconst videoInput = document.getElementById('video-input')\nconst videoTitle = document.getElementById('video-title')\nconst videoDescription = document.getElementById('video-description')\nconst uploadMessageLabel = document.getElementById('upload-message')\nconst uploadFileContainer = document.getElementById('upload-file')\nconst uploadFilenameLabel = document.getElementById('upload-filename')\nconst uploadButtonWrapper = document.getElementById('upload-button-wrapper')\nconst uploadButton = document.getElementById('upload-button')\nconst uploadProgressContainer = document.getElementById('upload-progress-container')\nconst uploadProgressBar = document.getElementById('upload-progress')\nconst uploadProgressLabel = document.getElementById('upload-progress-label')\nconst uploadStopped = document.getElementById('upload-stopped')\nconst uploadStarted = document.getElementById('upload-started')\n\n/* HELPERS */\n\nconst setProgress = (_progress) => {\n uploadProgressContainer.style.display = _progress > 0 ? 'flex' : 'none'\n uploadProgressBar.style.width = `${_progress}%`\n uploadProgressLabel.innerText = _progress >= 15 ? `${_progress}%` : ''\n}\n\nconst setMessage = (_message, isError) => {\n uploadMessageLabel.style.display = _message ? 'block' : 'none'\n uploadMessageLabel.innerHTML = _message\n if (isError) {\n uploadMessageLabel.classList.add('error')\n } else {\n uploadMessageLabel.classList.remove('error')\n }\n}\n\nconst setUploadState = (_uploadInProgress) => {\n uploadInProgress = _uploadInProgress\n\n uploadStarted.style.display = _uploadInProgress ? 'inline-block' : 'none'\n uploadStopped.style.display = _uploadInProgress ? 'none' : 'block'\n\n if (_uploadInProgress) {\n uploadButton.classList.add('transparent')\n timer = setInterval(doInnerUpdates, 300)\n } else {\n uploadButton.classList.remove('transparent')\n clearInterval(timer)\n }\n}\n\nconst secondsToTime = (secs) => {\n let hr = Math.floor(secs / 3600)\n let min = Math.floor((secs - (hr * 3600)) / 60)\n let sec = Math.floor(secs - (hr * 3600) - (min * 60))\n if (hr < 10) hr = `0${hr}`\n if (min < 10) min = `0${min}`\n if (sec < 10) sec = `0${sec}`\n if (hr) hr = '00'\n return `${hr}:${min}:${sec}`\n}\n\nconst bytesToSize = (bytes) => {\n const sizes = ['Bytes', 'KB', 'MB']\n if (bytes == 0) return 'n/a'\n const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))\n return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]\n}\n\nconst determineDragAndDropCapable = () => {\n const div = document.createElement('div')\n return (('draggable' in div)\n || ('ondragstart' in div && 'ondrop' in div))\n && 'FormData' in window\n && 'FileReader' in window\n}\n\n/* MAIN */\n\ndocument.addEventListener('DOMContentLoaded', () => {\n ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave']\n .forEach((evt) => {\n uploadForm.addEventListener(evt, (e) => {\n e.preventDefault()\n e.stopPropagation()\n })\n })\n\n uploadForm.addEventListener('drop', (e) => {\n console.log(111)\n e.preventDefault()\n e.stopPropagation()\n\n const _file = e.dataTransfer.files[0]\n if (!_file) return false\n fileSelected(_file)\n\n return false\n })\n}, false)\n\nconst labelClicked = (e) => {\n if (uploadInProgress === true || file != null) {\n e.preventDefault()\n return false\n }\n}\n\nconst fileSelected = (_file) => {\n const fileObj = _file || videoInput.files[0]\n if (_file) videoInput.value = ''\n\n if (fileObj) file = fileObj\n if (!file) return\n\n if (file.size > iMaxFilesize) {\n setMessage('Your file is very big. We can\\'t accept it. Please select more small file.', true)\n return\n }\n\n setMessage('')\n setProgress(0)\n \n const filename = file.name.length <= 20 ? file.name : `${file.name.substring(0, 14)}...${file.name.substring(file.name.length - 3)}`\n uploadFilenameLabel.innerText = filename\n uploadFileContainer.style.display = 'flex'\n \n uploadButtonWrapper.style.display = 'block'\n setUploadState(false)\n}\n\nconst removeFile = (e, keepMessage) => {\n if (e) e.preventDefault()\n if (uploadInProgress === true) return\n\n uploadFileContainer.style.display = 'none'\n uploadButtonWrapper.style.display = 'none'\n videoInput.value = ''\n file = null\n if (!keepMessage) setMessage('No file selected')\n\n return false\n}\n\nconst startUploading = () => {\n if (uploadInProgress === true) return\n if (!file) return\n\n isProcessing = false\n iPreviousBytesLoaded = 0\n setMessage('')\n setProgress(0)\n setUploadState(true)\n\n const formData = new FormData()\n formData.append('video_file', file)\n formData.append('video_title', videoTitle.value)\n formData.append('video_description', videoDescription.value)\n const xhr = new XMLHttpRequest()\n\n xhr.upload.addEventListener('progress', uploadProgress, false)\n xhr.addEventListener('load', uploadFinish, false)\n xhr.addEventListener('error', uploadError, false)\n xhr.addEventListener('abort', uploadAbort, false)\n\n xhr.open('POST', '/upload')\n xhr.send(formData)\n\n timer = setInterval(doInnerUpdates, 300)\n}\n\nconst doInnerUpdates = () => { // we will use this function to display upload speed\n if (isProcessing) {\n clearInterval(timer)\n return\n }\n\n let iDiff = iBytesUploaded - iPreviousBytesLoaded\n // if nothing new loaded - exit\n if (iDiff == 0)\n return\n iPreviousBytesLoaded = iBytesUploaded\n iDiff = iDiff * 2\n const iBytesRem = iBytesTotal - iPreviousBytesLoaded\n const secondsRemaining = iBytesRem / iDiff\n // update speed info\n let iSpeed = iDiff.toString() + 'B/s'\n if (iDiff > 1024 * 1024) {\n iSpeed = (Math.round(iDiff * 100/(1024*1024))/100).toString() + 'MB/s'\n } else if (iDiff > 1024) {\n iSpeed = (Math.round(iDiff * 100/1024)/100).toString() + 'KB/s'\n }\n\n const speedMessage = `${iSpeed} | ${secondsToTime(secondsRemaining)}`\n setMessage(speedMessage)\n}\n\nfunction uploadProgress(e) { // upload process in progress\n if (e.lengthComputable) {\n iBytesUploaded = e.loaded\n iBytesTotal = e.total\n\n const iPercentComplete = Math.round(iBytesUploaded / iBytesTotal * 100)\n setProgress(iPercentComplete)\n if (iPercentComplete === 100) {\n isProcessing = true\n setMessage('Processing video... please wait')\n }\n } else {\n setMessage('Unable to compute progress.')\n }\n}\n\nconst uploadFinish = (e) => { // upload successfully finished\n const message = e.target.responseText\n const isSuccess = e.target.status < 400\n\n setProgress(isSuccess ? 100 : 0)\n setMessage(message, !isSuccess)\n setUploadState(false)\n if (isSuccess) removeFile(null, true)\n}\n\nconst uploadError = () => { // upload error\n setMessage('An error occurred while uploading the file.', true)\n setProgress(0)\n setUploadState(false)\n}\n\nconst uploadAbort = () => { // upload abort\n setMessage('The upload has been canceled by the user or the browser dropped the connection.', true)\n setProgress(0)\n setUploadState(false)\n}\n"), + Content: string("// common variables\nlet iBytesUploaded = 0\nlet iBytesTotal = 0\nlet iPreviousBytesLoaded = 0\nlet iMaxFilesize = 104857600 // 100MB\nlet timer = 0\nlet uploadInProgress = 'n/a'\nlet isProcessing = false\nlet file = null\n\n/* CACHED ELEMENTS */\n\nconst uploadForm = document.getElementById('upload-form')\nconst videoInput = document.getElementById('video-input')\nconst videoTitle = document.getElementById('video-title')\nconst videoDescription = document.getElementById('video-description')\nconst uploadMessageLabel = document.getElementById('upload-message')\nconst uploadFileContainer = document.getElementById('upload-file')\nconst uploadFilenameLabel = document.getElementById('upload-filename')\nconst uploadButtonWrapper = document.getElementById('upload-button-wrapper')\nconst uploadButton = document.getElementById('upload-button')\nconst uploadProgressContainer = document.getElementById('upload-progress-container')\nconst uploadProgressBar = document.getElementById('upload-progress')\nconst uploadProgressLabel = document.getElementById('upload-progress-label')\nconst uploadStopped = document.getElementById('upload-stopped')\nconst uploadStarted = document.getElementById('upload-started')\n\n/* HELPERS */\n\nconst setProgress = (_progress) => {\n uploadProgressContainer.style.display = _progress > 0 ? 'flex' : 'none'\n uploadProgressBar.style.width = `${_progress}%`\n uploadProgressLabel.innerText = _progress >= 15 ? `${_progress}%` : ''\n}\n\nconst setMessage = (_message, isError) => {\n uploadMessageLabel.style.display = _message ? 'block' : 'none'\n uploadMessageLabel.innerHTML = _message\n if (isError) {\n uploadMessageLabel.classList.add('error')\n } else {\n uploadMessageLabel.classList.remove('error')\n }\n}\n\nconst setUploadState = (_uploadInProgress) => {\n uploadInProgress = _uploadInProgress\n\n uploadStarted.style.display = _uploadInProgress ? 'inline-block' : 'none'\n uploadStopped.style.display = _uploadInProgress ? 'none' : 'block'\n\n if (_uploadInProgress) {\n uploadButton.classList.add('transparent')\n timer = setInterval(doInnerUpdates, 300)\n } else {\n uploadButton.classList.remove('transparent')\n clearInterval(timer)\n }\n}\n\nconst secondsToTime = (secs) => {\n let hr = Math.floor(secs / 3600)\n let min = Math.floor((secs - (hr * 3600)) / 60)\n let sec = Math.floor(secs - (hr * 3600) - (min * 60))\n if (hr < 10) hr = `0${hr}`\n if (min < 10) min = `0${min}`\n if (sec < 10) sec = `0${sec}`\n if (hr) hr = '00'\n return `${hr}:${min}:${sec}`\n}\n\nconst bytesToSize = (bytes) => {\n const sizes = ['Bytes', 'KB', 'MB']\n if (bytes == 0) return 'n/a'\n const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))\n return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i]\n}\n\nconst determineDragAndDropCapable = () => {\n const div = document.createElement('div')\n return (('draggable' in div)\n || ('ondragstart' in div && 'ondrop' in div))\n && 'FormData' in window\n && 'FileReader' in window\n}\n\n/* MAIN */\n\ndocument.addEventListener('DOMContentLoaded', () => {\n console.log(\"adding event listeners...\");\n videoTitle.addEventListener(\"keypress\", (e) => {\n console.log(\"keypress[1]: \" + e);\n if (e.keyCode == 9 || keyCode == 13 || keyCode == 10) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n });\n\n videoDescription.addEventListener(\"keypress\", (e) => {\n console.log(\"keypress[2]: \" + e);\n if (e.keyCode == 9 || keyCode == 13 || keyCode == 10) {\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n });\n\n ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave']\n .forEach((evt) => {\n uploadForm.addEventListener(evt, (e) => {\n e.preventDefault()\n e.stopPropagation()\n })\n })\n\n uploadForm.addEventListener('drop', (e) => {\n console.log(111)\n e.preventDefault()\n e.stopPropagation()\n\n const _file = e.dataTransfer.files[0]\n if (!_file) return false\n fileSelected(_file)\n\n return false\n })\n}, false)\n\nconst labelClicked = (e) => {\n if (uploadInProgress === true || file != null) {\n e.preventDefault()\n return false\n }\n}\n\nconst fileSelected = (_file) => {\n const fileObj = _file || videoInput.files[0]\n if (_file) videoInput.value = ''\n\n if (fileObj) file = fileObj\n if (!file) return\n\n if (file.size > iMaxFilesize) {\n setMessage('Your file is very big. We can\\'t accept it. Please select more small file.', true)\n return\n }\n\n setMessage('')\n setProgress(0)\n \n const filename = file.name.length <= 20 ? file.name : `${file.name.substring(0, 14)}...${file.name.substring(file.name.length - 3)}`\n uploadFilenameLabel.innerText = filename\n uploadFileContainer.style.display = 'flex'\n \n uploadButtonWrapper.style.display = 'block'\n setUploadState(false)\n}\n\nconst removeFile = (e, keepMessage) => {\n if (e) e.preventDefault()\n if (uploadInProgress === true) return\n\n uploadFileContainer.style.display = 'none'\n uploadButtonWrapper.style.display = 'none'\n videoInput.value = ''\n file = null\n if (!keepMessage) setMessage('No file selected')\n\n return false\n}\n\nconst startUploading = () => {\n if (uploadInProgress === true) return\n if (!file) return\n\n isProcessing = false\n iPreviousBytesLoaded = 0\n setMessage('')\n setProgress(0)\n setUploadState(true)\n\n const formData = new FormData()\n formData.append('video_file', file)\n formData.append('video_title', videoTitle.value)\n formData.append('video_description', videoDescription.value)\n const xhr = new XMLHttpRequest()\n\n xhr.upload.addEventListener('progress', uploadProgress, false)\n xhr.addEventListener('load', uploadFinish, false)\n xhr.addEventListener('error', uploadError, false)\n xhr.addEventListener('abort', uploadAbort, false)\n\n xhr.open('POST', '/upload')\n xhr.send(formData)\n\n timer = setInterval(doInnerUpdates, 300)\n}\n\nconst doInnerUpdates = () => { // we will use this function to display upload speed\n if (isProcessing) {\n clearInterval(timer)\n return\n }\n\n let iDiff = iBytesUploaded - iPreviousBytesLoaded\n // if nothing new loaded - exit\n if (iDiff == 0)\n return\n iPreviousBytesLoaded = iBytesUploaded\n iDiff = iDiff * 2\n const iBytesRem = iBytesTotal - iPreviousBytesLoaded\n const secondsRemaining = iBytesRem / iDiff\n // update speed info\n let iSpeed = iDiff.toString() + 'B/s'\n if (iDiff > 1024 * 1024) {\n iSpeed = (Math.round(iDiff * 100/(1024*1024))/100).toString() + 'MB/s'\n } else if (iDiff > 1024) {\n iSpeed = (Math.round(iDiff * 100/1024)/100).toString() + 'KB/s'\n }\n\n const speedMessage = `${iSpeed} | ${secondsToTime(secondsRemaining)}`\n setMessage(speedMessage)\n}\n\nfunction uploadProgress(e) { // upload process in progress\n if (e.lengthComputable) {\n iBytesUploaded = e.loaded\n iBytesTotal = e.total\n\n const iPercentComplete = Math.round(iBytesUploaded / iBytesTotal * 100)\n setProgress(iPercentComplete)\n if (iPercentComplete === 100) {\n isProcessing = true\n setMessage('Processing video... please wait')\n }\n } else {\n setMessage('Unable to compute progress.')\n }\n}\n\nconst uploadFinish = (e) => { // upload successfully finished\n const message = e.target.responseText\n const isSuccess = e.target.status < 400\n\n setProgress(isSuccess ? 100 : 0)\n setMessage(message, !isSuccess)\n setUploadState(false)\n if (isSuccess) removeFile(null, true)\n}\n\nconst uploadError = () => { // upload error\n setMessage('An error occurred while uploading the file.', true)\n setProgress(0)\n setUploadState(false)\n}\n\nconst uploadAbort = () => { // upload abort\n setMessage('The upload has been canceled by the user or the browser dropped the connection.', true)\n setProgress(0)\n setUploadState(false)\n}\n"), } // define dirs dir6 := &embedded.EmbeddedDir{ Filename: "", - DirModTime: time.Unix(1585463457, 0), + DirModTime: time.Unix(1585653781, 0), ChildFiles: []*embedded.EmbeddedFile{ file7, // "close-icon.png" file8, // "defaulticon.jpg" @@ -148,7 +148,7 @@ func init() { // register embeddedBox embedded.RegisterEmbeddedBox(`../static`, &embedded.EmbeddedBox{ Name: `../static`, - Time: time.Unix(1585463457, 0), + Time: time.Unix(1585653781, 0), Dirs: map[string]*embedded.EmbeddedDir{ "": dir6, }, diff --git a/static/import.js b/static/import.js index aa29b87..29922f6 100644 --- a/static/import.js +++ b/static/import.js @@ -75,10 +75,20 @@ const bytesToSize = (bytes) => { /* MAIN */ document.addEventListener('DOMContentLoaded', () => { - importInput.addEventListener("keyup", (e) => { - if (e.keyCode === 13) { + importInput.addEventListener("keypress", (e) => { + if (e.keyCode == 9) { + urlSelected(); e.preventDefault(); + e.stopPropagation(); + return; + } + + if (e.keyCode === 13 || e.keyCode == 10) { + e.preventDefault(); + e.stopPropagation(); + urlSelected(); importButton.click(); + return; } }); }, false)