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");
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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(`
|
||||
<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>
|
||||
for (let r in responses) {
|
||||
let part = responses[r];
|
||||
|
||||
<div class="media__title">
|
||||
${part.value.title}
|
||||
</div>
|
||||
|
||||
<div class="media__subtitle">
|
||||
${part.signing_channel ? part.signing_channel.name : "Anon"}
|
||||
</div>
|
||||
</section>
|
||||
`);
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
return; // TODO: Return nice error message
|
||||
if (part.value && part.value.thumbnail.url) {
|
||||
renderedContentCollection.push(`
|
||||
<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__title">
|
||||
${part.value.title || "Untitled"}
|
||||
</div>
|
||||
|
||||
<div class="media__subtitle">
|
||||
${part.signing_channel ? part.signing_channel.name : "Anon"}
|
||||
</div>
|
||||
</section>
|
||||
`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderedContentCollection.push(`
|
||||
<script>
|
||||
document.getElementById("playground-example-description").innerHTML = document.querySelector("[data-action='playground, example 1']").dataset.description
|
||||
</script>
|
||||
`);
|
||||
|
||||
<script>
|
||||
document.getElementById("playground-example-description").innerHTML = document.querySelector("[data-action='playground, example 1']").dataset.description
|
||||
</script>
|
||||
`);
|
||||
displayTrendingContent(renderedContentCollection.join(""));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -199,7 +187,7 @@ function generateContent(exampleNumber, displayTrendingContent) {
|
|||
|
||||
lbrytvAPI.resolve(approvedUrls)
|
||||
.then(resolveResponse => {
|
||||
if (resolveResponse != null) {
|
||||
if (resolveResponse !== null) {
|
||||
let responses = Object.values(resolveResponse);
|
||||
|
||||
for (let r in responses) {
|
||||
|
@ -217,11 +205,11 @@ function generateContent(exampleNumber, displayTrendingContent) {
|
|||
</figure>
|
||||
|
||||
<div class="media__title">
|
||||
${part.value.title}
|
||||
${part.value.title || "Untitled"}
|
||||
</div>
|
||||
|
||||
<div class="media__subtitle">
|
||||
${part.signing_channel.name || "Anon"}
|
||||
${part.signing_channel ? part.signing_channel.name : "Anon"}
|
||||
</div>
|
||||
</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) {
|
||||
if (!url || !url.length)
|
||||
return url;
|
||||
|
|
Loading…
Reference in a new issue