port resolve call to lbrytv
This commit is contained in:
parent
777d9f0f83
commit
d5932ce67c
4 changed files with 139 additions and 75 deletions
62
app/helpers/lbrytv-sdk.js
Normal file
62
app/helpers/lbrytv-sdk.js
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
"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;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
addSupport,
|
||||||
|
publish,
|
||||||
|
resolve,
|
||||||
|
getTrending
|
||||||
|
};
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
// P A C K A G E S
|
// P A C K A G E S
|
||||||
|
|
||||||
import color from "colorette";
|
import * as color from "colorette";
|
||||||
import compress from "fastify-compress";
|
import compress from "fastify-compress";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import fastify from "fastify";
|
import fastify from "fastify";
|
||||||
|
|
147
app/sockets.js
147
app/sockets.js
|
@ -11,6 +11,7 @@ import html from "choo/html";
|
||||||
|
|
||||||
import apiPage from "~view/api";
|
import apiPage from "~view/api";
|
||||||
import fetchMetadata from "~helper/fetch-metadata";
|
import fetchMetadata from "~helper/fetch-metadata";
|
||||||
|
import lbrytvAPI from "~helper/lbrytv-sdk";
|
||||||
import { generateGitHubFeed } from "~helper/github";
|
import { generateGitHubFeed } from "~helper/github";
|
||||||
import messageSlack from "~helper/slack";
|
import messageSlack from "~helper/slack";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
|
@ -117,31 +118,32 @@ export default async(socket, action) => {
|
||||||
|
|
||||||
function generateContent(exampleNumber, displayTrendingContent) {
|
function generateContent(exampleNumber, displayTrendingContent) {
|
||||||
if (exampleNumber === 1) {
|
if (exampleNumber === 1) {
|
||||||
return getTrendingContent().then(response => {
|
return getTrendingContent()
|
||||||
if (!response || !response.success || response.success !== true || !response.data)
|
.then(response => {
|
||||||
return "";
|
if (!response || !response.success || response.success !== true || !response.data)
|
||||||
|
return "";
|
||||||
|
|
||||||
const rawContentCollection = [];
|
const rawContentCollection = [];
|
||||||
const renderedContentCollection = [];
|
const renderedContentCollection = [];
|
||||||
const trendingContentData = response.data;
|
const trendingContentData = response.data;
|
||||||
|
|
||||||
for (const data of trendingContentData) {
|
for (const data of trendingContentData) {
|
||||||
rawContentCollection.push(fetchMetadata({
|
rawContentCollection.push(fetchMetadata({
|
||||||
claim: data.url,
|
claim: data.url,
|
||||||
example: exampleNumber,
|
example: exampleNumber,
|
||||||
method: "resolve"
|
method: "resolve"
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(rawContentCollection)
|
Promise.all(rawContentCollection)
|
||||||
.then(collection => {
|
.then(collection => {
|
||||||
for (const part of collection) {
|
for (const part of collection) {
|
||||||
if (part && part.value.tags && part.value.tags.includes("mature"))
|
if (part && part.value.tags && part.value.tags.includes("mature"))
|
||||||
continue;
|
continue;
|
||||||
if (part === undefined)
|
if (part === undefined)
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
renderedContentCollection.push(`
|
renderedContentCollection.push(`
|
||||||
<section class="playground-content__trend">
|
<section class="playground-content__trend">
|
||||||
<figure
|
<figure
|
||||||
class="media__thumb"
|
class="media__thumb"
|
||||||
|
@ -159,25 +161,25 @@ function generateContent(exampleNumber, displayTrendingContent) {
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
`);
|
`);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return; // TODO: Return nice error message
|
return; // TODO: Return nice error message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exampleNumber === 3) {
|
if (exampleNumber === 3) {
|
||||||
|
@ -193,50 +195,49 @@ function generateContent(exampleNumber, displayTrendingContent) {
|
||||||
"minecraft-in-real-life-iron-man#758dd6497cdfc401ae1f25984738d024d47b50af",
|
"minecraft-in-real-life-iron-man#758dd6497cdfc401ae1f25984738d024d47b50af",
|
||||||
"ethan-shows-kyle-warframe-skyvault#8a7401b88d5ed0376d98f16808194d4dcb05b284"
|
"ethan-shows-kyle-warframe-skyvault#8a7401b88d5ed0376d98f16808194d4dcb05b284"
|
||||||
];
|
];
|
||||||
|
|
||||||
const rawContentCollection = [];
|
|
||||||
const renderedContentCollection = [];
|
const renderedContentCollection = [];
|
||||||
|
|
||||||
for (const url of approvedUrls)
|
lbrytvAPI.resolve(approvedUrls)
|
||||||
rawContentCollection.push(fetchMetadata({ claim: url, method: "resolve", example: 1 }));
|
.then(resolveResponse => {
|
||||||
|
if (resolveResponse != null) {
|
||||||
|
let responses = Object.values(resolveResponse);
|
||||||
|
|
||||||
return Promise.all(rawContentCollection).then(collection => {
|
for (let r in responses) {
|
||||||
for (const part of collection) {
|
let part = responses[r];
|
||||||
if (
|
|
||||||
part &&
|
|
||||||
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">
|
if (part.value && part.value.thumbnail.url) {
|
||||||
${part.value.title}
|
renderedContentCollection.push(`
|
||||||
</div>
|
<section class="playground-content__trend">
|
||||||
|
<figure
|
||||||
<div class="media__subtitle">
|
class="media__thumb"
|
||||||
${part.signing_channel.name || "Anon"}
|
data-action="choose claim"
|
||||||
</div>
|
data-claim-id="${part.claim_id}"
|
||||||
</section>
|
data-name=${part.name}
|
||||||
`);
|
style="background-image: url(${makeImageSourceSecure(part.value.thumbnail.url)})">
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<div class="media__title">
|
||||||
|
${part.value.title}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="media__subtitle">
|
||||||
|
${part.signing_channel.name || "Anon"}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
renderedContentCollection.push(`
|
||||||
|
<script>
|
||||||
renderedContentCollection.push(`
|
document.getElementById("playground-example-description").innerHTML = document.querySelector("[data-action='playground, example 3']").dataset.description
|
||||||
<script>
|
</script>
|
||||||
document.getElementById("playground-example-description").innerHTML = document.querySelector("[data-action='playground, example 3']").dataset.description
|
`);
|
||||||
</script>
|
displayTrendingContent(renderedContentCollection.join(""));
|
||||||
`);
|
})
|
||||||
|
.catch(error => {
|
||||||
displayTrendingContent(renderedContentCollection.join(""));
|
console.error(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,8 @@
|
||||||
"redis": "^2.8.0",
|
"redis": "^2.8.0",
|
||||||
"slack-node": "^0.1.8",
|
"slack-node": "^0.1.8",
|
||||||
"socket.io": "^2.2.0",
|
"socket.io": "^2.2.0",
|
||||||
"stringify-object": "^3.3.0"
|
"stringify-object": "^3.3.0",
|
||||||
|
"request": "latest"
|
||||||
},
|
},
|
||||||
"description": "Documentation for the LBRY protocol and associated projects",
|
"description": "Documentation for the LBRY protocol and associated projects",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue