added patch for recently-published, not-yet-mined short urls
This commit is contained in:
parent
1ed55a3a92
commit
4c8157e38e
4 changed files with 72 additions and 21 deletions
|
@ -36,6 +36,29 @@ function determineShortUrl (claimId, claimList) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkLocalDbForClaims (name, shortUrl) {
|
||||||
|
return db.File
|
||||||
|
.findAll({
|
||||||
|
where: {
|
||||||
|
name,
|
||||||
|
claimId: { $like: `${shortUrl}%` },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(records => {
|
||||||
|
logger.debug('number of local search results:', records.length);
|
||||||
|
if (records.length === 0) {
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
const localClaims = records.map(record => { // format the data to match what lbry daemon would have returned
|
||||||
|
return { name: record.dataValues.name, claim_id: record.dataValues.claimId, height: record.dataValues.height };
|
||||||
|
});
|
||||||
|
return localClaims;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
return error;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getClaimAndUpdate (uri, address, height) {
|
function getClaimAndUpdate (uri, address, height) {
|
||||||
// 1. get the claim
|
// 1. get the claim
|
||||||
lbryApi
|
lbryApi
|
||||||
|
@ -100,8 +123,19 @@ module.exports = {
|
||||||
},
|
},
|
||||||
getClaimIdByShortUrl (name, shortUrl) {
|
getClaimIdByShortUrl (name, shortUrl) {
|
||||||
const deferred = new Promise((resolve, reject) => {
|
const deferred = new Promise((resolve, reject) => {
|
||||||
lbryApi.getClaimsList(name)
|
lbryApi.getClaimsList(name) // use the daemon to check for claims list
|
||||||
.then(({ claims }) => {
|
.then(({ claims }) => { // if no claims were found, check locally for possible claims
|
||||||
|
logger.debug('Number of claims from getClaimsList:', claims.length);
|
||||||
|
if (claims.length === 0) {
|
||||||
|
logger.debug('no claims found with getClaimsList');
|
||||||
|
return checkLocalDbForClaims(name, shortUrl);
|
||||||
|
} else {
|
||||||
|
logger.debug('claims were found by getClaimsList');
|
||||||
|
return claims;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(claims => { // handle the claims list
|
||||||
|
logger.debug('Claims ready for filtering:', claims);
|
||||||
const regex = new RegExp(`^${shortUrl}`);
|
const regex = new RegExp(`^${shortUrl}`);
|
||||||
logger.debug('regex:', regex);
|
logger.debug('regex:', regex);
|
||||||
const filteredClaimsList = claims.filter(claim => {
|
const filteredClaimsList = claims.filter(claim => {
|
||||||
|
|
|
@ -92,7 +92,7 @@ h4 {
|
||||||
/* other */
|
/* other */
|
||||||
|
|
||||||
.asset-small {
|
.asset-small {
|
||||||
height: 200px;
|
width: 30%;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
float: left;
|
float: left;
|
||||||
|
|
17
speech.js
17
speech.js
|
@ -70,8 +70,21 @@ const hbs = expressHandlebars.create({
|
||||||
return options.inverse(this);
|
return options.inverse(this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
firstCharacter (word) {
|
grouped_each (every, context, options) {
|
||||||
return word.substring(0, 1);
|
let out = '';
|
||||||
|
let subcontext = [];
|
||||||
|
let i;
|
||||||
|
if (context && context.length > 0) {
|
||||||
|
for (i = 0; i < context.length; i++) {
|
||||||
|
if (i > 0 && i % every === 0) {
|
||||||
|
out += options.fn(subcontext);
|
||||||
|
subcontext = [];
|
||||||
|
}
|
||||||
|
subcontext.push(context[i]);
|
||||||
|
}
|
||||||
|
out += options.fn(subcontext);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<div class="full">
|
<div class="full">
|
||||||
<h2>Trending</h2>
|
<h2>Trending</h2>
|
||||||
{{#each trendingAssets}}
|
{{#grouped_each 3 trendingAssets}}
|
||||||
|
<div>
|
||||||
|
{{#each this}}
|
||||||
{{#if this.nsfw}}
|
{{#if this.nsfw}}
|
||||||
{{else }}
|
{{else }}
|
||||||
<a href="/show/{{this.name}}/{{this.claimId}}">
|
<a href="/show/{{this.name}}/{{this.claimId}}">
|
||||||
|
@ -16,4 +18,6 @@
|
||||||
</a>
|
</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
</div>
|
||||||
|
{{/grouped_each}}
|
||||||
</div>
|
</div>
|
Loading…
Reference in a new issue