2017-11-22 00:44:27 +01:00
<div id="asset-display-component">
2017-11-29 19:37:19 +01:00
<div id="asset-status">
2017-11-30 01:02:40 +01:00
<p id="searching-message" hidden="true">Sit tight, we're searching the LBRY blockchain for your asset!</p>
2017-11-29 19:37:19 +01:00
<div id="failure-message" hidden="true">
<p>Unfortunately, we couldn't download your asset from LBRY. You can help us out by sharing the below error message in the <a class="link--primary" href="https://discord.gg/YjYbwhS" target="_blank">LBRY discord</a>.</p>
<i><p id="error-message"></p></i>
</div>
</div>
<div id="asset-holder" hidden="true">
2017-11-22 00:44:27 +01:00
{{ # if Conditional claimInfo .contentType '===' 'video/mp4' }}
2017-11-28 21:17:22 +01:00
{{ > video }}
2017-11-22 00:44:27 +01:00
{{ else }}
2017-11-28 21:17:22 +01:00
{{ > image }}
2017-11-22 00:44:27 +01:00
{{ / if Conditional }}
2017-11-29 20:21:45 +01:00
<div>
<a id="asset-boilerpate" class="link--primary fine-print" href="/ {{ claimInfo .claimId }} / {{ claimInfo .name }} ">hosted via Spee<h</a>
</div>
2017-11-21 21:53:43 +01:00
</div>
</div>
<script type="text/javascript">
const getAssetFunctions = {
showAsset: function () {
2017-11-29 19:37:19 +01:00
this.hideAssetStatus();
this.showAssetHolder();
2017-11-29 18:10:40 +01:00
{{ # if Conditional claimInfo .contentType '===' 'video/mp4' }}
this.showVideo();
{{ else }}
this.showImage();
{{ / if Conditional }}
},
showVideo: function () {
console.log('showing video');
2017-11-29 19:11:56 +01:00
const video = document.getElementById('video-asset');
2017-11-29 18:10:40 +01:00
const source = document.createElement('source');
source.setAttribute('src', '/ {{ claimInfo .claimId }} / {{ claimInfo .name }} . {{ claimInfo .fileExt }} ');
video.appendChild(source);
video.play();
},
showImage: function () {
console.log('showing image');
2017-11-29 19:11:56 +01:00
const asset = document.getElementById('image-asset');
2017-11-29 18:10:40 +01:00
asset.setAttribute('src', "/ {{ claimInfo .claimId }} / {{ claimInfo .name }} . {{ claimInfo .fileExt }} ");
},
2017-11-29 19:37:19 +01:00
hideAssetStatus: function () {
const assetStatus = document.getElementById('asset-status');
assetStatus.hidden = true;
},
showAssetHolder: function () {
const assetHolder = document.getElementById('asset-holder');
assetHolder.hidden = false;
2017-11-22 00:44:27 +01:00
},
2017-11-29 18:10:40 +01:00
showSearchMessage: function () {
const searchMessage = document.getElementById('searching-message');
2017-11-22 00:44:27 +01:00
searchMessage.hidden = false;
2017-11-21 21:53:43 +01:00
},
showFailureMessage: function (msg) {
console.log(msg);
2017-11-29 18:10:40 +01:00
const searchMessage = document.getElementById('searching-message');
2017-11-21 21:53:43 +01:00
const failureMessage = document.getElementById('failure-message');
2017-11-29 19:37:19 +01:00
const errorMessage = document.getElementById('error-message');
2017-11-21 21:53:43 +01:00
searchMessage.hidden = true;
failureMessage.hidden = false;
2017-11-29 19:37:19 +01:00
errorMessage.innerText = msg;
2017-11-21 21:53:43 +01:00
},
2017-11-22 00:44:27 +01:00
checkClaimAvailability: function (claimName, claimId) {
2017-11-29 19:37:19 +01:00
console.log(`checking local availability for $ { claimName}#$ { claimId}`)
2017-11-30 00:36:23 +01:00
var uri = `/api/local-file-available/$ { claimName}/$ { claimId}`;
2017-11-22 00:44:27 +01:00
var xhr = new XMLHttpRequest();
var that = this;
xhr.open("GET", uri, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
const response = JSON.parse(xhr.response);
2017-11-22 00:49:16 +01:00
if (xhr.status == 200) {
2017-11-28 21:17:22 +01:00
if (response.message === true) {
2017-11-22 00:49:16 +01:00
console.log('local asset is available on spee.ch')
that.showAsset();
2017-11-28 21:17:22 +01:00
} else {
that.showSearchMessage();
that.getAsset(claimName, claimId)
2017-11-22 00:49:16 +01:00
}
2017-11-22 00:44:27 +01:00
} else {
console.log('get failed:', response);
that.showFailureMessage('Well this sucks, but we can\'t seem to phone home');
}
} else {
console.log('xhr.readyState', xhr.readyState);
}
};
xhr.send();
2017-11-21 21:53:43 +01:00
},
getAsset: function(claimName, claimId) {
2017-11-29 20:56:09 +01:00
console.log(`getting $ { claimName}#$ { claimId}`)
2017-11-29 21:41:53 +01:00
var uri = `/api/get-claim/$ { claimName}/$ { claimId}`;
2017-11-29 20:56:09 +01:00
var xhr = new XMLHttpRequest();
var that = this;
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}`);
}
} else {
console.log('xhr.readyState', xhr.readyState);
}
};
xhr.send();
},
2017-11-21 21:53:43 +01:00
}
2017-11-22 00:44:27 +01:00
getAssetFunctions.checkClaimAvailability(' {{ claimInfo .name }} ', ' {{ claimInfo .claimId }} ');
2017-11-21 21:53:43 +01:00
</script>