finished /name routes
This commit is contained in:
parent
8edd2e278e
commit
6945e3943a
4 changed files with 23 additions and 61 deletions
|
@ -5,12 +5,6 @@ const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicCla
|
||||||
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
|
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
|
||||||
const serveHelpers = require('../helpers/serveHelpers.js');
|
const serveHelpers = require('../helpers/serveHelpers.js');
|
||||||
|
|
||||||
// function checkForLocalAssetByShortUrl (shortUrl, name) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// function checkForLocalAssetByChannel (channelName, name) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
function checkForLocalAssetByClaimId (claimId, name) {
|
function checkForLocalAssetByClaimId (claimId, name) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
db.File
|
db.File
|
||||||
|
@ -115,50 +109,23 @@ module.exports = {
|
||||||
},
|
},
|
||||||
getAssetByName (name) {
|
getAssetByName (name) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// temporarily throw error
|
// 1. get a list of the free public claims
|
||||||
reject(new Error('get by name is not currently supported'));
|
getAllFreePublicClaims(name)
|
||||||
// get the claim id
|
// 2. check locally for the top claim
|
||||||
// get teh asset by claim Id
|
.then(freePublicClaimList => {
|
||||||
});
|
// if no claims were found, return null
|
||||||
},
|
if (!freePublicClaimList) {
|
||||||
serveClaimByName (claimName) {
|
resolve(null);
|
||||||
return new Promise((resolve, reject) => {
|
return;
|
||||||
// 1. get the top free, public claims
|
}
|
||||||
getAllFreePublicClaims(claimName)
|
// parse the result
|
||||||
.then(freePublicClaimList => {
|
const claimId = freePublicClaimList[0].claim_id;
|
||||||
// check to make sure some claims were found
|
// get the asset
|
||||||
if (!freePublicClaimList) {
|
resolve(getAssetByClaimId(claimId, name));
|
||||||
resolve(null);
|
})
|
||||||
return;
|
.catch(error => {
|
||||||
}
|
reject(error);
|
||||||
const name = freePublicClaimList[0].name;
|
});
|
||||||
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);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ const logger = require('winston');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getWalletList () {
|
getWalletList () {
|
||||||
logger.debug('getting wallet list');
|
logger.debug('lbryApi >> getting wallet list');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios
|
axios
|
||||||
.post('http://localhost:5279/lbryapi', {
|
.post('http://localhost:5279/lbryapi', {
|
||||||
|
@ -19,7 +19,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
publishClaim (publishParams) {
|
publishClaim (publishParams) {
|
||||||
logger.debug(`Publishing claim to "${publishParams.name}"`);
|
logger.debug(`lbryApi >> Publishing claim to "${publishParams.name}"`);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios
|
axios
|
||||||
.post('http://localhost:5279/lbryapi', {
|
.post('http://localhost:5279/lbryapi', {
|
||||||
|
@ -36,7 +36,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getClaim (uri) {
|
getClaim (uri) {
|
||||||
logger.debug(`Getting Claim for "${uri}"`);
|
logger.debug(`lbryApi >> Getting Claim for "${uri}"`);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios
|
axios
|
||||||
.post('http://localhost:5279/lbryapi', {
|
.post('http://localhost:5279/lbryapi', {
|
||||||
|
@ -57,13 +57,12 @@ module.exports = {
|
||||||
resolve(data.result);
|
resolve(data.result);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
logger.debug("axios.post 'get' error");
|
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getClaimsList (claimName) {
|
getClaimsList (claimName) {
|
||||||
logger.debug(`Getting Claim List for "${claimName}"`);
|
logger.debug(`lbryApi >> Getting Claim List for "${claimName}"`);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios
|
axios
|
||||||
.post('http://localhost:5279/lbryapi', {
|
.post('http://localhost:5279/lbryapi', {
|
||||||
|
@ -79,7 +78,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
resolveUri (uri) {
|
resolveUri (uri) {
|
||||||
logger.debug(`Resolving URI for "${uri}"`);
|
logger.debug(`lbryApi >> Resolving URI for "${uri}"`);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios
|
axios
|
||||||
.post('http://localhost:5279/lbryapi', {
|
.post('http://localhost:5279/lbryapi', {
|
||||||
|
@ -99,7 +98,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getDownloadDirectory () {
|
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) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios
|
axios
|
||||||
.post('http://localhost:5279/lbryapi', {
|
.post('http://localhost:5279/lbryapi', {
|
||||||
|
|
|
@ -3,8 +3,6 @@ const db = require('../models');
|
||||||
const lbryApi = require('./lbryApi');
|
const lbryApi = require('./lbryApi');
|
||||||
|
|
||||||
function determineShortUrl (claimId, claimList) {
|
function determineShortUrl (claimId, claimList) {
|
||||||
console.log('claimid =', claimId);
|
|
||||||
console.log('claimlist = ', claimList);
|
|
||||||
logger.debug('determining short url based on claim id and claim list');
|
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
|
const thisClaim = claimList.filter(claim => { // find this claim in the list & store it
|
||||||
return claim.claim_id === claimId;
|
return claim.claim_id === claimId;
|
||||||
|
|
|
@ -123,7 +123,6 @@ module.exports = (app) => {
|
||||||
// if asset was retrieved from lbrynet, create db record
|
// if asset was retrieved from lbrynet, create db record
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log('...error was caught');
|
|
||||||
handleRequestError('serve', originalUrl, ip, error, res);
|
handleRequestError('serve', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -166,7 +165,6 @@ module.exports = (app) => {
|
||||||
// if asset was retrieved from lbrynet, create db record
|
// if asset was retrieved from lbrynet, create db record
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log('...error was caught');
|
|
||||||
handleRequestError('serve', originalUrl, ip, error, res);
|
handleRequestError('serve', originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue