lbry.tech/app/helpers/lbrytv-sdk.js
Niko Storni 6ae0984edf add trending call
use new resolve and trending
remove old trending func
2019-09-23 19:42:21 +02:00

119 lines
2.8 KiB
JavaScript

"use strict";
const request = require("request");
import messageSlack from "./slack";
let addSupport = function() {
return;
};
let publish = function() {
return;
};
let resolve = function(urls) {
return new Promise(function(resolve, reject) {
let options = {
method: "POST",
url: "https://api.lbry.tv/api/proxy",
headers:
{
"Content-Type": "application/json"
},
body: {
method: "resolve",
params: { urls: urls }
},
json: true
};
request(options, function(error, response, daemonResponse) {
if (error) {
messageSlack({
message: "```" + error + "```",
title: "DAEMON ERROR: resolve"
});
return reject("DAEMON ERROR: resolve");
}
if (Object.prototype.hasOwnProperty.call(daemonResponse, "error")) {
messageSlack({
message: "```" + daemonResponse.error + "```",
title: "DAEMON ERROR: resolve"
});
return reject("DAEMON ERROR: resolve");
} else
return resolve(daemonResponse.result);
});
});
};
let getTrending = function() {
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 {
addSupport,
publish,
resolve,
getTrending
};