Resolves and Tipping work with the new daemon
This commit is contained in:
parent
cf4d8a9349
commit
4625a4367a
11 changed files with 79 additions and 435 deletions
|
@ -40,6 +40,7 @@ module.exports = exports = (data, socket) => {
|
|||
const body = {};
|
||||
const claimAddress = data.claim;
|
||||
const resolveMethod = data.method;
|
||||
let apiRequestMethod = "";
|
||||
|
||||
if (allowedMethods.indexOf(resolveMethod) < 0) return socket.send(JSON.stringify({
|
||||
"details": "Unallowed resolve method for tutorial",
|
||||
|
@ -49,10 +50,12 @@ module.exports = exports = (data, socket) => {
|
|||
|
||||
|
||||
|
||||
body.access_token = process.env.LBRY_DAEMON_ACCESS_TOKEN;
|
||||
body.authorization = process.env.LBRY_DAEMON_ACCESS_TOKEN; // access_token
|
||||
body.method = resolveMethod;
|
||||
|
||||
if (resolveMethod === "publish") {
|
||||
apiRequestMethod = "PUT";
|
||||
|
||||
body.bid = 0.001; // Hardcoded publish amount
|
||||
body.description = dataDetails.description;
|
||||
body.file_path = process.env.LBRY_DAEMON_IMAGES_PATH + dataDetails.file_path; // TODO: Fix the internal image path in daemon (original comment, check to see if still true)
|
||||
|
@ -93,46 +96,64 @@ module.exports = exports = (data, socket) => {
|
|||
});
|
||||
}
|
||||
|
||||
if (resolveMethod === "resolve") body.uri = claimAddress;
|
||||
if (resolveMethod === "resolve") {
|
||||
apiRequestMethod = "GET";
|
||||
body.uri = claimAddress;
|
||||
}
|
||||
|
||||
if (resolveMethod === "wallet_send") {
|
||||
body.amount = "0.001"; // Hardcoded tip amount
|
||||
apiRequestMethod = "POST";
|
||||
|
||||
body.amount = "0.01"; // Hardcoded tip amount
|
||||
body.claim_id = claimAddress;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => { // eslint-disable-line
|
||||
let explorerNotice = "";
|
||||
|
||||
request({
|
||||
url: "http://daemon.lbry.tech",
|
||||
qs: body
|
||||
body: body,
|
||||
json: true,
|
||||
method: apiRequestMethod,
|
||||
url: `${process.env.NODE_ENV === "development" ?
|
||||
`http://localhost:5200/${resolveMethod}` :
|
||||
`http://daemon.lbry.tech/${resolveMethod}`}`
|
||||
}, (error, response, body) => {
|
||||
if (error) {
|
||||
if (process.env.NODE_ENV !== "development") {
|
||||
logSlackError(
|
||||
"\n" +
|
||||
"> *DAEMON ERROR:* ```" + JSON.parse(JSON.stringify(error)) + "```" + "\n" +
|
||||
"> _Cause: Someone is going through the Tour_\n"
|
||||
);
|
||||
}
|
||||
|
||||
return resolve(error);
|
||||
}
|
||||
|
||||
body = JSON.parse(body);
|
||||
|
||||
if (body.error && typeof body.error !== "undefined") {
|
||||
if (process.env.NODE_ENV !== "development") {
|
||||
logSlackError(
|
||||
"\n" +
|
||||
"> *DAEMON ERROR:* ```" + JSON.parse(JSON.stringify(body.error.message)) + "```" + "\n" +
|
||||
"> _Cause: Someone is going through the Tour after a response has been parsed_\n"
|
||||
);
|
||||
}
|
||||
|
||||
return resolve(body.error);
|
||||
}
|
||||
|
||||
if (body.result.txid) explorerNotice = `
|
||||
<p>If you want proof of the tip you just gave, <a href="https://explorer.lbry.io/tx/${body.result.txid}" target="_blank" title="Your tip, on our blockchain explorer" rel="noopener noreferrer">check it out</a> on our blockchain explorer!</p>
|
||||
`;
|
||||
|
||||
if (socket) {
|
||||
const renderedCode = prism.highlight(stringifyObject(body, { indent: " ", singleQuotes: false }), prism.languages.json, "json");
|
||||
|
||||
return socket.send(JSON.stringify({
|
||||
"html": raw(`
|
||||
<h3>Response</h3>
|
||||
${explorerNotice}
|
||||
<pre><code class="language-json">${renderedCode}</code></pre>
|
||||
`),
|
||||
"message": "updated html",
|
||||
|
|
|
@ -125,7 +125,7 @@ function refToBranch(ref) {
|
|||
|
||||
|
||||
|
||||
// E X P O R T
|
||||
// E X P O R T S
|
||||
|
||||
module.exports = exports = {
|
||||
generateEvent,
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
"use strict";
|
||||
|
||||
|
||||
|
||||
// P A C K A G E
|
||||
|
||||
const crypto = require("crypto");
|
||||
|
||||
|
||||
|
||||
// E X P O R T
|
||||
|
||||
module.exports = exports = len => {
|
||||
if (!Number.isFinite(len)) throw new TypeError("Expected a finite number");
|
||||
return crypto.randomBytes(Math.ceil(len / 2)).toString("hex").slice(0, len);
|
||||
|
|
|
@ -49,10 +49,9 @@
|
|||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"choo-devtools": "^2.5.1",
|
||||
"dependency-check": "^3.2.0",
|
||||
"nodemon": "^1.18.3",
|
||||
"npm-run-all": "^4.1.3",
|
||||
"sass": "^1.10.4",
|
||||
"sass": "^1.11.0",
|
||||
"snazzy": "^7.1.1",
|
||||
"standardx": "^2.1.0",
|
||||
"updates": "^4.1.2"
|
||||
|
@ -78,7 +77,7 @@
|
|||
"lint": "standardx --verbose | snazzy",
|
||||
"start": "NODE_ENV=production node server",
|
||||
"test": "run-p test:*",
|
||||
"test:dependencies": "dependency-check ./package.json && updates -u ./",
|
||||
"test:dependencies": "updates -u ./",
|
||||
"test:lint": "standardx --verbose | snazzy",
|
||||
"watch": "run-p watch:*",
|
||||
"watch:sass": "sass --watch sass:public/css --style compressed",
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,395 +0,0 @@
|
|||
.hook {
|
||||
.loader {
|
||||
animation: spin 2s linear infinite;
|
||||
border-radius: 50%;
|
||||
border-style: solid;
|
||||
border-top-color: $teal;
|
||||
|
||||
&:not(.small):not(.tiny) {
|
||||
width: 4rem; height: 4rem;
|
||||
|
||||
border-width: 6px;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
&.small {
|
||||
width: 2rem; height: 2rem;
|
||||
border-width: 3px;
|
||||
}
|
||||
|
||||
&.tiny {
|
||||
width: 1rem; height: 1rem;
|
||||
border-width: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.hook__navigation {
|
||||
background-color: $black;
|
||||
color: $white;
|
||||
font-size: 1rem;
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.hook__navigation__step {
|
||||
background-color: transparent;
|
||||
|
||||
@media (min-width: 501px) {
|
||||
display: inline-block;
|
||||
|
||||
&:not(:last-of-type) {
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
span {
|
||||
width: 3rem; height: 3rem;
|
||||
|
||||
display: block;
|
||||
font-size: 1.25rem;
|
||||
line-height: 3rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 500px) {
|
||||
display: block;
|
||||
|
||||
span {
|
||||
width: 1rem; height: 1rem;
|
||||
|
||||
display: inline-block;
|
||||
font-size: 0.7rem;
|
||||
line-height: 0.9rem;
|
||||
position: relative;
|
||||
top: 2px;
|
||||
vertical-align: top;
|
||||
}
|
||||
}
|
||||
|
||||
&:not(.active) {
|
||||
color: $white;
|
||||
|
||||
span {
|
||||
border-color: rgba($white, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: $teal;
|
||||
|
||||
span {
|
||||
border-color: rgba($teal, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
span {
|
||||
border: 1px solid;
|
||||
border-radius: 50%;
|
||||
margin: 0 auto 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.hook__page {
|
||||
@extend .page__content;
|
||||
}
|
||||
|
||||
.hook__page__hero {
|
||||
margin-bottom: 2rem;
|
||||
border-bottom: 1px solid rgba($black, 0.05);
|
||||
|
||||
h1, p {
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.hook__page__hero__claim,
|
||||
.hook__page__hero__support {
|
||||
margin-bottom: 3rem; padding-left: 1rem;
|
||||
|
||||
background-color: $white;
|
||||
border: 1px solid rgba($gray, 0.7);
|
||||
font-size: 1rem;
|
||||
|
||||
@media (min-width: 501px) {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
&::after {
|
||||
@include clearfix;
|
||||
}
|
||||
|
||||
button, input {
|
||||
line-height: 3rem;
|
||||
}
|
||||
|
||||
span {
|
||||
color: rgba($black, 0.3);
|
||||
}
|
||||
|
||||
button {
|
||||
border-left: 1px solid rgba($gray, 0.7);
|
||||
color: $white;
|
||||
float: right;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
transition: all 0.2s;
|
||||
width: 6rem;
|
||||
|
||||
&::after {
|
||||
width: calc(100% + 2px); height: calc(100% + 2px);
|
||||
top: -1px; left: -1px;
|
||||
|
||||
border: 1px solid;
|
||||
content: "";
|
||||
position: absolute;
|
||||
transition: inherit;
|
||||
}
|
||||
|
||||
&:not(:hover) {
|
||||
background-color: $black;
|
||||
|
||||
&::after {
|
||||
border-color: $black;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: $teal;
|
||||
|
||||
&::after {
|
||||
border-color: $teal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hook__page__hero__claim input {
|
||||
width: calc(100% - 10rem);
|
||||
}
|
||||
|
||||
.hook__page__hero__support {
|
||||
input[type=number] {
|
||||
width: 3rem;
|
||||
}
|
||||
|
||||
input[type=text] {
|
||||
width: calc(100% - 11.5rem);
|
||||
}
|
||||
|
||||
span {
|
||||
line-height: 3rem;
|
||||
}
|
||||
|
||||
a {
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
.hook__page__content::after {
|
||||
@include clearfix;
|
||||
}
|
||||
|
||||
.hook__page__content__card {
|
||||
margin-bottom: 1rem; padding: 1rem;
|
||||
cursor: pointer;
|
||||
|
||||
img {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
@media (min-width: 501px) {
|
||||
float: left;
|
||||
vertical-align: top;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
@media (max-width: 500px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.hook__page__content__meme {
|
||||
margin-bottom: 2rem;
|
||||
padding-right: 1rem;
|
||||
padding-left: 1rem;
|
||||
|
||||
@media (min-width: 701px) {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
canvas {
|
||||
width: 100%; height: 100%;
|
||||
|
||||
background-color: rgba($teal, 0.3);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
h2.__metadata {
|
||||
margin-top: 3rem;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
border: none;
|
||||
|
||||
&:not(:last-of-type) {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
label {
|
||||
color: rgba($black, 0.3);
|
||||
display: block;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.05rem;
|
||||
margin-bottom: 0.025rem;
|
||||
text-transform: uppercase;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
input:not([type="checkbox"]):not([type="submit"]),
|
||||
select,
|
||||
textarea {
|
||||
@media (min-width: 901px) {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
}
|
||||
|
||||
input {
|
||||
&:not([type="checkbox"]):not([type="file"]):not([type="submit"]) {
|
||||
border-bottom: 2px solid;
|
||||
padding-bottom: 0.15rem;
|
||||
transition: all 0.2s;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&:not([type="file"]):not([type="submit"]) {
|
||||
&:not(:hover):not(:active) {
|
||||
border-color: $black;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&:active {
|
||||
border-color: $teal;
|
||||
}
|
||||
}
|
||||
|
||||
&[type="checkbox"] {
|
||||
width: 1.25rem; height: 1.25rem;
|
||||
|
||||
border: 2px solid;
|
||||
margin-right: 0.5rem;
|
||||
position: relative;
|
||||
top: 0.35rem;
|
||||
|
||||
&::after {
|
||||
width: 100%; height: 100%;
|
||||
|
||||
content: "✓";
|
||||
font-size: 1.5rem;
|
||||
line-height: 1rem;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
&:not(:checked)::after {
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
&:checked::after {
|
||||
color: $teal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
select,
|
||||
textarea {
|
||||
border-bottom: 2px solid;
|
||||
width: 100%;
|
||||
|
||||
&:not(:hover):not(:active) {
|
||||
border-color: $black;
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&:active {
|
||||
border-color: $teal;
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
background-image: url("/assets/media/svg/down.svg");
|
||||
background-position: 99% center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 1rem;
|
||||
padding-right: 2rem;
|
||||
}
|
||||
|
||||
textarea {
|
||||
min-height: 100px;
|
||||
resize: vertical;
|
||||
}
|
||||
}
|
||||
|
||||
.hook__page__content__meme__thumbnail {
|
||||
width: 5rem; height: 5rem;
|
||||
|
||||
border-style: solid;
|
||||
border-width: 2px;
|
||||
margin-bottom: 1rem;
|
||||
object-fit: contain;
|
||||
object-position: center;
|
||||
|
||||
&:not(:last-of-type) {
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
&:not(.selected) {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: $black;
|
||||
}
|
||||
}
|
||||
|
||||
.hook__page__content__meme__uploader {
|
||||
@extend .__button-black;
|
||||
text-align: center;
|
||||
width: 11rem;
|
||||
|
||||
> div:first-of-type {
|
||||
width: 100%; height: 100%;
|
||||
top: 0; left: 0;
|
||||
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
input {
|
||||
top: 0; left: 0;
|
||||
bottom: 0; right: 0;
|
||||
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 10;
|
||||
}
|
||||
}
|
|
@ -156,11 +156,9 @@
|
|||
|
||||
|
||||
|
||||
.tour__content__meme {
|
||||
&::after {
|
||||
.tour__content__meme::after {
|
||||
@include clearfix;
|
||||
}
|
||||
}
|
||||
|
||||
.tour__content__meme__canvas {
|
||||
float: left;
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
}
|
||||
|
||||
&.boolean,
|
||||
&.null {
|
||||
&.null,
|
||||
&.url {
|
||||
color: #86c2f7;
|
||||
}
|
||||
|
||||
|
|
15
server.js
15
server.js
|
@ -127,7 +127,6 @@ fastify.ready(err => {
|
|||
generateMemeCreator(socket);
|
||||
break;
|
||||
|
||||
/*
|
||||
case "request for tour, example 3":
|
||||
generateTrendingContent(3, result => {
|
||||
socket.send(JSON.stringify({
|
||||
|
@ -138,7 +137,6 @@ fastify.ready(err => {
|
|||
});
|
||||
|
||||
break;
|
||||
*/
|
||||
|
||||
case "subscribe":
|
||||
newsletterSubscribe(data, socket);
|
||||
|
@ -220,6 +218,19 @@ function generateGitHubFeed(displayGitHubFeed) {
|
|||
}
|
||||
|
||||
function generateMemeCreator(socket) {
|
||||
/*
|
||||
request({
|
||||
body: { authorization: "hi" },
|
||||
json: true,
|
||||
method: "GET",
|
||||
url: `${process.env.NODE_ENV === "development" ? "http://localhost:5200" : "http://daemon.lbry.tech"}`
|
||||
}).then(body => {
|
||||
console.log(body);
|
||||
}).catch(welp => {
|
||||
console.log(welp);
|
||||
});
|
||||
*/
|
||||
|
||||
const images = [
|
||||
{
|
||||
alt: "Carl Sagan",
|
||||
|
|
|
@ -37,13 +37,14 @@ $("body").on("click", "[data-action]", event => {
|
|||
$("#tour-loader").removeClass("tour__content__meme").addClass("tour__content__trends");
|
||||
}
|
||||
|
||||
$("#fetch-claim-uri").val(""); // reset URL bar
|
||||
if ($("#tour-url")[0].style.display === "none") $("#tour-url").show();
|
||||
|
||||
$(".tour__sidebar__example").removeClass("active");
|
||||
$(".tour__sidebar__example:nth-child(1)").addClass("active");
|
||||
|
||||
$("#tour-loader").html("");
|
||||
$("#tour-results").html("");
|
||||
$("#tour-loader").empty().show(); // .html("");
|
||||
$("#tour-results").empty().show(); // .html("");
|
||||
|
||||
send(JSON.stringify({
|
||||
"message": `request for ${data.action}`
|
||||
|
@ -56,13 +57,14 @@ $("body").on("click", "[data-action]", event => {
|
|||
$("#tour-loader").removeClass("tour__content__trends").addClass("tour__content__meme");
|
||||
}
|
||||
|
||||
$("#fetch-claim-uri").val(""); // reset URL bar
|
||||
$("#tour-url").hide();
|
||||
|
||||
$(".tour__sidebar__example").removeClass("active");
|
||||
$(".tour__sidebar__example:nth-child(2)").addClass("active");
|
||||
|
||||
$("#tour-loader").html("");
|
||||
$("#tour-results").html("");
|
||||
$("#tour-loader").empty().show(); // .html("");
|
||||
$("#tour-results").empty().show(); // .html("");
|
||||
|
||||
send(JSON.stringify({
|
||||
"message": `request for ${data.action}`
|
||||
|
@ -75,13 +77,14 @@ $("body").on("click", "[data-action]", event => {
|
|||
$("#tour-loader").removeClass("tour__content__meme").addClass("tour__content__trends");
|
||||
}
|
||||
|
||||
$("#fetch-claim-uri").val(""); // reset URL bar
|
||||
if ($("#tour-url")[0].style.display === "none") $("#tour-url").show();
|
||||
|
||||
$(".tour__sidebar__example").removeClass("active");
|
||||
$(".tour__sidebar__example:nth-child(3)").addClass("active");
|
||||
|
||||
$("#tour-loader").html("");
|
||||
$("#tour-results").html("");
|
||||
$("#tour-loader").empty().show(); // .html("");
|
||||
$("#tour-results").empty().show(); // .html("");
|
||||
|
||||
send(JSON.stringify({
|
||||
"message": `request for ${data.action}`
|
||||
|
@ -167,8 +170,8 @@ function fetchMetadata(exampleNumber, data) {
|
|||
|
||||
$("#tour-results").html(`
|
||||
<pre><code class="language-bash">
|
||||
<span class="token comment"># With the LBRY daemon running locally, you can use this in your Terminal</span>
|
||||
curl --header "Content-Type: application/json" --data '{ "method": "resolve", "params": { "uri": "${data}" }}' http://localhost:5279
|
||||
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
|
||||
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "resolve", "params": { "uri": "${data}" }}'</span> <span class="token url">http://localhost:5279 </span>
|
||||
</code></pre>
|
||||
|
||||
<div class="loader" id="temp-loader"></div>
|
||||
|
@ -200,8 +203,8 @@ curl --header "Content-Type: application/json" --data '{ "method": "resolve", "p
|
|||
|
||||
$("#tour-results").html(`
|
||||
<pre><code class="language-bash">
|
||||
<span class="token comment"># If you have the LBRY desktop app, you can run this in your Terminal</span>
|
||||
curl "http://localhost:5279" --data "{ 'method': 'wallet_send', 'params': { 'claim_id': '${data}', 'amount': '0.01' } }"
|
||||
<span class="token comment"># With the LBRY app/daemon running locally, you can use this in your Terminal</span>
|
||||
curl --header <span class="token string">"Content-Type: application/json"</span> --data <span class="token string">'{ "method": "wallet_send", "params": { "amount": "0.01", "claim_id": "${data}" }}'</span> <span class="token url">http://localhost:5279 </span>
|
||||
</code></pre>
|
||||
|
||||
<div class="loader" id="temp-loader"></div>
|
||||
|
|
Loading…
Reference in a new issue