updated api/get_claim route to return message and status
This commit is contained in:
parent
fe49f7e7de
commit
8400ca5110
4 changed files with 55 additions and 33 deletions
|
@ -10,13 +10,13 @@ const errorHandlers = require('../helpers/errorHandlers.js');
|
||||||
const { postToStats } = require('../controllers/statsController.js');
|
const { postToStats } = require('../controllers/statsController.js');
|
||||||
const { authenticateOrSkip } = require('../auth/authentication.js');
|
const { authenticateOrSkip } = require('../auth/authentication.js');
|
||||||
|
|
||||||
function addGetResultsToFileRecord (fileInfo, getResult) {
|
function addGetResultsToFileData (fileInfo, getResult) {
|
||||||
fileInfo.fileName = getResult.file_name;
|
fileInfo.fileName = getResult.file_name;
|
||||||
fileInfo.filePath = getResult.download_path;
|
fileInfo.filePath = getResult.download_path;
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFileRecord ({ name, claimId, outpoint, height, address, nsfw, contentType }) {
|
function createFileData ({ name, claimId, outpoint, height, address, nsfw, contentType }) {
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
claimId,
|
claimId,
|
||||||
|
@ -60,24 +60,23 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// route to get an asset
|
// route to get an asset
|
||||||
app.get('/api/get_claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/get_claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
|
||||||
let fileRecord;
|
// 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 => {
|
||||||
|
// make sure a claim actually exists at that uri
|
||||||
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);
|
let fileData = createFileData(resolveResult);
|
||||||
// get the claim
|
// get the claim
|
||||||
return getClaim(`${params.name}#${params.claimId}`);
|
return Promise.all([fileData, getClaim(`${params.name}#${params.claimId}`)]);
|
||||||
})
|
})
|
||||||
.then(getResult => {
|
.then(([ fileData, getResult ]) => {
|
||||||
fileRecord = addGetResultsToFileRecord(fileRecord, getResult);
|
fileData = addGetResultsToFileData(fileData, getResult);
|
||||||
// insert a record for the claim into the File table
|
return Promise.all([db.File.create(fileData), getResult]); // insert a record for the claim into the File table
|
||||||
return db.File.create(fileRecord);
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(([ fileRecord, {message, completed} ]) => {
|
||||||
res.status(200).json({status: 'success', message: 'content was successfully retrieved via lbrynet'});
|
res.status(200).json({ status: 'success', message, completed });
|
||||||
logger.debug('File record successfully created');
|
logger.debug('File record successfully created');
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -3,23 +3,9 @@
|
||||||
<p id="failure-message" hidden="true"></p>
|
<p id="failure-message" hidden="true"></p>
|
||||||
<div id="asset-holder" hidden="true">
|
<div id="asset-holder" hidden="true">
|
||||||
{{#ifConditional claimInfo.contentType '===' 'video/mp4'}}
|
{{#ifConditional claimInfo.contentType '===' 'video/mp4'}}
|
||||||
<video id="video-player" controls poster="{{claimInfo.thumbnail}}">
|
{{> video}}
|
||||||
<source id="asset">
|
|
||||||
<!--fallback-->
|
|
||||||
Your browser does not support the <code>video</code> element.
|
|
||||||
</video>
|
|
||||||
<!--dynamically resize video player-->
|
|
||||||
<script type="text/javascript">
|
|
||||||
document.addEventListener('DOMContentLoaded', resizeVideoPlayer)
|
|
||||||
window.addEventListener("resize", resizeVideoPlayer);
|
|
||||||
function resizeVideoPlayer() {
|
|
||||||
const div = document.getElementById('video-player');
|
|
||||||
const width = div.offsetWidth;
|
|
||||||
div.height = (width * 9 / 16);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{{else}}
|
{{else}}
|
||||||
<img id="asset" class="asset" />
|
{{> image}}
|
||||||
{{/ifConditional}}
|
{{/ifConditional}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,6 +20,7 @@
|
||||||
searchMessage.hidden = true;
|
searchMessage.hidden = true;
|
||||||
assetHolder.hidden = false;
|
assetHolder.hidden = false;
|
||||||
asset.setAttribute('src', `/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}`);
|
asset.setAttribute('src', `/{{claimInfo.claimId}}/{{claimInfo.name}}.{{claimInfo.fileExt}}`);
|
||||||
|
asset.load();
|
||||||
},
|
},
|
||||||
showSearchMessage: function (msg) {
|
showSearchMessage: function (msg) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
@ -58,12 +45,12 @@
|
||||||
if (xhr.readyState == 4) {
|
if (xhr.readyState == 4) {
|
||||||
const response = JSON.parse(xhr.response);
|
const response = JSON.parse(xhr.response);
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
if (response.message === false) {
|
if (response.message === true) {
|
||||||
that.showSearchMessage();
|
|
||||||
that.getAsset(claimName, claimId)
|
|
||||||
} else {
|
|
||||||
console.log('local asset is available on spee.ch')
|
console.log('local asset is available on spee.ch')
|
||||||
that.showAsset();
|
that.showAsset();
|
||||||
|
} else {
|
||||||
|
that.showSearchMessage();
|
||||||
|
that.getAsset(claimName, claimId)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('get failed:', response);
|
console.log('get failed:', response);
|
||||||
|
@ -87,7 +74,13 @@
|
||||||
const response = JSON.parse(xhr.response);
|
const response = JSON.parse(xhr.response);
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
console.log('get returned successfully', response);
|
console.log('get returned successfully', response);
|
||||||
|
if (response.completed === true) {
|
||||||
|
console.log('lbrynet has finished downloading the asset');
|
||||||
that.showAsset();
|
that.showAsset();
|
||||||
|
} else {
|
||||||
|
console.log('lbrynet is still downloading the asset');
|
||||||
|
setTimeout(getAsset, 5000);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('get failed:', response);
|
console.log('get failed:', response);
|
||||||
that.showFailureMessage(`${response.message}`);
|
that.showFailureMessage(`${response.message}`);
|
||||||
|
|
15
views/partials/image.handlebars
Normal file
15
views/partials/image.handlebars
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<video id="video-player" controls poster="{{claimInfo.thumbnail}}">
|
||||||
|
<source id="asset">
|
||||||
|
<!--fallback-->
|
||||||
|
Your browser does not support the <code>video</code> element.
|
||||||
|
</video>
|
||||||
|
<!--dynamically resize video player-->
|
||||||
|
<script type="text/javascript">
|
||||||
|
document.addEventListener('DOMContentLoaded', resizeVideoPlayer)
|
||||||
|
window.addEventListener("resize", resizeVideoPlayer);
|
||||||
|
function resizeVideoPlayer() {
|
||||||
|
const div = document.getElementById('video-player');
|
||||||
|
const width = div.offsetWidth;
|
||||||
|
div.height = (width * 9 / 16);
|
||||||
|
}
|
||||||
|
</script>
|
15
views/partials/video.handlebars
Normal file
15
views/partials/video.handlebars
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<video id="video-player" controls poster="{{claimInfo.thumbnail}}">
|
||||||
|
<source id="asset">
|
||||||
|
<!--fallback-->
|
||||||
|
Your browser does not support the <code>video</code> element.
|
||||||
|
</video>
|
||||||
|
<!--dynamically resize video player-->
|
||||||
|
<script type="text/javascript">
|
||||||
|
document.addEventListener('DOMContentLoaded', resizeVideoPlayer)
|
||||||
|
window.addEventListener("resize", resizeVideoPlayer);
|
||||||
|
function resizeVideoPlayer() {
|
||||||
|
const div = document.getElementById('video-player');
|
||||||
|
const width = div.offsetWidth;
|
||||||
|
div.height = (width * 9 / 16);
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in a new issue