fixed show route get process and api routes

This commit is contained in:
bill bittner 2017-11-27 16:53:32 -08:00
parent dbb552e662
commit 0fd7dd6b08
4 changed files with 10 additions and 15 deletions

View file

@ -13,12 +13,7 @@ module.exports = {
},
};
// send the file
if (filePath) {
res.status(200).sendFile(filePath, options);
} else {
// res.status(307).redirect(`/api/get/${name}/${claimId}`);
res.status(400).json({success: false, message: 'that claim is not hosted locally by Spee<ch yet'});
}
res.status(200).sendFile(filePath, options);
},
showFile (claimInfo, shortId, res) {
const openGraphInfo = module.exports.createOpenGraphInfo(claimInfo);

View file

@ -43,7 +43,7 @@ module.exports = (app) => {
});
});
// route to see if asset is available locally
app.get('/api/local/:name/:claimId', ({ ip, originalUrl, params }, res) => {
app.get('/api/check_local_claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
const name = params.name;
const claimId = params.claimId;
let isLocalFileAvailable = false;
@ -52,14 +52,14 @@ module.exports = (app) => {
if (result) {
isLocalFileAvailable = true;
}
res.status(200).json({status: 'success', isLocalFileAvailable});
res.status(200).json({status: 'success', message: isLocalFileAvailable});
})
.catch(error => {
errorHandlers.handleApiError('get', originalUrl, ip, error, res);
});
});
// route to get an asset
app.get('/api/get/:name/:claimId', ({ ip, originalUrl, params }, res) => {
app.get('/api/get_claim/:name/:claimId', ({ ip, originalUrl, params }, res) => {
let fileRecord;
// resolve and get the claim
db.Claim.resolveClaim(params.name, params.claimId)

View file

@ -207,7 +207,7 @@ function serveAssetToClient (claimId, name, res) {
.then(fileInfo => {
logger.debug('fileInfo:', fileInfo);
if (fileInfo === NO_FILE) {
return res.status(307).json({status: 'success', message: 'resource temporarily unavailable'});
res.status(307).redirect(`/api/get_claim/${name}/${claimId}`);
} else {
return serveHelpers.serveFile(fileInfo, claimId, name, res);
}

View file

@ -49,8 +49,8 @@
failureMessage.innerText = msg;
},
checkClaimAvailability: function (claimName, claimId) {
console.log(`getting ${claimName}#${claimId}}`)
var uri = `/api/local/${claimName}/${claimId}`;
console.log(`getting ${claimName}#${claimId}`)
var uri = `/api/check_local_claim/${claimName}/${claimId}`;
var xhr = new XMLHttpRequest();
var that = this;
xhr.open("GET", uri, true);
@ -77,8 +77,8 @@
xhr.send();
},
getAsset: function(claimName, claimId) {
console.log(`getting ${claimName}#${claimId}}`)
var uri = `/api/get/${claimName}/${claimId}`;
console.log(`getting ${claimName}#${claimId}`)
var uri = `/api/get_claim/${claimName}/${claimId}`;
var xhr = new XMLHttpRequest();
var that = this;
xhr.open("GET", uri, true);
@ -90,7 +90,7 @@
that.showAsset();
} else {
console.log('get failed:', response);
that.showFailureMessage('Hmmm, looks like no peers have your content. How anti-social!');
that.showFailureMessage(`${response.message}`);
}
} else {
console.log('xhr.readyState', xhr.readyState);