added patch for recently-published, not-yet-mined short urls

This commit is contained in:
bill bittner 2017-07-20 10:15:20 -07:00
parent 1ed55a3a92
commit 4c8157e38e
4 changed files with 72 additions and 21 deletions

View file

@ -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) {
// 1. get the claim
lbryApi
@ -100,8 +123,19 @@ module.exports = {
},
getClaimIdByShortUrl (name, shortUrl) {
const deferred = new Promise((resolve, reject) => {
lbryApi.getClaimsList(name)
.then(({ claims }) => {
lbryApi.getClaimsList(name) // use the daemon to check for claims list
.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}`);
logger.debug('regex:', regex);
const filteredClaimsList = claims.filter(claim => {

View file

@ -92,7 +92,7 @@ h4 {
/* other */
.asset-small {
height: 200px;
width: 30%;
padding: 0px;
margin: 10px;
float: left;

View file

@ -70,8 +70,21 @@ const hbs = expressHandlebars.create({
return options.inverse(this);
}
},
firstCharacter (word) {
return word.substring(0, 1);
grouped_each (every, context, options) {
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;
},
},
});

View file

@ -1,19 +1,23 @@
<div class="full">
<h2>Trending</h2>
{{#each trendingAssets}}
{{#if this.nsfw}}
{{else }}
<a href="/show/{{this.name}}/{{this.claimId}}">
{{#ifConditional this.fileType '===' 'video/mp4'}}
<video class="asset-small" controls>
<source src="/api/streamFile/{{this.fileName}}">
{{!--fallback--}}
Your browser does not support the <code>video</code> element.
</video>
{{else}}
<img class="asset-small" src="/api/streamFile/{{this.fileName}}" />
{{/ifConditional}}
</a>
{{/if}}
{{/each}}
{{#grouped_each 3 trendingAssets}}
<div>
{{#each this}}
{{#if this.nsfw}}
{{else }}
<a href="/show/{{this.name}}/{{this.claimId}}">
{{#ifConditional this.fileType '===' 'video/mp4'}}
<video class="asset-small" controls>
<source src="/api/streamFile/{{this.fileName}}">
{{!--fallback--}}
Your browser does not support the <code>video</code> element.
</video>
{{else}}
<img class="asset-small" src="/api/streamFile/{{this.fileName}}" />
{{/ifConditional}}
</a>
{{/if}}
{{/each}}
</div>
{{/grouped_each}}
</div>