separated client functions into availability and get
This commit is contained in:
parent
cda9efa800
commit
58cb05d2dc
9 changed files with 102 additions and 141 deletions
|
@ -47,9 +47,8 @@ module.exports = {
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
res.status(200).sendFile(filePath, options);
|
res.status(200).sendFile(filePath, options);
|
||||||
} else {
|
} else {
|
||||||
// 'get' the file
|
// res.status(307).redirect(`/api/get/${name}/${claimId}`);
|
||||||
// send the file
|
res.status(400).json({success: false, message: 'that claim is not hosted locally by Spee<ch yet'});
|
||||||
res.status(307).redirect(`/api/get/${name}/${claimId}`);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showFile (fileInfo, claimInfo, shortId, res) {
|
showFile (fileInfo, claimInfo, shortId, res) {
|
||||||
|
|
|
@ -99,6 +99,10 @@ h3, p {
|
||||||
font-size: small;
|
font-size: small;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#show-body > .fine-print {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.blue {
|
.blue {
|
||||||
color: #4156C5;
|
color: #4156C5;
|
||||||
}
|
}
|
||||||
|
@ -153,9 +157,7 @@ a, a:visited {
|
||||||
.link--primary, .link--primary:visited {
|
.link--primary, .link--primary:visited {
|
||||||
color: #4156C5;
|
color: #4156C5;
|
||||||
}
|
}
|
||||||
.link--primary.fine-print {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.link--nav {
|
.link--nav {
|
||||||
color: black;
|
color: black;
|
||||||
border-bottom: 2px solid white;
|
border-bottom: 2px solid white;
|
||||||
|
@ -513,11 +515,7 @@ table {
|
||||||
|
|
||||||
/* Show page */
|
/* Show page */
|
||||||
|
|
||||||
.video-show, .gifv-show, .image-show {
|
#video-player {
|
||||||
display: block;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
#video-player, .showlite-asset {
|
|
||||||
display: block;
|
display: block;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
|
@ -529,10 +527,15 @@ table {
|
||||||
max-width: 50%;
|
max-width: 50%;
|
||||||
border: 1px solid #d0d0d0;
|
border: 1px solid #d0d0d0;
|
||||||
}
|
}
|
||||||
.showlite-asset {
|
|
||||||
|
.asset {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#showlite-body > .asset {
|
||||||
|
max-width: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
/* item lists */
|
/* item lists */
|
||||||
|
|
||||||
.content-list-item-asset {
|
.content-list-item-asset {
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
padding-right: 1.5em;
|
padding-right: 1.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.showlite-asset {
|
#showlite-body > asset {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,57 +30,6 @@ function createFileRecord ({ name, claimId, outpoint, height, address, nsfw, con
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// function getAssetByLongClaimId (fullClaimId, name) {
|
|
||||||
// logger.debug('...getting asset by claim Id...');
|
|
||||||
// return new Promise((resolve, reject) => {
|
|
||||||
// // 1. check locally for claim
|
|
||||||
// checkForLocalAssetByClaimId(fullClaimId, name)
|
|
||||||
// .then(dataValues => {
|
|
||||||
// // if a result was found, return early with the result
|
|
||||||
// if (dataValues) {
|
|
||||||
// logger.debug('found a local file for this name and claimId');
|
|
||||||
// resolve(dataValues);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// logger.debug('no local file found for this name and claimId');
|
|
||||||
// // 2. if no local claim, resolve and get the claim
|
|
||||||
// db.Claim
|
|
||||||
// .resolveClaim(name, fullClaimId)
|
|
||||||
// .then(resolveResult => {
|
|
||||||
// // if no result, return early (claim doesn't exist or isn't free)
|
|
||||||
// if (!resolveResult) {
|
|
||||||
// resolve(NO_CLAIM);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// logger.debug('resolve result >> ', resolveResult.dataValues);
|
|
||||||
// let fileRecord = {};
|
|
||||||
// // get the claim
|
|
||||||
// lbryApi.getClaim(`${name}#${fullClaimId}`)
|
|
||||||
// .then(getResult => {
|
|
||||||
// logger.debug('getResult >>', getResult);
|
|
||||||
// fileRecord = createFileRecord(resolveResult);
|
|
||||||
// fileRecord = addGetResultsToFileRecord(fileRecord, getResult);
|
|
||||||
// // insert a record in the File table & Update Claim table
|
|
||||||
// return db.File.create(fileRecord);
|
|
||||||
// })
|
|
||||||
// .then(() => {
|
|
||||||
// logger.debug('File record successfully updated');
|
|
||||||
// resolve(fileRecord);
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// reject(error);
|
|
||||||
// });
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// reject(error);
|
|
||||||
// });
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// reject(error);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to run a claim_list request on the daemon
|
// route to run a claim_list request on the daemon
|
||||||
app.get('/api/claim_list/:name', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/claim_list/:name', ({ ip, originalUrl, params }, res) => {
|
||||||
|
@ -93,30 +42,42 @@ module.exports = (app) => {
|
||||||
errorHandlers.handleApiError('claim_list', originalUrl, ip, error, res);
|
errorHandlers.handleApiError('claim_list', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// route to see if asset is available locally
|
||||||
|
app.get('/api/local/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
||||||
|
const name = params.name;
|
||||||
|
const claimId = params.claimId;
|
||||||
|
let isLocalFileAvailable = false;
|
||||||
|
db.File.findOne({where: {name, claimId}})
|
||||||
|
.then(result => {
|
||||||
|
if (result) {
|
||||||
|
isLocalFileAvailable = true;
|
||||||
|
}
|
||||||
|
res.status(200).json({status: 'success', isLocalFileAvailable});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
errorHandlers.handleApiError('get', originalUrl, ip, error, res);
|
||||||
|
});
|
||||||
|
});
|
||||||
// route to get an asset
|
// route to get an asset
|
||||||
app.get('/api/get/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/get/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
||||||
if (!params.name || !params.claimId) {
|
|
||||||
res.status(400).json({success: false, message: 'provide a claimId and/or a name'});
|
|
||||||
}
|
|
||||||
let fileRecord;
|
let fileRecord;
|
||||||
// 1. resolve the claim
|
// resolve and get the claim
|
||||||
db.Claim.resolveClaim(params.name, params.claimId)
|
db.Claim.resolveClaim(params.name, params.claimId)
|
||||||
.then(resolveResult => {
|
.then(resolveResult => {
|
||||||
if (!resolveResult) {
|
if (!resolveResult) {
|
||||||
throw new Error('No matching uri found in Claim table');
|
throw new Error('No matching uri found in Claim table');
|
||||||
}
|
}
|
||||||
fileRecord = createFileRecord(resolveResult);
|
fileRecord = createFileRecord(resolveResult);
|
||||||
// 2. get the claim
|
// get the claim
|
||||||
return getClaim(`${params.name}#${params.claimId}`);
|
return getClaim(`${params.name}#${params.claimId}`);
|
||||||
})
|
})
|
||||||
.then(getResult => {
|
.then(getResult => {
|
||||||
res.status(200).json({status: 'success', message: getResult});
|
|
||||||
logger.debug('response was sent to the client');
|
|
||||||
fileRecord = addGetResultsToFileRecord(fileRecord, getResult);
|
fileRecord = addGetResultsToFileRecord(fileRecord, getResult);
|
||||||
// 3. insert a record for the claim into the File table
|
// insert a record for the claim into the File table
|
||||||
return db.File.create(fileRecord);
|
return db.File.create(fileRecord);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
res.status(200).json({status: 'success', message: 'content was successfully retrieved via lbrynet'});
|
||||||
logger.debug('File record successfully created');
|
logger.debug('File record successfully created');
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
{{ googleAnalytics }}
|
{{ googleAnalytics }}
|
||||||
</head>
|
</head>
|
||||||
<body id="showlite-body">
|
<body id="showlite-body">
|
||||||
{{> getAsset}}
|
{{{ body }}}
|
||||||
<script src="/assets/js/showFunctions.js"></script>
|
<script src="/assets/js/showFunctions.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
{{#ifConditional claimInfo.contentType '===' 'video/mp4'}}
|
<div id="asset-display-component">
|
||||||
{{#ifConditional claimInfo.fileExt '===' 'gifv'}}
|
<p id="search-message" hidden="true">We're currently combing the blockchain for your asset!</p>
|
||||||
<video class="gifv-show" autoplay loop muted>
|
<p id="failure-message" hidden="true"></p>
|
||||||
<source src="/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}">
|
<div id="asset-holder" hidden="true">
|
||||||
{{!--fallback--}}
|
{{#ifConditional claimInfo.contentType '===' 'video/mp4'}}
|
||||||
Your browser does not support the <code>video</code> element.
|
<video id="video-player" controls poster="{{claimInfo.thumbnail}}">
|
||||||
</video>
|
<source id="asset">
|
||||||
{{else}}
|
<!--fallback-->
|
||||||
<video id="video-player" class="video-show video" controls poster="{{claimInfo.thumbnail}}">
|
|
||||||
<source src="/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}">
|
|
||||||
{{!--fallback--}}
|
|
||||||
Your browser does not support the <code>video</code> element.
|
Your browser does not support the <code>video</code> element.
|
||||||
</video>
|
</video>
|
||||||
|
<!--dynamically resize video player-->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
document.addEventListener('DOMContentLoaded', resizeVideoPlayer)
|
document.addEventListener('DOMContentLoaded', resizeVideoPlayer)
|
||||||
window.addEventListener("resize", resizeVideoPlayer);
|
window.addEventListener("resize", resizeVideoPlayer);
|
||||||
|
@ -20,22 +18,9 @@
|
||||||
div.height = (width * 9 / 16);
|
div.height = (width * 9 / 16);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
{{else}}
|
||||||
|
<img id="asset" class="asset" />
|
||||||
{{/ifConditional}}
|
{{/ifConditional}}
|
||||||
{{else}}
|
|
||||||
<a href="/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}">
|
|
||||||
<img class="image-show" src="/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}" />
|
|
||||||
</a>
|
|
||||||
{{/ifConditional}}
|
|
||||||
|
|
||||||
<div id="asset-holder">
|
|
||||||
<div id="search-message" hidden="true">
|
|
||||||
<p>We're currently combing the blockchain for your asset!</p>
|
|
||||||
</div>
|
|
||||||
<div id="failure-message" hidden="true">
|
|
||||||
<p>Hmmm, looks like no peers have your content. How anti-social!</p>
|
|
||||||
</div>
|
|
||||||
<div id="asset" hidden="true">
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -44,9 +29,16 @@
|
||||||
const getAssetFunctions = {
|
const getAssetFunctions = {
|
||||||
showAsset: function () {
|
showAsset: function () {
|
||||||
const searchMessage = document.getElementById('search-message');
|
const searchMessage = document.getElementById('search-message');
|
||||||
|
const assetHolder = document.getElementById('asset-holder');
|
||||||
const asset = document.getElementById('asset');
|
const asset = document.getElementById('asset');
|
||||||
searchMessage.hidden = true;
|
searchMessage.hidden = true;
|
||||||
asset.hidden = false;
|
assetHolder.hidden = false;
|
||||||
|
asset.setAttribute('src', `/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}`);
|
||||||
|
},
|
||||||
|
showSearchMessage: function (msg) {
|
||||||
|
console.log(msg);
|
||||||
|
const searchMessage = document.getElementById('search-message');
|
||||||
|
searchMessage.hidden = false;
|
||||||
},
|
},
|
||||||
showFailureMessage: function (msg) {
|
showFailureMessage: function (msg) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
@ -54,26 +46,49 @@
|
||||||
const failureMessage = document.getElementById('failure-message');
|
const failureMessage = document.getElementById('failure-message');
|
||||||
searchMessage.hidden = true;
|
searchMessage.hidden = true;
|
||||||
failureMessage.hidden = false;
|
failureMessage.hidden = false;
|
||||||
|
failureMessage.innerText(msg);
|
||||||
},
|
},
|
||||||
displayAsset: function(contentType, source) {
|
checkClaimAvailability: function (claimName, claimId) {
|
||||||
|
console.log(`getting ${claimName}#${claimId}}`)
|
||||||
|
var uri = `/api/get/${claimName}/${claimId}`;
|
||||||
|
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 && response.message === false) {
|
||||||
|
that.showSearchMessage();
|
||||||
|
that.getAsset(claimName, claimId)
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Initiate a multipart/form-data upload
|
||||||
|
xhr.send();
|
||||||
},
|
},
|
||||||
getAsset: function(claimName, claimId) {
|
getAsset: function(claimName, claimId) {
|
||||||
console.log(`getting ${claimName}#${claimId}}`)
|
console.log(`getting ${claimName}#${claimId}}`)
|
||||||
var uri = `/api/get/${claimName}/${claimId}`;
|
var uri = `/api/get/${claimName}/${claimId}`;
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
|
var that = this;
|
||||||
xhr.open("GET", uri, true);
|
xhr.open("GET", uri, true);
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState == 4) {
|
if (xhr.readyState == 4) {
|
||||||
|
const response = JSON.parse(xhr.response);
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
console.log('get returned successfully', xhr.response);
|
console.log('get returned successfully', response);
|
||||||
this.showAsset();
|
that.showAsset();
|
||||||
} else {
|
} else {
|
||||||
console.log('get failed:', xhr.response);
|
console.log('get failed:', response);
|
||||||
|
that.showFailureMessage('Hmmm, looks like no peers have your content. How anti-social!');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('xhr.readyState', xhr.readyState);
|
console.log('xhr.readyState', xhr.readyState);
|
||||||
this.showFailureMessage(xhr.readyState.message);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Initiate a multipart/form-data upload
|
// Initiate a multipart/form-data upload
|
||||||
|
@ -81,4 +96,6 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAssetFunctions.checkClaimAvailability('{{claimInfo.name}}', '{{claimInfo.claimId}}');
|
||||||
|
|
||||||
</script>
|
</script>
|
|
@ -1,17 +0,0 @@
|
||||||
<div class="row row--tall row--padded">
|
|
||||||
<div class="column column--10">
|
|
||||||
<!-- title -->
|
|
||||||
<span class="text--large">{{claimInfo.title}}</span>
|
|
||||||
</div>
|
|
||||||
<div class="column column--5 column--sml-10 align-content-top">
|
|
||||||
<!-- asset -->
|
|
||||||
<div class="row row--padded">
|
|
||||||
{{> asset}}
|
|
||||||
</div>
|
|
||||||
</div><div class="column column--5 column--sml-10 align-content-top">
|
|
||||||
<!-- details -->
|
|
||||||
<div class="row row--padded">
|
|
||||||
{{> assetInfo}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
|
@ -1,2 +0,0 @@
|
||||||
{{> asset }}
|
|
||||||
<a class="link--primary fine-print" href="/{{claimInfo.claimId}}/{{claimInfo.name}}">hosted via spee<h</a>
|
|
|
@ -1,2 +1,2 @@
|
||||||
{{> asset }}
|
{{> asset }}
|
||||||
<a class="link--primary fine-print" href="/{{claimInfo.claimId}}/{{claimInfo.name}}">hosted via spee<h</a>
|
<a class="link--primary fine-print" href="/{{claimInfo.claimId}}/{{claimInfo.name}}">hosted via Spee<h</a>
|
Loading…
Reference in a new issue