updated /all route and getTopFreeClaim
This commit is contained in:
parent
5b87c53aa3
commit
cddd7ac3b2
3 changed files with 17 additions and 10 deletions
|
@ -34,20 +34,22 @@ function formatGetResultsToFileInfo ({ name, claim_id, outpoint, file_name, down
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAssetByClaimId (fullClaimId, name) {
|
function getAssetByClaimId (fullClaimId, name) {
|
||||||
|
logger.debug('...getting asset by claim Id...');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 1. check locally for claim
|
// 1. check locally for claim
|
||||||
checkForLocalAssetByClaimId(fullClaimId, name)
|
checkForLocalAssetByClaimId(fullClaimId, name)
|
||||||
.then(dataValues => {
|
.then(dataValues => {
|
||||||
// 2. if a result was found, return the result
|
// 2. if a result was found, return the result
|
||||||
if (dataValues) {
|
if (dataValues) {
|
||||||
logger.debug('found a local file for this claimId');
|
logger.debug('found a local file for this name and claimId');
|
||||||
resolve(dataValues);
|
resolve(dataValues);
|
||||||
// 2. if not found locally, make a get request
|
// 2. if not found locally, make a get request
|
||||||
} else {
|
} else {
|
||||||
logger.debug('no local file for this claimId');
|
logger.debug('no local file for this name and claimId');
|
||||||
// 3. resolve the claim
|
// 3. resolve the claim
|
||||||
lbryApi.resolveUri(`${name}#${fullClaimId}`)
|
lbryApi.resolveUri(`${name}#${fullClaimId}`) // USE A LOCAL RESOLVE HERE
|
||||||
.then(resolveResult => {
|
.then(resolveResult => {
|
||||||
|
logger.debug('resolve result >> ', resolveResult);
|
||||||
// if the claim is free...
|
// if the claim is free...
|
||||||
if (resolveResult.claim && isFreeClaim(resolveResult.claim)) {
|
if (resolveResult.claim && isFreeClaim(resolveResult.claim)) {
|
||||||
// get the claim
|
// get the claim
|
||||||
|
@ -83,19 +85,22 @@ function getAssetByClaimId (fullClaimId, name) {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAssetByChannel (channelName, name) {
|
getAssetByChannel (channelName, name) {
|
||||||
|
logger.debug('...getting asset by channel...');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// temporarily throw error
|
// temporarily throw error
|
||||||
reject(new Error('channel names are not currently supported'));
|
reject(new Error('channel names are not currently supported'));
|
||||||
// get the claim id
|
// get the claim id
|
||||||
// get teh asset by claim Id
|
// get the asset by claim Id
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getAssetByShortId: function (shortId, name) {
|
getAssetByShortId: function (shortId, name) {
|
||||||
|
logger.debug('...getting asset by short id...');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// get the full claimId
|
// get the full claimId
|
||||||
getFullClaimIdFromShortId(shortId, name)
|
getFullClaimIdFromShortId(shortId, name)
|
||||||
// get the asset by the claimId
|
// get the asset by the claimId
|
||||||
.then(claimId => {
|
.then(claimId => {
|
||||||
|
logger.debug('claim id =', claimId);
|
||||||
resolve(getAssetByClaimId(claimId, name));
|
resolve(getAssetByClaimId(claimId, name));
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -107,17 +112,19 @@ module.exports = {
|
||||||
return getAssetByClaimId(fullClaimId, name);
|
return getAssetByClaimId(fullClaimId, name);
|
||||||
},
|
},
|
||||||
getAssetByName (name) {
|
getAssetByName (name) {
|
||||||
|
logger.debug('...getting asset by claim name...');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 1. get a list of the free public claims
|
// 1. get a list of the free public claims
|
||||||
getTopFreeClaim(name)
|
getTopFreeClaim(name)
|
||||||
// 2. check locally for the top claim
|
// 2. check locally for the top claim
|
||||||
.then(freePublicClaimList => {
|
.then(topFreeClaim => {
|
||||||
// if no claims were found, return null
|
// if no claims were found, return null
|
||||||
if (!freePublicClaimList) {
|
if (!topFreeClaim) {
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
// parse the result
|
// parse the result
|
||||||
const claimId = freePublicClaimList[0].claimId;
|
const claimId = topFreeClaim.claimId;
|
||||||
|
logger.debug('top free claim id =', claimId);
|
||||||
// get the asset
|
// get the asset
|
||||||
resolve(getAssetByClaimId(claimId, name));
|
resolve(getAssetByClaimId(claimId, name));
|
||||||
})
|
})
|
||||||
|
|
|
@ -151,7 +151,7 @@ module.exports = {
|
||||||
case 0:
|
case 0:
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
default:
|
default:
|
||||||
return resolve(result);
|
return resolve(result[0]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
<p>These are all the free, public assets at that claim. You can publish more at <a href="/">spee.ch</a>.</p>
|
<p>These are all the free, public assets at that claim. You can publish more at <a href="/">spee.ch</a>.</p>
|
||||||
{{#each claims}}
|
{{#each claims}}
|
||||||
<div class="all-claims-item">
|
<div class="all-claims-item">
|
||||||
<img class="all-claims-img" src="/{{this.claim_id}}/{{this.name}}.test" />
|
<img class="all-claims-img" src="/{{this.claimId}}/{{this.name}}.test" />
|
||||||
<div class="all-claims-details">
|
<div class="all-claims-details">
|
||||||
<ul style="list-style-type:none">
|
<ul style="list-style-type:none">
|
||||||
<li>claim: {{this.name}}</li>
|
<li>claim: {{this.name}}</li>
|
||||||
<li>claim_id: {{this.claim_id}}</li>
|
<li>claim_id: {{this.claim_id}}</li>
|
||||||
<li>link: <a href="/{{this.claim_id}}/{{this.name}}">spee.ch/{{this.name}}/{{this.claim_id}}</a></li>
|
<li>link: <a href="/{{this.claimId}}/{{this.name}}">spee.ch/{{this.name}}/{{this.claimId}}</a></li>
|
||||||
<li>author: {{this.value.stream.metadata.author}}</li>
|
<li>author: {{this.value.stream.metadata.author}}</li>
|
||||||
<li>description: {{this.value.stream.metadata.description}}</li>
|
<li>description: {{this.value.stream.metadata.description}}</li>
|
||||||
<li>license: {{this.value.stream.metadata.license}}</li>
|
<li>license: {{this.value.stream.metadata.license}}</li>
|
||||||
|
|
Loading…
Add table
Reference in a new issue