finished /name routes

This commit is contained in:
bill bittner 2017-08-03 11:46:56 -07:00
parent 8edd2e278e
commit 6945e3943a
4 changed files with 23 additions and 61 deletions

View file

@ -5,12 +5,6 @@ const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicCla
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
const serveHelpers = require('../helpers/serveHelpers.js');
// function checkForLocalAssetByShortUrl (shortUrl, name) {
// }
// function checkForLocalAssetByChannel (channelName, name) {
// }
function checkForLocalAssetByClaimId (claimId, name) {
return new Promise((resolve, reject) => {
db.File
@ -115,46 +109,19 @@ module.exports = {
},
getAssetByName (name) {
return new Promise((resolve, reject) => {
// temporarily throw error
reject(new Error('get by name is not currently supported'));
// get the claim id
// get teh asset by claim Id
});
},
serveClaimByName (claimName) {
return new Promise((resolve, reject) => {
// 1. get the top free, public claims
getAllFreePublicClaims(claimName)
// 1. get a list of the free public claims
getAllFreePublicClaims(name)
// 2. check locally for the top claim
.then(freePublicClaimList => {
// check to make sure some claims were found
// if no claims were found, return null
if (!freePublicClaimList) {
resolve(null);
return;
}
const name = freePublicClaimList[0].name;
// parse the result
const claimId = freePublicClaimList[0].claim_id;
const uri = `${name}#${claimId}`;
const height = freePublicClaimList[0].height;
const address = freePublicClaimList[0].address;
// 2. check to see if the file is available locally
db.File
.findOne({ where: { name, claimId } })
.then(claim => {
// 3. if a matching record is found locally, serve it
if (claim) {
// serve the file
resolve(claim.dataValues);
// trigger update if needed
serveHelpers.updateFileIfNeeded(uri, claim.dataValues.outpoint, claim.dataValues.height);
// 3. otherwise use daemon to retrieve it
} else {
// get the claim and serve it
serveHelpers.getClaimAndHandleResponse(uri, address, height, resolve, reject);
}
})
.catch(error => {
reject(error);
});
// get the asset
resolve(getAssetByClaimId(claimId, name));
})
.catch(error => {
reject(error);

View file

@ -3,7 +3,7 @@ const logger = require('winston');
module.exports = {
getWalletList () {
logger.debug('getting wallet list');
logger.debug('lbryApi >> getting wallet list');
return new Promise((resolve, reject) => {
axios
.post('http://localhost:5279/lbryapi', {
@ -19,7 +19,7 @@ module.exports = {
});
},
publishClaim (publishParams) {
logger.debug(`Publishing claim to "${publishParams.name}"`);
logger.debug(`lbryApi >> Publishing claim to "${publishParams.name}"`);
return new Promise((resolve, reject) => {
axios
.post('http://localhost:5279/lbryapi', {
@ -36,7 +36,7 @@ module.exports = {
});
},
getClaim (uri) {
logger.debug(`Getting Claim for "${uri}"`);
logger.debug(`lbryApi >> Getting Claim for "${uri}"`);
return new Promise((resolve, reject) => {
axios
.post('http://localhost:5279/lbryapi', {
@ -57,13 +57,12 @@ module.exports = {
resolve(data.result);
})
.catch(error => {
logger.debug("axios.post 'get' error");
reject(error);
});
});
},
getClaimsList (claimName) {
logger.debug(`Getting Claim List for "${claimName}"`);
logger.debug(`lbryApi >> Getting Claim List for "${claimName}"`);
return new Promise((resolve, reject) => {
axios
.post('http://localhost:5279/lbryapi', {
@ -79,7 +78,7 @@ module.exports = {
});
},
resolveUri (uri) {
logger.debug(`Resolving URI for "${uri}"`);
logger.debug(`lbryApi >> Resolving URI for "${uri}"`);
return new Promise((resolve, reject) => {
axios
.post('http://localhost:5279/lbryapi', {
@ -99,7 +98,7 @@ module.exports = {
});
},
getDownloadDirectory () {
logger.debug('Retrieving the download directory path from lbry daemon...');
logger.debug('lbryApi >> Retrieving the download directory path from lbry daemon...');
return new Promise((resolve, reject) => {
axios
.post('http://localhost:5279/lbryapi', {

View file

@ -3,8 +3,6 @@ const db = require('../models');
const lbryApi = require('./lbryApi');
function determineShortUrl (claimId, claimList) {
console.log('claimid =', claimId);
console.log('claimlist = ', claimList);
logger.debug('determining short url based on claim id and claim list');
const thisClaim = claimList.filter(claim => { // find this claim in the list & store it
return claim.claim_id === claimId;

View file

@ -123,7 +123,6 @@ module.exports = (app) => {
// if asset was retrieved from lbrynet, create db record
})
.catch(error => {
console.log('...error was caught');
handleRequestError('serve', originalUrl, ip, error, res);
});
});
@ -166,7 +165,6 @@ module.exports = (app) => {
// if asset was retrieved from lbrynet, create db record
})
.catch(error => {
console.log('...error was caught');
handleRequestError('serve', originalUrl, ip, error, res);
});
});