add trending call
use new resolve and trending remove old trending func
This commit is contained in:
parent
d5932ce67c
commit
6ae0984edf
2 changed files with 98 additions and 62 deletions
|
@ -37,7 +37,7 @@ let resolve = function(urls) {
|
||||||
return reject("DAEMON ERROR: resolve");
|
return reject("DAEMON ERROR: resolve");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(daemonResponse,"error")) {
|
if (Object.prototype.hasOwnProperty.call(daemonResponse, "error")) {
|
||||||
messageSlack({
|
messageSlack({
|
||||||
message: "```" + daemonResponse.error + "```",
|
message: "```" + daemonResponse.error + "```",
|
||||||
title: "DAEMON ERROR: resolve"
|
title: "DAEMON ERROR: resolve"
|
||||||
|
@ -51,7 +51,64 @@ let resolve = function(urls) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let getTrending = function() {
|
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 {
|
export default {
|
||||||
|
|
|
@ -118,66 +118,54 @@ export default async(socket, action) => {
|
||||||
|
|
||||||
function generateContent(exampleNumber, displayTrendingContent) {
|
function generateContent(exampleNumber, displayTrendingContent) {
|
||||||
if (exampleNumber === 1) {
|
if (exampleNumber === 1) {
|
||||||
return getTrendingContent()
|
return lbrytvAPI.getTrending()
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response || !response.success || response.success !== true || !response.data)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
const rawContentCollection = [];
|
|
||||||
const renderedContentCollection = [];
|
const renderedContentCollection = [];
|
||||||
const trendingContentData = response.data;
|
const urlsToResolve = [];
|
||||||
|
|
||||||
for (const data of trendingContentData) {
|
response.forEach(r =>{
|
||||||
rawContentCollection.push(fetchMetadata({
|
urlsToResolve.push(r.canonical_url);
|
||||||
claim: data.url,
|
});
|
||||||
example: exampleNumber,
|
lbrytvAPI.resolve(urlsToResolve)
|
||||||
method: "resolve"
|
.then(resolveResponse => {
|
||||||
}));
|
if (resolveResponse !== null) {
|
||||||
}
|
let responses = Object.values(resolveResponse);
|
||||||
|
|
||||||
Promise.all(rawContentCollection)
|
for (let r in responses) {
|
||||||
.then(collection => {
|
let part = responses[r];
|
||||||
for (const part of collection) {
|
|
||||||
if (part && part.value.tags && part.value.tags.includes("mature"))
|
|
||||||
continue;
|
|
||||||
if (part === undefined)
|
|
||||||
continue;
|
|
||||||
try {
|
|
||||||
renderedContentCollection.push(`
|
|
||||||
<section class="playground-content__trend">
|
|
||||||
<figure
|
|
||||||
class="media__thumb"
|
|
||||||
data-action="choose claim"
|
|
||||||
data-claim-id="${part.name}"
|
|
||||||
${part.value.thumbnail.url.length ? `style="background-image: url(${makeImageSourceSecure(part.value.thumbnail.url)})"` : ""}
|
|
||||||
></figure>
|
|
||||||
|
|
||||||
<div class="media__title">
|
if (part.value && part.value.thumbnail.url) {
|
||||||
${part.value.title}
|
renderedContentCollection.push(`
|
||||||
</div>
|
<section class="playground-content__trend">
|
||||||
|
<figure
|
||||||
|
class="media__thumb"
|
||||||
|
data-action="choose claim"
|
||||||
|
data-claim-id="${part.claim_id}"
|
||||||
|
data-name=${part.name}
|
||||||
|
style="background-image: url(${makeImageSourceSecure(part.value.thumbnail.url)})">
|
||||||
|
</figure>
|
||||||
|
|
||||||
<div class="media__subtitle">
|
<div class="media__title">
|
||||||
${part.signing_channel ? part.signing_channel.name : "Anon"}
|
${part.value.title || "Untitled"}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
`);
|
<div class="media__subtitle">
|
||||||
} catch(err) {
|
${part.signing_channel ? part.signing_channel.name : "Anon"}
|
||||||
console.error(err);
|
</div>
|
||||||
return; // TODO: Return nice error message
|
</section>
|
||||||
|
`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderedContentCollection.push(`
|
renderedContentCollection.push(`
|
||||||
<script>
|
<script>
|
||||||
document.getElementById("playground-example-description").innerHTML = document.querySelector("[data-action='playground, example 1']").dataset.description
|
document.getElementById("playground-example-description").innerHTML = document.querySelector("[data-action='playground, example 1']").dataset.description
|
||||||
</script>
|
</script>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
displayTrendingContent(renderedContentCollection.join(""));
|
displayTrendingContent(renderedContentCollection.join(""));
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return null;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -199,7 +187,7 @@ function generateContent(exampleNumber, displayTrendingContent) {
|
||||||
|
|
||||||
lbrytvAPI.resolve(approvedUrls)
|
lbrytvAPI.resolve(approvedUrls)
|
||||||
.then(resolveResponse => {
|
.then(resolveResponse => {
|
||||||
if (resolveResponse != null) {
|
if (resolveResponse !== null) {
|
||||||
let responses = Object.values(resolveResponse);
|
let responses = Object.values(resolveResponse);
|
||||||
|
|
||||||
for (let r in responses) {
|
for (let r in responses) {
|
||||||
|
@ -217,11 +205,11 @@ function generateContent(exampleNumber, displayTrendingContent) {
|
||||||
</figure>
|
</figure>
|
||||||
|
|
||||||
<div class="media__title">
|
<div class="media__title">
|
||||||
${part.value.title}
|
${part.value.title || "Untitled"}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="media__subtitle">
|
<div class="media__subtitle">
|
||||||
${part.signing_channel.name || "Anon"}
|
${part.signing_channel ? part.signing_channel.name : "Anon"}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
`);
|
`);
|
||||||
|
@ -378,15 +366,6 @@ function getGitHubUserToken(socket) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTrendingContent() {
|
|
||||||
try {
|
|
||||||
const response = await got("https://api.lbry.com/file/list_trending");
|
|
||||||
return JSON.parse(response.body); // eslint-disable-line padding-line-between-statements
|
|
||||||
} catch(error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeImageSourceSecure(url) {
|
function makeImageSourceSecure(url) {
|
||||||
if (!url || !url.length)
|
if (!url || !url.length)
|
||||||
return url;
|
return url;
|
||||||
|
|
Loading…
Reference in a new issue