diff --git a/public/assets/js/showFunctions.js b/public/assets/js/showFunctions.js
index 155404b5..8200d456 100644
--- a/public/assets/js/showFunctions.js
+++ b/public/assets/js/showFunctions.js
@@ -1,4 +1,8 @@
const showFunctions = {
+ state: {},
+ setState: function(key, value) {
+ this.state[key] = value;
+ },
addPlayPauseToVideo: function () {
const that = this;
const video = document.getElementById('video-asset');
@@ -22,5 +26,99 @@ const showFunctions = {
else{
video.pause();
}
- }
-}
\ No newline at end of file
+ },
+ showAsset: function () {
+ this.hideAssetStatus();
+ this.showAssetHolder();
+ if (!this.state.src) {
+ return console.log('error: src is not set')
+ }
+ if (!this.state.contentType) {
+ return console.log('error: contentType is not set')
+ }
+ if (this.state.contentType === 'video/mp4') {
+ this.showVideo();
+ } else {
+ this.showImage();
+ }
+ },
+ showVideo: function () {
+ console.log('showing video', this.state.src);
+ const video = document.getElementById('video-asset');
+ const source = document.createElement('source');
+ source.setAttribute('src', this.state.src);
+ video.appendChild(source);
+ video.play();
+ },
+ showImage: function () {
+ console.log('showing image', this.state.src);
+ const asset = document.getElementById('image-asset');
+ asset.setAttribute('src', this.state.src);
+ },
+ hideAssetStatus: function () {
+ const assetStatus = document.getElementById('asset-status');
+ assetStatus.hidden = true;
+ },
+ showAssetHolder: function () {
+ const assetHolder = document.getElementById('asset-holder');
+ assetHolder.hidden = false;
+ },
+ showSearchMessage: function () {
+ const searchMessage = document.getElementById('searching-message');
+ searchMessage.hidden = false;
+ },
+ showFailureMessage: function (msg) {
+ console.log(msg);
+ const searchMessage = document.getElementById('searching-message');
+ const failureMessage = document.getElementById('failure-message');
+ const errorMessage = document.getElementById('error-message');
+ searchMessage.hidden = true;
+ failureMessage.hidden = false;
+ errorMessage.innerText = msg;
+ },
+ checkClaimAvailability: function () {
+ const that = this;
+ const uri = `/api/local-file-available/${this.state.claimName}/${this.state.claimId}`;
+ const xhr = new XMLHttpRequest();
+ console.log(`checking local availability for ${this.state.claimName}#${this.state.claimId}`)
+ xhr.open("GET", uri, true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ const response = JSON.parse(xhr.response);
+ if (xhr.status == 200) {
+ if (response.message === true) {
+ console.log('local asset is available on spee.ch')
+ that.showAsset();
+ } else {
+ that.showSearchMessage();
+ that.getAsset()
+ }
+ } else {
+ console.log('get failed:', response);
+ that.showFailureMessage('Well this sucks, but we can\'t seem to phone home');
+ }
+ }
+ };
+ xhr.send();
+ },
+ getAsset: function() {
+ const that = this;
+ const uri = `/api/get-claim/${this.state.claimName}/${this.state.claimId}`;
+ const xhr = new XMLHttpRequest();
+ console.log(`getting ${this.state.claimName}#${this.state.claimId}`)
+ xhr.open("GET", uri, true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ const response = JSON.parse(xhr.response);
+ if (xhr.status == 200) {
+ console.log('get returned successfully', response);
+ that.showAsset();
+ } else {
+ console.log('get failed:', response);
+ that.showFailureMessage(`${response.message}`);
+ }
+ }
+ };
+ xhr.send();
+ },
+};
\ No newline at end of file
diff --git a/views/partials/asset.handlebars b/views/partials/asset.handlebars
index ed73dcdb..7cc50511 100644
--- a/views/partials/asset.handlebars
+++ b/views/partials/asset.handlebars
@@ -21,101 +21,12 @@
\ No newline at end of file
diff --git a/views/partials/video.handlebars b/views/partials/video.handlebars
index f3f46dbc..d968c652 100644
--- a/views/partials/video.handlebars
+++ b/views/partials/video.handlebars
@@ -6,6 +6,5 @@
\ No newline at end of file