From 4c8157e38ef464aa88389fb8a781823d495f496b Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 20 Jul 2017 10:15:20 -0700 Subject: [PATCH] added patch for recently-published, not-yet-mined short urls --- helpers/libraries/serveHelpers.js | 38 ++++++++++++++++++++++-- public/assets/css/generalStyle.css | 2 +- speech.js | 17 +++++++++-- views/partials/trendingAssets.handlebars | 36 ++++++++++++---------- 4 files changed, 72 insertions(+), 21 deletions(-) diff --git a/helpers/libraries/serveHelpers.js b/helpers/libraries/serveHelpers.js index e266c51b..9493862b 100644 --- a/helpers/libraries/serveHelpers.js +++ b/helpers/libraries/serveHelpers.js @@ -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 => { diff --git a/public/assets/css/generalStyle.css b/public/assets/css/generalStyle.css index 71737044..c2b6d894 100644 --- a/public/assets/css/generalStyle.css +++ b/public/assets/css/generalStyle.css @@ -92,7 +92,7 @@ h4 { /* other */ .asset-small { - height: 200px; + width: 30%; padding: 0px; margin: 10px; float: left; diff --git a/speech.js b/speech.js index 0633a23a..717070f6 100644 --- a/speech.js +++ b/speech.js @@ -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; }, }, }); diff --git a/views/partials/trendingAssets.handlebars b/views/partials/trendingAssets.handlebars index 7ce5379a..1b81583f 100644 --- a/views/partials/trendingAssets.handlebars +++ b/views/partials/trendingAssets.handlebars @@ -1,19 +1,23 @@

Trending

- {{#each trendingAssets}} - {{#if this.nsfw}} - {{else }} - - {{#ifConditional this.fileType '===' 'video/mp4'}} - - {{else}} - - {{/ifConditional}} - - {{/if}} - {{/each}} + {{#grouped_each 3 trendingAssets}} +
+ {{#each this}} + {{#if this.nsfw}} + {{else }} + + {{#ifConditional this.fileType '===' 'video/mp4'}} + + {{else}} + + {{/ifConditional}} + + {{/if}} + {{/each}} +
+ {{/grouped_each}}
\ No newline at end of file