diff --git a/app/helpers/lbrytv-sdk.js b/app/helpers/lbrytv-sdk.js
index d7c0ab8..5fdfca1 100644
--- a/app/helpers/lbrytv-sdk.js
+++ b/app/helpers/lbrytv-sdk.js
@@ -37,7 +37,7 @@ let resolve = function(urls) {
return reject("DAEMON ERROR: resolve");
}
- if (Object.prototype.hasOwnProperty.call(daemonResponse,"error")) {
+ if (Object.prototype.hasOwnProperty.call(daemonResponse, "error")) {
messageSlack({
message: "```" + daemonResponse.error + "```",
title: "DAEMON ERROR: resolve"
@@ -51,7 +51,64 @@ let resolve = function(urls) {
};
let getTrending = function() {
- return;
+ return new Promise(function(resolve, reject) {
+ let options = {
+ method: "POST",
+ url: "https://api.lbry.tv/api/proxy",
+ headers:
+ {
+ "Content-Type": "application/json"
+ },
+ body:
+ {
+ method: "claim_search",
+ params:
+ {
+ page_size: 20,
+ page: 1,
+ no_totals: true,
+ any_tags:
+ ["art",
+ "automotive",
+ "blockchain",
+ "comedy",
+ "economics",
+ "education",
+ "gaming",
+ "music",
+ "news",
+ "science",
+ "sports",
+ "technology"],
+ channel_ids: [],
+ not_channel_ids: [],
+ not_tags: ["porn", "nsfw", "mature", "xxx"],
+ order_by: ["trending_global", "trending_mixed"]
+ }
+ },
+ json: true
+ };
+
+ request(options, function(error, response, daemonResponse) {
+ if (error) {
+ messageSlack({
+ message: "```" + error + "```",
+ title: "DAEMON ERROR: trending"
+ });
+ return reject("DAEMON ERROR: trending");
+ }
+
+ if (Object.prototype.hasOwnProperty.call(daemonResponse, "error")) {
+ messageSlack({
+ message: "```" + daemonResponse.error + "```",
+ title: "DAEMON ERROR: trending"
+ });
+ return reject("DAEMON ERROR: trending");
+ } else
+ return resolve(daemonResponse.result.items);
+
+ });
+ });
};
export default {
diff --git a/app/sockets.js b/app/sockets.js
index 1b4cb54..847e70c 100644
--- a/app/sockets.js
+++ b/app/sockets.js
@@ -118,66 +118,54 @@ export default async(socket, action) => {
function generateContent(exampleNumber, displayTrendingContent) {
if (exampleNumber === 1) {
- return getTrendingContent()
+ return lbrytvAPI.getTrending()
.then(response => {
- if (!response || !response.success || response.success !== true || !response.data)
- return "";
-
- const rawContentCollection = [];
const renderedContentCollection = [];
- const trendingContentData = response.data;
+ const urlsToResolve = [];
- for (const data of trendingContentData) {
- rawContentCollection.push(fetchMetadata({
- claim: data.url,
- example: exampleNumber,
- method: "resolve"
- }));
- }
+ response.forEach(r =>{
+ urlsToResolve.push(r.canonical_url);
+ });
+ lbrytvAPI.resolve(urlsToResolve)
+ .then(resolveResponse => {
+ if (resolveResponse !== null) {
+ let responses = Object.values(resolveResponse);
- Promise.all(rawContentCollection)
- .then(collection => {
- for (const part of collection) {
- if (part && part.value.tags && part.value.tags.includes("mature"))
- continue;
- if (part === undefined)
- continue;
- try {
- renderedContentCollection.push(`
-