From e1d03f16582247491a64a1c18a17610a23f9f522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Z=C3=A1le=C5=A1=C3=A1k?= Date: Tue, 2 Feb 2021 00:18:41 +0100 Subject: [PATCH] =?UTF-8?q?Oprava=20upload=20scriptu=20a=20=C3=BAprava=20n?= =?UTF-8?q?a=C4=8D=C3=ADt=C3=A1n=C3=AD=20vide=C3=AD=20closes=20#8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/controller.js | 58 ++++++++++++++++++------------------------------ js/model.js | 25 +++++++++++++++++++++ upload.php | 12 +++++----- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/js/controller.js b/js/controller.js index a7f28d5..37c2171 100644 --- a/js/controller.js +++ b/js/controller.js @@ -10,14 +10,22 @@ class Controller { let video = document.getElementById("video"); if (videoToLoad != null && videoToLoad != "") { - this.loadVideo(videoToLoad).then( - function () { - video.addEventListener( - "loadedmetadata", + this.model.loadXml(videoToLoad).then( + function (v) { + let comments = this.model.parseXML(v); + let videoFileName = this.model.getVideoFileName(v); + this.view.drawCommentTitles(comments); + this.addEventListeners(); + this.loadVideo(videoFileName).then( function () { - this.view.videoPlayer.updateVideoDuration(); - this.addEventListenersToVideoControls(); - this.init(videoToLoad); + video.addEventListener( + "loadedmetadata", + function () { + this.view.videoPlayer.updateVideoDuration(); + this.view.drawCommentsToVideo(comments); + this.addEventListenersToVideoControls(); + }.bind(this) + ); }.bind(this) ); }.bind(this) @@ -28,21 +36,14 @@ class Controller { } } - init(videoToLoad) { - this.loadXml(videoToLoad).then( - function (v) { - this.view.drawCommentTitles(v); - this.addEventListeners(); - this.view.drawCommentsToVideo(v); - }.bind(this) - ); - } - addEventListenersToAddVideo() { let form = document.getElementById("form"); - form.addEventListener("submit", function () { - document.getElementById("xmlFile").value = this.view.editor.getValue(); - }.bind(this)); + form.addEventListener( + "submit", + function () { + document.getElementById("xmlFile").value = this.view.editor.getValue(); + }.bind(this) + ); } // Přidání listenerů @@ -121,28 +122,13 @@ class Controller { video.classList.remove("hidden"); - source.setAttribute("src", "./videos/" + v + ".webm"); + source.setAttribute("src", "./videos/" + v); video.append(source); await video.load(); this.view.createVideoPlayerObject(); } - async loadXml(v) { - var Connect = new XMLHttpRequest(); - // Define which file to open and - // send the request. - Connect.open("GET", "./videos/" + v + ".xml", false); - Connect.setRequestHeader("Content-Type", "text/xml"); - Connect.send(null); - // Place the response in an XML document. - var TheDocument = Connect.responseText; - // Place the root node in an element. - // var Customers = TheDocument.childNodes[0]; - - return this.model.parseXML(TheDocument); - } - getActiveComment() { const video = document.getElementById("video"); let currentTime = video.currentTime; diff --git a/js/model.js b/js/model.js index fb98e6a..9ef9227 100644 --- a/js/model.js +++ b/js/model.js @@ -19,4 +19,29 @@ class Model { return this.comments; } + + getVideoFileName(xml) { + let parser = new DOMParser(); + let xmlDoc = parser.parseFromString(xml, "text/xml"); + let videoTag = xmlDoc.activeElement.getAttribute("src"); + + return videoTag; + } + + getCommentsObjects() {} + + async loadXml(v) { + var Connect = new XMLHttpRequest(); + // Define which file to open and + // send the request. + Connect.open("GET", "./videos/" + v + ".xml", false); + Connect.setRequestHeader("Content-Type", "text/xml"); + Connect.send(null); + // Place the response in an XML document. + var TheDocument = Connect.responseText; + // Place the root node in an element. + // var Customers = TheDocument.childNodes[0]; + + return TheDocument; + } } diff --git a/upload.php b/upload.php index 415084c..7034dfd 100644 --- a/upload.php +++ b/upload.php @@ -26,11 +26,13 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { move_uploaded_file( $_FILES["videoFile"]["tmp_name"], - "videos/R-" . + "videos/" . $generatedFileName . "." . $extension ); - writeToFile("videos/" . $generatedFileName . ".xml", $_POST["xmlFile"]); - shell_exec("./transcode.sh > /dev/null 2>&1 &"); + $xml = $_POST["xmlFile"]; + $xml = str_replace("